/// <summary> /// 获取单例配置数据 /// 编辑器环境下:第一次打开,将保存的 txt 文件反序列化为所需资料数据, /// 如没有找到对应的 Txt,将自动创建一份 Asset 文件,以保存持久化数据。 /// 点击保存资料文件以将Asset序列化为 txt,以更安全地保存持久化数据。 /// </summary> /// <returns></returns> public static GenericSingleDati <TActual, TImpl> GetSingleDati() { var implType = typeof(TImpl); if (instance != null) { return(instance); } //获取 ScriptableObject Asset 文件路径 var assetFilePath = DatiUtility.GetSingleScriptObjectPath(implType); #if UNITY_EDITOR //在编辑器下,直接加载 Asset 文件 if (UnityModeUtility.IsEditorMode) { if (File.Exists(assetFilePath)) { var scriptAsset = AssetDatabaseUtility.LoadAssetAtPath(assetFilePath, implType); instance = (GenericSingleDati <TActual, TImpl>)scriptAsset; } } #endif // Asset 文件加载失败或在运行时,加载序列化文件 if (instance == null) { var originPath = DatiUtility.GetSingleSerializeDataPath(implType); instance = UnityModeUtility.IsEditorMode ? LoadSingleOriginAtEditor(implType, originPath, assetFilePath) : LoadSingleOriginAtPlay(implType, originPath); } instance.LoadDetailHelp(); return(instance); }
public override void Save() { var type = GetType(); var originPath = DatiUtility.GetSingleSerializeDataPath(type); Serialize(originPath); Debug.Log($"目标路径{originPath}的资料文件已更新!"); AssetDatabaseUtility.Refresh(); //var asset = YuAssetDatabaseUtility.LoadAssetAtPath(originPath, //typeof(TextAsset)); //YuEditorAPIInvoker.PingObject(asset); }