void Start () {
PlayerPrefs.SetInt("Test001",101);
PlayerPrefs.SetInt("Test002", 202);
PlayerPrefs.SetString("Test001", "Test001");
PlayerPrefs.SetString("Test002", "Test002");
PlayerPrefs.SetFloat("Test001", 1.1f);
PlayerPrefs.SetFloat("Test002", 2.2f);
int int001=-1, int002 = -1;
string str001="null", str002 = "null";
float f001 = -1f, f002 = -1f;
int001 = PlayerPrefs.GetInt("Test001");
int002 = PlayerPrefs.GetInt("Test002");
str001 = PlayerPrefs.GetString("Test001");
str002 = PlayerPrefs.GetString("Test002");
f001 = PlayerPrefs.GetFloat("Test001");
f002 = PlayerPrefs.GetFloat("Test002");
Debug.Log(" Test001: int:"+int001+"///string:"+str001+"///float:"+f001);
Debug.Log(" Test002: int:" + int002 + "///string:" + str002 + "///float:" + f002);
}
顯示的結果如下所示:
Test001: int:0///string:///float:1.1
Test002: int:0///string:///float:2.2
經過以下測試
意味着同一個關鍵字,的 最後一個讀取的 獲得的關鍵字,會覆蓋之前 設置的 同一個 關鍵字的數值。
...
PlayerPrefs.SetFloat("Test002", 2.2f);
PlayerPrefs.SetFloat("Test002", 3.3f);
...
Debug.Log(" Test002: int:" + int002 + "///string:" + str002 + "///float:" + f002);
運行後的結果顯示爲
Test002: int:0///string:///float:3.3
參考資料:
1.
2.
3.