/// <summary> /// 加载Json文件 /// </summary> /// <param name="url"></param> /// <param name="completeHandler"></param> public void LoadRes(string url, LoadHandler completeHandler) { string json = IOHelper.OpenText(Const.GetLocalFileUrl(url)); if (null != completeHandler) { completeHandler(new LoadedData(json, url, url)); } }
/// <summary> /// 保存音效信息 /// </summary> private void SaveAudioList() { StringBuilder sb = new StringBuilder(); // TODO 后面要改成Json格式 foreach (string key in audioDic.Keys) { string value; audioDic.TryGetValue(key, out value); sb.Append(key + "," + value + "\n"); } File.WriteAllText(Const.GetLocalFileUrl(Const.Audio_Coinfig_Path), sb.ToString()); AssetDatabase.Refresh(); }
public Object LoadMovie(string name) { obj = null; string path = Const.GetLocalFileUrl("Movie" + name); if (!File.Exists(path)) { Debug.LogError(path + " is not exit!"); return(obj); } StartCoroutine(DownAsset(path)); return(obj); }
/// <summary> /// 加载Json文件 /// </summary> /// <param name="url"></param> /// <param name="completeHandler"></param> public void LoadRes(string url, LoadHandler completeHandler) { string result = string.Empty; url = Const.GetLocalFileUrl(url); if (!File.Exists(url)) { return; } using (StreamReader sr = new StreamReader(url, Encoding.UTF8)) { result = sr.ReadToEnd(); } if (null != completeHandler) { completeHandler(new LoadedData(result, url, url)); } }
/// <summary> /// 加载配置文件 /// </summary> private void LoadAudioConfig() { configDic.Clear(); if (!File.Exists(Const.GetLocalFileUrl(Const.Audio_Coinfig_Path))) { Debug.LogError("缺少音效配置文件"); return; } string[] lines = File.ReadAllLines(Const.GetLocalFileUrl(Const.Audio_Coinfig_Path)); foreach (string line in lines) { if (string.IsNullOrEmpty(line)) { continue; } string[] keyvalue = line.Split(','); configDic.Add(keyvalue[0], keyvalue[1]); } }
private void LoadPoolList() { poolDic.Clear(); if (!File.Exists(Const.Pool_Config_Path)) { return; } string[] lines = File.ReadAllLines(Const.GetLocalFileUrl(Const.Pool_Config_Path)); foreach (string line in lines) { if (string.IsNullOrEmpty(line)) { continue; } string[] keyvalue = line.Split(','); poolDic.Add(keyvalue[0], keyvalue[1]); } }
public SettingManager() { // 取出后台存储所有数据 this.po = LoadJson(Const.GetLocalFileUrl(Const.Setting_Coinfig_Path)); if (null == this.po) { this.po = new SettingConfigData(); } // CheckID this._checkID = po.CheckId; // 游戏币率 this._gameRate = po.GameRate; // 游戏语言版本 0中文 1英文 this._gameLanguage = po.GameLanguage; // 检查点模式 this._ticketModel = po.TicketModel; // 游戏音量 this._gameVolume = po.GameVolume; // 游戏难度 this._gameLevel = po.GameLevel; // 当前剩余币数 this._hasCoin = po.Coin; // 月份信息 this._monthList = po.MonthList; // 总记录 this._totalRecord = po.TotalRecord; CheckIsNewMonth(); }
void OnGUI() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("音效名称"); EditorGUILayout.LabelField("音效路径"); EditorGUILayout.LabelField("操作"); EditorGUILayout.EndHorizontal(); foreach (string key in audioDic.Keys) { string value; audioDic.TryGetValue(key, out value); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(key); EditorGUILayout.LabelField(value); if (GUILayout.Button("删除")) { audioDic.Remove(key); SaveAudioList(); return; } EditorGUILayout.EndHorizontal(); } //audioName = EditorGUILayout.TextField("音效名字", audioName); //audioPath = EditorGUILayout.TextField("音效路径", audioPath); //if(GUILayout.Button("添加音效")) //{ // object o = AssetDatabase.LoadAssetAtPath(audioPath, typeof(object)); // if (null == o) // { // Debug.LogWarning("音效不存在于" + audioPath + " 添加不成功"); // audioPath = ""; // } // else // { // if (audioDic.ContainsKey(audioName)) // Debug.Log("名字已存在,请修改"); // else // { // audioDic.Add(audioName, audioPath); // SaveAudioList(); // } // } //} if (GUILayout.Button("添加所有音效")) { audioDic.Clear(); if (File.Exists(Const.GetLocalFileUrl(Const.Audio_Coinfig_Path))) { File.Delete(Const.GetLocalFileUrl(Const.Audio_Coinfig_Path)); } DirectoryInfo folder = new DirectoryInfo(Application.dataPath + "/Resources/Sound"); FileSystemInfo[] files = folder.GetFileSystemInfos(); for (int i = 0; i < files.Length; ++i) { if (files[i].Extension.Equals(".meta")) { continue; } audioName = files[i].Name; audioName = audioName.Remove(audioName.LastIndexOf('.')); audioPath = files[i].FullName; audioPath = audioPath.Replace("\\", "/"); audioPath = audioPath.Remove(audioPath.LastIndexOf(".")); audioPath = audioPath.Substring((Application.dataPath + "/Resources/").Length); if (audioDic.ContainsKey(audioName)) { audioDic[audioName] = audioPath; } else { audioDic.Add(audioName, audioPath); } } SaveAudioList(); } }
void OnGUI() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("对象名称"); EditorGUILayout.LabelField("对象路径"); EditorGUILayout.LabelField("操作"); EditorGUILayout.EndHorizontal(); foreach (string key in poolDic.Keys) { string value; poolDic.TryGetValue(key, out value); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(key); EditorGUILayout.LabelField(value); if (GUILayout.Button("删除")) { poolDic.Remove(key); SavePoolList(); return; } EditorGUILayout.EndHorizontal(); } if (GUILayout.Button("添加所有对象")) { poolDic.Clear(); if (File.Exists(Const.GetLocalFileUrl(Const.Pool_Config_Path))) { File.Delete(Const.GetLocalFileUrl(Const.Pool_Config_Path)); } DirectoryInfo folder = new DirectoryInfo(Application.dataPath + "/Resources/Model"); FileSystemInfo[] files = folder.GetFileSystemInfos(); for (int i = 0; i < files.Length; ++i) { if (files[i].Extension.Equals(".meta")) { continue; } poolName = files[i].Name; poolName = poolName.Remove(poolName.LastIndexOf('.')); poolPath = files[i].FullName; poolPath = poolPath.Replace("\\", "/"); poolPath = poolPath.Remove(poolPath.LastIndexOf(".")); poolPath = poolPath.Substring((Application.dataPath + "/Resources/").Length); if (poolDic.ContainsKey(poolName)) { poolDic[poolName] = poolPath; } else { poolDic.Add(poolName, poolPath); } } SavePoolList(); CreatePools(); } }
//---------------------------------------------- // 保存后台信息 public void Save() { CopyToPo(); SaveJson(this.po, Const.GetLocalFileUrl(Const.Setting_Coinfig_Path)); }