using System; using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; public class DataManager : MonoBehaviour { static void SaveJson<T>(string path, T target, bool withoutCreat = false) { if (!File.Exists(path) && !withoutCreat) { Debug.Log("存储失败"); return; } string jsonText = JsonUtility.ToJson(target); File.WriteAllText(path, jsonText); Debug.Log("存储成功"); } static T ParseJson<T>(string path, bool withoutCreat = false) { if (!File.Exists(path) && withoutCreat) { File.Create(path); } else if (!File.Exists(path) && !withoutCreat) { Debug.Log("解析失败"); return default(T); } string jsonText = File.ReadAllText(path); T target = JsonUtility.FromJson<T>(jsonText); Debug.Log("解析成功"); return target; } }