美文网首页
unity json

unity json

作者: MakerSir | 来源:发表于2020-12-15 13:50 被阅读0次

    public class MyClass

        {

            public int level;

            public float timeElapsed;

            public string playerName;

        }

        // Start is called before the first frame update

        void Start()

        {

            MyClass myObject = new MyClass();

            myObject.level = 1;

            myObject.timeElapsed = 47.5f;

            myObject.playerName = "zyx";

            string json = JsonUtility.ToJson(myObject);

            print("json: " + json);

            MyClass myObject1 = new MyClass();

            myObject1 = JsonUtility.FromJson<MyClass>(json);

            print("playerName: " + myObject1.playerName);

            List<MyClass> ml = new List<MyClass>();

            myObject.level = 1;

            myObject.timeElapsed = 47.5f;

            myObject.playerName = "zyx";

            ml.Add(myObject);

            myObject.level = 2;

            myObject.timeElapsed = 47.5f;

            myObject.playerName = "wb";

            ml.Add(myObject);

            string jsonToSave = JsonUtility.ToJson(ml);

            print("jsonToSave: " + jsonToSave);

        }

    相关文章

      网友评论

          本文标题:unity json

          本文链接:https://www.haomeiwen.com/subject/nyhwgktx.html