PlayerPrefsPlus 插件支持 PlayerPrefs 数据加密,支持保存自定义类等复制数据。
PlayerPrefsPlus 插件下载地址:百度网盘
具体使用方法,参考测试脚本:TestPlayerPrefsPlus
1.相同 value值 经过加密后会保存成不同内容
经过加密后保存的数据内容不一样:
2.存储读取自定义类型数据
class Student
{
public string name;
public int age;
public float height;
public bool sex;
public List<int> list;
public Dictionary<int, string> dict;
public BookInfo bookInfo;
public List<BookInfo> bookList;
public Dictionary<int, BookInfo> bookDict;
}
class BookInfo
{
public int id;
public int num;
public BookInfo() { }
public BookInfo(int id, int num) {
this.id = id;
this.num = num;
}
}
private void TestCustomClass() {
// 读取数据
Student p = (Student)PlayerPrefsPlus.Instance.LoadData("Student1", typeof(Student));
// 游戏逻辑,修改信息
p.name = "LiSha";
p.age = 28;
p.height = 176.5f;
p.sex = true;
p.list = new List<int> { 1, 2, 3, 4, 5, 6 };
p.dict = new Dictionary<int, string>() {
{ 1, "football" },
{ 2, "pingpong" }
};
p.bookInfo = new BookInfo(1, 10);
p.bookList = new List<BookInfo>() {
new BookInfo(2, 20),
new BookInfo(3, 30)
};
p.bookDict = new Dictionary<int, BookInfo>() {
{ 4, new BookInfo(44, 400) },
{ 5, new BookInfo(55, 500) },
};
// 保存数据
PlayerPrefsPlus.Instance.SaveData("Student1", p);
}
PlayerPrefsPlus 更多功能正在开发中,敬请关注...