/// <summary> /// 新建多语言文件 /// </summary> /// <param name="fileName"></param> /// <param name="contentDic"></param> /// <returns>返回每个key对应的多语言访问key</returns> public Dictionary <string, string> CreateNewFile(string fileName, Dictionary <string, string> contentDic) { selectEditorModuleName = fileName; Dictionary <string, string> keyPaths = new Dictionary <string, string>(); string tempContent = fileName.Replace('_', '/'); s_languageKeyDict.Add(fileName, new List <string>()); DataTable data = new DataTable(); data.TableKeys.Add(LanguageManager.c_mainKey); data.TableKeys.Add(LanguageManager.c_valueKey); data.SetDefault(LanguageManager.c_valueKey, "NoValue"); if (contentDic != null) { foreach (var item in contentDic) { SingleData sd = new SingleData(); sd.Add(LanguageManager.c_mainKey, item.Key); sd.Add(LanguageManager.c_valueKey, item.Value); data.AddData(sd); s_languageKeyDict[fileName].Add(item.Key); keyPaths.Add(item.Key, tempContent + "/" + item.Key); } } m_langeuageDataDict.Add(selectEditorModuleName, data); SaveData(); OnEnable(); return(keyPaths); }
void AddMissLanguageGUI(DataTable data, string key) { if (GUILayout.Button("添加记录")) { SingleData newData = new SingleData(); newData.Add(LanguageManager.c_valueKey, ""); newData.Add(LanguageManager.c_mainKey, key); data.AddData(newData); } }
private void AddNewKey(string fullKeyFileName, string key) { foreach (var language in config.gameExistLanguages) { DataTable data = LanguageDataUtils.LoadFileData(language, fullKeyFileName); SingleData sd = new SingleData(); sd.Add(LanguageManager.c_mainKey, key); sd.Add(LanguageManager.c_valueKey, ""); data.AddData(sd); LanguageDataEditorUtils.SaveData(language, fullKeyFileName, data); } }
static void RecursionAddResouces(DataTable data, string path) { if (!File.Exists(path)) { FileTool.CreatPath(path); } string[] dires = Directory.GetDirectories(path); for (int i = 0; i < dires.Length; i++) { RecursionAddResouces(data, dires[i]); } string[] files = Directory.GetFiles(path); for (int i = 0; i < files.Length; i++) { string fileName = FileTool.RemoveExpandName(FileTool.GetFileNameByPath(files[i])); string relativePath = files[i].Substring(direIndex); if (relativePath.EndsWith(".meta") || relativePath.EndsWith(".DS_Store")) { continue; } else { relativePath = FileTool.RemoveExpandName(relativePath).Replace("\\", "/"); SingleData sd = new SingleData(); sd.Add(c_MainKey, fileName.ToLower()); sd.Add(c_PathKey, relativePath.ToLower()); if (fileName.Contains(" ")) { Debug.LogError("文件名中有空格! ->" + fileName + "<-"); } else { if (!data.ContainsKey(fileName.ToLower())) { data.AddData(sd); } else { Debug.LogError("GenerateResourcesConfig error 存在重名文件!" + relativePath); } } } } }
/// <summary> /// 添加一行数据 /// </summary> private void AddLineDataGUI() { GeneralDataModificationWindow.OpenWindow(this, "插入一行数据", "", (value) => { value = EditorDrawGUIUtil.DrawBaseValue("Key:", value); if (string.IsNullOrEmpty(value.ToString())) { EditorGUILayout.HelpBox("Key不能为空!!", MessageType.Error); } else if (m_currentData.TableKeys.Contains(value.ToString())) { EditorGUILayout.HelpBox("Key重复!!", MessageType.Error); } return(value); }, (value) => { if (string.IsNullOrEmpty(value.ToString()) || m_currentData.TableKeys.Contains(value.ToString())) { return(false); } return(true); }, (value) => { heightItemList.Add(30); SingleData data = new SingleData(); DataTable table = m_currentData; List <string> keys = table.TableKeys; for (int i = 0; i < keys.Count; i++) { string keyTmp = keys[i]; if (i == 0) { data.Add(keyTmp, value.ToString()); } else { data.Add(keyTmp, table.m_defaultValue[keyTmp]); } } m_currentData.AddData(data); }); }
//创建对话 private void CreateNewTalk(string _talkId) { m_talkContent = new SingleData(); m_talkContent.Add("talk_id", _talkId); if (m_playerTalkDatas.TableKeys.Count == 0) { m_playerTalkDatas.TableKeys.Add("talk_id"); } m_playerTalkDatas.AddData(m_talkContent); DataEditorWindow.SaveData(GetTalkConfigName(), m_playerTalkDatas); PrepareTalk(); }
void Import() { string key = GetKey(m_poemType, m_defaultLevel, m_index); SingleData dt = new SingleData(); dt.Add("poemName", poemName); dt.Add("author", author); dt.Add("description", description); dt.Add("poemID", key); string contentTmp = ""; for (int i = 0; i < poemContent.Count; i++) { contentTmp += poemContent[i]; if (i != poemContent.Count - 1) { contentTmp += "|"; } } dt.Add("content", contentTmp); data.AddData(dt); DataEditorWindow.SaveData(c_dataName, data); oldContent = content; content = ""; poemName = ""; author = ""; description = ""; poemContent.Clear(); GUI.FocusControl("button"); //GUI.FocusControl("inputContent"); }
void MergeLanguage(string path, SystemLanguage language) { Debug.Log("MergeLanguage " + path); string languageKey = FileTool.GetFileNameByPath(FileTool.RemoveExpandName(path)).Replace(LanguageManager.c_DataFilePrefix + language + "_", "").Replace("_", "/"); Debug.Log("languageKey " + languageKey); string content = ResourceIOTool.ReadStringByFile(path); DataTable aimLanguage = DataTable.Analysis(content); DataTable localLanguage = LanguageDataUtils.LoadFileData(language, languageKey); foreach (var key in aimLanguage.TableIDs) { string value = aimLanguage[key].GetString(LanguageManager.c_valueKey); SingleData sd = new SingleData(); sd.Add(LanguageManager.c_mainKey, key); sd.Add(LanguageManager.c_valueKey, value); if (!localLanguage.TableIDs.Contains(key)) { Debug.Log("新增字段 " + key + " -> " + value); localLanguage.AddData(sd); } else { if (localLanguage[key].GetString(LanguageManager.c_valueKey) != value) { Debug.Log("更新字段 key" + key + " Value >" + localLanguage[key].GetString(LanguageManager.c_valueKey) + "< newValue >" + value + "<"); localLanguage[key] = sd; } } } LanguageDataEditorUtils.SaveData(language, languageKey, localLanguage); }
public Dictionary<string, string> CreateLanguageNewFile(SystemLanguage language, string fullKeyFileName, Dictionary<string, string> contentDic) { Dictionary<string, string> keyPaths = new Dictionary<string, string>(); DataTable data = new DataTable(); data.TableKeys.Add(LanguageManager.c_mainKey); data.TableKeys.Add(LanguageManager.c_valueKey); data.SetDefault(LanguageManager.c_valueKey, "NoValue"); if (contentDic != null) { foreach (var item in contentDic) { SingleData sd = new SingleData(); sd.Add(LanguageManager.c_mainKey, item.Key); sd.Add(LanguageManager.c_valueKey, item.Value); data.AddData(sd); keyPaths.Add(item.Key, fullKeyFileName + "/" + item.Key); } } LanguageDataEditorUtils.SaveData(language, fullKeyFileName, data); return keyPaths; }
private void AddNewKey(SystemLanguage language, string fullKeyFileName, string[] keys) { if (keys == null || keys.Length == 0) { return; } DataTable data = LanguageDataUtils.LoadFileData(language, fullKeyFileName); foreach (var key in keys) { if (data.ContainsKey(key)) { continue; } SingleData sd = new SingleData(); sd.Add(LanguageManager.c_mainKey, key); sd.Add(LanguageManager.c_valueKey, ""); data.AddData(sd); } LanguageDataEditorUtils.SaveData(language, fullKeyFileName, data); UnityEditor.AssetDatabase.Refresh(); }
void AddDataGUI(DataTable dict) { isFold = EditorGUILayout.Foldout(isFold, "新增记录"); if (isFold) { EditorGUI.indentLevel++; string key = dict.TableKeys[0]; AddDataPos = EditorGUILayout.BeginScrollView(AddDataPos, GUILayout.ExpandHeight(false)); EditorGUILayout.LabelField("<主键>字段名", key); mianKey = EditorUtilGUI.FieldGUI_TypeValue(FieldType.String, mianKey,null); if (mianKey == "") { EditorGUILayout.LabelField("主键不能为空!"); } else if (dict.ContainsKey(mianKey)) { EditorGUILayout.LabelField("重复的主键!"); } EditorGUILayout.Space(); EditorDataGUI(dict, content); if (!dict.ContainsKey(mianKey) && mianKey != "") { EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button("新增", GUILayout.Width(position.width - 60))) { content.Add(key, mianKey); m_currentData.AddData(content); content = new SingleData(); mianKey = ""; } EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); EditorGUILayout.Space(); } }
private void AddPlayerGUI() { //当前没有选中角色时时,才显示 if (m_curPlayerIndex != 0) { return; } newPlayerisFold = EditorGUILayout.Foldout(newPlayerisFold, "创建角色"); if (newPlayerisFold) { EditorGUI.indentLevel++; var fieldData = new SingleField(FieldType.String, playerId, null); playerId = EditorUtilGUI.FieldGUI_Type(fieldData, "角色ID"); if (string.IsNullOrEmpty(playerId)) { EditorGUILayout.LabelField("输入要添加的ID(角色id从101开始)=,,="); } else if (m_curPlayerDatas.ContainsKey(playerId)) { EditorGUILayout.LabelField("重复啦=..="); } EditorGUILayout.Space(); if (!m_curPlayerDatas.ContainsKey(playerId) && !string.IsNullOrEmpty(playerId)) { EditorGUILayout.Space(); if (GUILayout.Button("创建")) { playerContent = new SingleData(); playerContent.Add("player_id", playerId); m_curPlayerDatas.AddData(playerContent); DataEditorWindow.SaveData(m_playerCfgName, m_curPlayerDatas); PreparePlayerData(); } EditorGUILayout.Space(); } EditorGUILayout.Space(); } }
SingleData EditorDataGUI(DataTable table, SingleData data) { try { List <string> keys = table.TableKeys; for (int i = 0; i < keys.Count; i++) { string keyTmp = keys[i]; FieldType type = table.GetFieldType(keyTmp); if (i != 0) { bool cancelDefault = false; EditorGUILayout.BeginHorizontal(); if (data.ContainsKey(keyTmp)) { EditorGUILayout.LabelField("[" + keyTmp + "]"); if (GUILayout.Button("使用默认值")) { data.Remove(keyTmp); EditorGUILayout.EndHorizontal(); continue; } } else { EditorGUILayout.LabelField("[" + keyTmp + "] (默认值)"); if (GUILayout.Button("取消默认值")) { cancelDefault = true; } } EditorGUILayout.EndHorizontal(); //EditorGUI.indentLevel++; EditorGUI.indentLevel++; //非默认值情况 if (data.ContainsKey(keyTmp)) { EditorGUILayout.LabelField("字段名", keyTmp); EditorGUILayout.LabelField("注释", table.GetNote(keyTmp)); string newContent = EditorUtilGUI.FieldGUI_TypeValue(type, data[keyTmp], table.GetEnumType(keyTmp)); if (newContent != data[keyTmp]) { data[keyTmp] = newContent; } } //如果是默认值则走这里 else { EditorGUILayout.LabelField("字段名", keyTmp); EditorGUILayout.LabelField("注释", table.GetNote(keyTmp)); string newContent = ""; if (table.m_defaultValue.ContainsKey(keyTmp)) { newContent = new SingleField(type, table.GetDefault(keyTmp), table.GetEnumType(keyTmp)).m_content; } else { newContent = new SingleField(type, null, table.GetEnumType(keyTmp)).m_content; } if (type != FieldType.Enum) { EditorGUILayout.LabelField("字段类型", type.ToString()); } else { EditorGUILayout.LabelField("字段类型", type.ToString() + "/" + table.GetEnumType(keyTmp)); } EditorGUILayout.LabelField("(默认)字段内容", new SingleField(type, newContent, table.GetEnumType(keyTmp)).GetShowString()); if (cancelDefault) { data.Add(keyTmp, newContent); } } EditorGUI.indentLevel--; //EditorGUI.indentLevel--; } EditorGUILayout.Space(); } } catch (Exception e) { EditorGUILayout.TextArea(e.ToString(), EditorGUIStyleData.s_ErrorMessageLabel); } return(data); }
SingleData EditorDataGUI(DataTable table, SingleData data) { List <string> keys = table.TableKeys; for (int i = 0; i < keys.Count; i++) { string keyTmp = keys[i]; FieldType type = table.GetFieldType(keyTmp); if (i != 0) { if (data.ContainsKey(keyTmp)) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("字段名", keyTmp); if (GUILayout.Button("使用默认值")) { data.Remove(keyTmp); EditorGUILayout.EndHorizontal(); continue; } EditorGUILayout.EndHorizontal(); string newContent = EditorUtilGUI.FieldGUI_TypeValue(type, data[keyTmp]); if (newContent != data[keyTmp]) { data[keyTmp] = newContent; } } else { bool cancelDefault = false; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("字段名", keyTmp); if (GUILayout.Button("取消默认值")) { cancelDefault = true; } EditorGUILayout.EndHorizontal(); string newContent = ""; if (table.m_defaultValue.ContainsKey(keyTmp)) { newContent = new SingleField(type, table.GetDefault(keyTmp)).m_content; } else { newContent = new SingleField(type, null).m_content; } EditorGUILayout.LabelField("字段类型", type.ToString()); EditorGUILayout.LabelField("(默认值)字段内容", new SingleField(type, newContent).GetShowString()); if (cancelDefault) { data.Add(keyTmp, newContent); } } } EditorGUILayout.Space(); } return(data); }
void EditorLanguageFieldGUI() { if (string.IsNullOrEmpty(selectFullFileName)) return; if (currentFileDataTable == null) return; DataTable data = currentFileDataTable; List<string> languageKeyList = data.TableIDs; //Debug.Log("languageKeyList :" + languageKeyList.Count); AddLangeuageFieldGUI(languageKeyList); EditorGUILayout.Space(); EditorDrawGUIUtil.DrawScrollView(languageKeyList, () => { for (int i = 0; i < languageKeyList.Count; i++) { string key = languageKeyList[i]; if (!string.IsNullOrEmpty(searchKey)) if (!key.Contains(searchKey)) continue; GUILayout.Space(5); GUILayout.BeginVertical("HelpBox"); EditorGUILayout.BeginHorizontal(); string content = ""; if (data != null) { if (!data.ContainsKey(key)) { SingleData sd = new SingleData(); sd.Add(LanguageManager.c_mainKey, key); sd.Add(LanguageManager.c_valueKey, ""); data.AddData(sd); } content = data[key].GetString(LanguageManager.c_valueKey); } if (GUILayout.Button("X", GUILayout.Width(20))) { if (EditorUtility.DisplayDialog("提示", "确定删除key", "OK", "Cancel")) { DeleteKey(selectFullFileName, key); Init(); return; } } GUILayout.Label(key); GUILayout.FlexibleSpace(); if (GUILayout.Button("CopyPath")) { string tempContent = selectFullFileName; tempContent += "/" + key; TextEditor tx = new TextEditor(); tx.text = tempContent; tx.OnFocus(); tx.Copy(); ShowNotification(new GUIContent("已复制")); } EditorGUILayout.EndHorizontal(); GUIStyle style = "TextArea"; style.wordWrap = true; style.richText = richText; content = EditorGUILayout.TextArea(content, style); if (data != null) { data[key][LanguageManager.c_valueKey] = content; } GUILayout.EndVertical(); } }, "box"); }
void EditorLanguageFieldGUI( ) { if (string.IsNullOrEmpty(selectEditorModuleName)) { return; } if (string.IsNullOrEmpty(m_currentLanguage)) { return; } List <string> languageKeyList = s_languageKeyDict[selectEditorModuleName]; DataTable data = null; if (m_langeuageDataDict.ContainsKey(selectEditorModuleName)) { data = m_langeuageDataDict[selectEditorModuleName]; } EditorGUI.indentLevel++; AddLangeuageFieldGUI(languageKeyList); EditorGUILayout.Space(); EditorDrawGUIUtil.DrawScrollView(languageKeyList, () => { for (int i = 0; i < languageKeyList.Count; i++) { string key = languageKeyList[i]; if (!string.IsNullOrEmpty(searchModuleKey)) { if (!key.Contains(searchModuleKey)) { continue; } } GUILayout.Space(5); GUILayout.BeginVertical("HelpBox"); EditorGUILayout.BeginHorizontal(); string content = ""; if (data != null) { if (!data.ContainsKey(key)) { SingleData sd = new SingleData(); sd.Add(LanguageManager.c_mainKey, key); sd.Add(LanguageManager.c_valueKey, ""); data.AddData(sd); } content = data[key].GetString(LanguageManager.c_valueKey); } if (GUILayout.Button("X", GUILayout.Width(20))) { if (EditorUtility.DisplayDialog("提示", "确定删除key", "OK", "Cancel")) { languageKeyList.RemoveAt(i); data.Remove(key); return; } } GUILayout.Label(key); GUILayout.FlexibleSpace(); if (GUILayout.Button("CopyPath")) { string tempContent = selectEditorModuleName.Replace('_', '/'); tempContent += "/" + key; TextEditor tx = new TextEditor(); tx.text = tempContent; tx.OnFocus(); tx.Copy(); ShowNotification(new GUIContent("已复制")); } EditorGUILayout.EndHorizontal(); GUIStyle style = "TextArea"; style.wordWrap = true; style.richText = richText; content = EditorGUILayout.TextArea(content, style); if (data != null) { data[key][LanguageManager.c_valueKey] = content; } GUILayout.EndVertical(); } }, "box"); }
void CreateModuleByConfigData() { m_newModelName = EditorGUILayout.TextField("模块名", m_newModelName); tableName = EditorDrawGUIUtil.DrawPopup("表格名", tableName, configFileNames, (value) => { if (string.IsNullOrEmpty(value)) { return; } fieldNames.Clear(); DataTable d = DataManager.GetData(value); List <string> tempList = new List <string>(); foreach (var item in d.TableKeys) { if (d.m_tableTypes.ContainsKey(item) && d.m_tableTypes[item] == FieldType.String) { tempList.Add(item); } } fieldNames.AddRange(tempList); }); fieldName = EditorDrawGUIUtil.DrawPopup("字段名", fieldName, fieldNames); if (m_newModelName != "" && !s_languageKeyDict.ContainsKey(m_newModelName) && m_currentLanguage != "None") { if (GUILayout.Button("新增模块")) { string modulePath = m_newModelName.Replace("_", "/"); DataTable d = DataManager.GetData(tableName); s_languageKeyDict.Add(m_newModelName, d.TableIDs); DataTable data = new DataTable(); data.TableKeys.Add(LanguageManager.c_mainKey); data.TableKeys.Add(LanguageManager.c_valueKey); data.SetDefault(LanguageManager.c_valueKey, "NoValue"); foreach (var item in d.TableIDs) { object obj = null; if (d[item].ContainsKey(fieldName)) { obj = d[item][fieldName]; } else { obj = d.m_defaultValue[fieldName]; } SingleData sd = new SingleData(); sd.Add(LanguageManager.c_mainKey, item); sd.Add(LanguageManager.c_valueKey, obj.ToString()); data.AddData(sd); d[item][fieldName] = modulePath + "/" + item; } d.m_fieldAssetTypes[fieldName] = DataFieldAssetType.LocalizedLanguage; m_langeuageDataDict.Add(m_newModelName, data); DataEditorWindow.SaveData(tableName, d); SaveData(); AssetDatabase.Refresh(); } EditorGUILayout.Space(); } else { if (s_languageKeyDict.ContainsKey(m_newModelName)) { EditorGUILayout.LabelField("模块名重复!", EditorGUIStyleData.WarnMessageLabel); } } }
SingleData EditorDataGUI(DataTable table, SingleData data) { try { List<string> keys = table.TableKeys; for (int i = 0; i < keys.Count; i++) { string keyTmp = keys[i]; FieldType type = table.GetFieldType(keyTmp); if (i != 0) { bool cancelDefault = false; EditorGUILayout.BeginHorizontal(); if (data.ContainsKey(keyTmp)) { EditorGUILayout.LabelField("[" + keyTmp + "]"); if (GUILayout.Button("使用默认值")) { data.Remove(keyTmp); EditorGUILayout.EndHorizontal(); continue; } } else { EditorGUILayout.LabelField("[" + keyTmp + "] (默认值)"); if (GUILayout.Button("取消默认值")) { cancelDefault = true; } } EditorGUILayout.EndHorizontal(); //EditorGUI.indentLevel++; EditorGUI.indentLevel++; //非默认值情况 if (data.ContainsKey(keyTmp)) { EditorGUILayout.LabelField("字段名", keyTmp); EditorGUILayout.LabelField("注释", table.GetNote(keyTmp)); string newContent = EditorUtilGUI.FieldGUI_TypeValue(type, data[keyTmp], table.GetEnumType(keyTmp)); if (newContent != data[keyTmp]) { data[keyTmp] = newContent; } } //如果是默认值则走这里 else { EditorGUILayout.LabelField("字段名", keyTmp); EditorGUILayout.LabelField("注释", table.GetNote(keyTmp)); string newContent = ""; if (table.m_defaultValue.ContainsKey(keyTmp)) { newContent = new SingleField(type, table.GetDefault(keyTmp), table.GetEnumType(keyTmp)).m_content; } else { newContent = new SingleField(type, null, table.GetEnumType(keyTmp)).m_content; } if (type != FieldType.Enum) { EditorGUILayout.LabelField("字段类型", type.ToString()); } else { EditorGUILayout.LabelField("字段类型", type.ToString() + "/" + table.GetEnumType(keyTmp)); } EditorGUILayout.LabelField("(默认)字段内容", new SingleField(type, newContent, table.GetEnumType(keyTmp)).GetShowString()); if (cancelDefault) { data.Add(keyTmp, newContent); } } EditorGUI.indentLevel--; //EditorGUI.indentLevel--; } EditorGUILayout.Space(); } } catch(Exception e) { EditorGUILayout.TextArea(e.ToString(),EditorGUIStyleData.s_ErrorMessageLabel); } return data; }