Unity 数据存储之SaveGameFree
一、安装直接在Asset Store搜索Save Game Free
或者直接进入Save Game Free保存安装
二、使用
存储基本对象
SaveGame.Save<int>("int", 2); int t = SaveGame.Load<int>("int"); SaveGame.Save<float>("float", 2.0f); float f = SaveGame.Load<float>("float"); SaveGame.Save<string>("string", "2"); string s = SaveGame.Load<string>("string"); Dictionary<int, string> dic = new Dictionary<int, string>(); dic.Add(3, "33"); SaveGame.Save<Dictionary<int, string>>("dictionary", dic); Dictionary<int, string> d = SaveGame.Load<Dictionary<int, string>>("dictionary");
存储对象
using BayatGames.SaveGameFree;public class CustomPathLine { public Vector3 cameraPosition; public Vector3 cameraRoataion; public List<Vector3> line;}//存储对象 private void Awake() { CustomPathLine line = new CustomPathLine(); line.cameraPosition = Vector3.zero; line.cameraRoataion = Vector3.one; List<Vector3> firstLine = new List<Vector3>(); firstLine.Add(Vector3.one); line.line = firstLine; SaveGame.Save<CustomPathLine>("line", line); if (SaveGame.Exists("line")) { CustomPathLine line1 = SaveGame.Load<CustomPathLine>("line"); } else { print("--------not exist"); } }
存储对象List
using BayatGames.SaveGameFree;public class CustomPathLine { public Vector3 cameraPosition; public Vector3 cameraRoataion; public List<Vector3> line;}//存储对象Listprivate void Awake() { //存 CustomPathLine line = new CustomPathLine(); line.cameraPosition = Vector3.zero; line.cameraRoataion = Vector3.one; List<Vector3> firstLine = new List<Vector3>(); firstLine.Add(Vector3.one); line.line = firstLine; List<CustomPathLine> lines = new List<CustomPathLine>(); lines.Add(line); SaveGame.Save<List<CustomPathLine>>("lines", lines); //取 if (SaveGame.Exists("lines")) { List<CustomPathLine> lines1 = SaveGame.Load<List<CustomPathLine>>("lines"); if (lines1.Count > 0) { CustomPathLine pa = lines1; } } else { print("--------not exist"); } }
判断是否存在
if (SaveGame.Exists("line")) {}
删除
SaveGame.Delete("line");SaveGame.DeleteAll();SaveGame.Clear();
页:
[1]