Beispiel #1
0
    /// <summary>
    /// 将一场战斗序列化到路径...
    /// </summary>
    /// <param name="outputPath"></param>
    private void SerializeBattleFieldToPath(string outputPath)
    {
        string folderPath = Path.GetDirectoryName(outputPath);

        if (!Directory.Exists(folderPath))
        {
            Directory.CreateDirectory(folderPath);
        }

        using (TextWriter tw = new StreamWriter(outputPath))
        {
            LitJson.JsonWriter jsonWriter = new LitJson.JsonWriter(tw);
#if UNITY_EDITOR
            //弄得好看一点
            jsonWriter.PrettyPrint = true;
#endif
            jsonWriter.WriteObjectStart();
            {
                //序列化战斗
                jsonWriter.WriteObject("battleField", battleField);
            }
            jsonWriter.WriteObjectEnd();
            Debug.LogFormat("序列化战场完毕 => {0}", outputPath);

            System.Diagnostics.Process.Start("explorer.exe", folderPath);
        }
    }