找回密码
 立即注册
查看: 229|回复: 0

Unity 数据存储之SaveGameFree

[复制链接]
发表于 2022-12-28 20:27 | 显示全部楼层 |阅读模式
一、安装


直接在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[0];            }        }        else        {            print("--------not exist");        }    }
判断是否存在
if (SaveGame.Exists("line")) {}
删除
SaveGame.Delete("line");SaveGame.DeleteAll();SaveGame.Clear();
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-16 00:44 , Processed in 0.088649 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表