PlayerPrefsEx

11/1/2024 Unity3d

Note:

There are limitations on PlayerPrefs in webgl:https://docs.unity3d.com/2022.1/Documentation/ScriptReference/PlayerPrefs.html (opens new window)

  1. The total data of PlayerPrefs cannot exceed 1MB
  2. The data of a PlayerPrefs entry cannot exceed 1MB

If PlayerPrefs already stores 1MB of data, setting PlayerPrefs.SetInt("t",1) will fail because the total will exceed 1MB. If PlayerPrefs does not have any data, PlayerPrefs.SetString("t2","ttttt-----") can store 1MB of data at a time.

gms version >=3074.2

Set

describe
UnityEngine.PlayerPrefsEx.SetFloat(key,value,back) key: string

value:float、number

back:Callback function, parameter is bool type. Like c# Action

true : success

false : fail

If you don't care about the result, callback can be omitted.
UnityEngine.PlayerPrefsEx.SetString(key,value,back) key: string

value:string

back:Callback function, parameter is bool type. Like c# Action

true : success

false : fail

If you don't care about the result, callback can be omitted.
UnityEngine.PlayerPrefsEx.SetInt(key,value,back) key: string

value:int

back:Callback function, parameter is bool type. Like c# Action

true : success

false : fail

If you don't care about the result, callback can be omitted.
UnityEngine.PlayerPrefsEx.SetFloatArray(key,value,back) key: string

value:float[]

back:Callback function, parameter is bool type. Like c# Action

true : success

false : fail

If you don't care about the result, callback can be omitted.

Get

describe
UnityEngine.PlayerPrefsEx.GetFloat(key,back) key: string

back:Callback function, parameter is bool type. Like c# Action

The return value in Lua is number

If the value does not exist or the type does not match, the result is number 0
UnityEngine.PlayerPrefsEx.GetString(key,back) key: string

back:Callback function, parameter is bool type. Like c# Action

The return value in Lua is string

If the value does not exist or the type does not match, the result is string "null"
UnityEngine.PlayerPrefsEx.GetInt(key,back) key: string

back:Callback function, parameter is bool type. Like c# Action

The return value in Lua is number, which is an integer.

If the value does not exist or the type does not match, the result is number 0
UnityEngine.PlayerPrefsEx.GetFloatArray(key,back) key: string

back:Callback function, parameter is bool type. Like c# Action<float[]>

The return value in Lua is number, which is an single.

If the value does not exist or the type does not match, the result float[] length =0

Del

describe
UnityEngine.PlayerPrefsEx.DeleteKey(key) key: string

example

--set
--no callback
UnityEngine.PlayerPrefsEx.SetFloat("1",15.86);

UnityEngine.PlayerPrefsEx.SetFloat("2",100,function(result)
	print("set","key","2","result=",result);
end
);

UnityEngine.PlayerPrefsEx.SetString("3","2212gdfgdf23dd",function(result)
	print("set","key","3","result=",result);
end
);

UnityEngine.PlayerPrefsEx.SetFloat("null-1",88,function(result)
print("set","key","null-1","result=",result);
end
);

UnityEngine.PlayerPrefsEx.SetFloat("null",100,function(result)
	print("set","key","null","result=",result);
end
);

local arr = newArray(System.Single,3)
arr[2]=90.5
UnityEngine.PlayerPrefsEx.SetFloatArray("fa",arr,function(result)
	print("set","key","fa","result=",result);
end
);

--get
UnityEngine.PlayerPrefsEx.GetFloat("1",function(result)
	print("get","key","1","result=",result);
end
);

UnityEngine.PlayerPrefsEx.GetFloat("2",function(result)
	print("get","key","2","result=",result);
end
);

UnityEngine.PlayerPrefsEx.GetInt("2",function(result)
	print("get","key","2","result=",result);
end
);

UnityEngine.PlayerPrefsEx.GetString("3",function(result)
	print("get","key","3","result=",result);
end
);

UnityEngine.PlayerPrefsEx.GetString("100",function(result)
	print("get","key","100","result=",result);
end
);

UnityEngine.PlayerPrefsEx.GetInt("null",function(result)
	print("get","key","null","result=",result);
end
);
UnityEngine.PlayerPrefsEx.GetFloatArray("fa",function(result)
	print("Get","key","fa","result=",result);
end
);

--del
UnityEngine.PlayerPrefsEx.DeleteKey("a");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

Last Updated: Fri, 01 Nov 2024 03:45:02 GMT