/// <summary> /// 加载配置文件 /// </summary> /// <param name="fileName">配置文件名, CSV文件</param> /// <param name="index">表示从第index行开始读取文件, 从0开始</param> public static T LoadConfig <T>(string fileName) where T : CsvTable { if (!loadedTables.ContainsKey(fileName)) { string csvText = LoadTextAsset(fileName); CsvTable table = Activator.CreateInstance <T>(); table.Load(csvText); loadedTables.Add(fileName, table); return((T)table); } else { return((T)loadedTables[fileName]); } }
//public CsvConfigManager(){ // //textureLoader = new TextureLoader(this); //} /// <summary> /// 异步加载配制表 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="action"></param> public void LoadConfigAsync <T>(string fileName, UnityAction <T> action) where T : CsvTable { if (action == null) { Debug.Log("null"); return; } //Debug.Log(fileName); if (loadedTables.ContainsKey(fileName)) { action((T)loadedTables[fileName]); } #if UNITY_EDITOR || UNITY_STANDALONE else if (File.Exists(FilesPath + fileName)) { string csvText = LoadTextAsset(fileName); CsvTable table = Activator.CreateInstance <T>(); table.Load(csvText); loadedTables.Add(fileName, table); action((T)table); } #endif else { UnityAction <string> txtAction = (csvText) => { CsvTable table = Activator.CreateInstance <T>(); table.Load(csvText); loadedTables.Add(fileName, table); action((T)table); #if UNITY_EDITOR || UNITY_STANDALONE //保存到本地文件 SaveTextAsset(fileName, csvText); #endif }; StartCoroutine(DownTextAssetAsync(fileName, txtAction)); } }