原文内容来自:Read from and write to external .json files using JsonUtilities or LitJson
文件Unity 版本号5.3,使用时候Unity 版本号5.6
文件分流 unity-json-master本文仅作分析,学习用途。
类似下面这样,//* 这样的表示和 LitJson 对应 的代码 相同。
//* 的 分数 +1
通过注释来区别 。主要用于 表示 在 代码中 可以 改变 的数据。
someList.Add (createSubObject ("Amazing Angus6", 64546));
原代码,无注释。
someList.Add (createSubObject ("Amazing Angus", 6454));
_4Update_ObjectArray_JsonUtility
----------------------------------------------------------------------------------------------原代码+注释
// Reading an array with nested object stored in a JSON-formatted text file. Changing objects and adding more objects
// using JsonUtility
// At start: {"highscore":[{"name":"BadBoy","scores":4711}]}
// After step 5: {"highscore":[{"name":"BadBoy","scores":4711},{"name":"MagicMike","scores":8828}]}
// After step 7: {"highscore":[{"name":"BadBoy","scores":4712},{"name":"MadMax","scores":1234},{"name":"Amazing Angus","scores":6454},{"name":"Good Guys","scores":1936}]}
using UnityEngine;
using System;
using System.IO;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
public class _4Update_ObjectArray_JsonUtility : MonoBehaviour {
void Start () {
/**
* 1. Fetch text from file * 从文件中取出 text 文本
*/
string jsonString = File.ReadAllText (Application.dataPath + "/Resources/Json_UpdateObj