[Unity][存档]PlayerPrefs同一关键字存储的数据是否会受到影响

 


 

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.

Unity保存数据方式——PlayerPrefs

2.

3.

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章