//编辑角色数据 private void EditorPlayerDataGUI() { if (m_curPlayerIndex == 0) { return; } var fieldData = new SingleField(FieldType.String, playerId, null); playerId = EditorUtilGUI.FieldGUI_Type(fieldData, "角色ID"); fieldData = new SingleField(FieldType.String, playerName, null); playerName = EditorUtilGUI.FieldGUI_Type(fieldData, "角色名"); fieldData = new SingleField(FieldType.String, startTalkId, null); startTalkId = EditorUtilGUI.FieldGUI_Type(fieldData, "初始对话ID"); if (GUILayout.Button("保存")) { playerContent["player_id"] = playerId; playerContent["player_name"] = playerName; playerContent["start_talk_id"] = startTalkId; //设置字段类型 m_curPlayerDatas.SetFieldType("player_id", FieldType.String); m_curPlayerDatas.SetFieldType("player_name", FieldType.String); m_curPlayerDatas.SetFieldType("start_talk_id", FieldType.String); m_curPlayerDatas.SetData(playerContent); DataEditorWindow.SaveData(m_playerCfgName, m_curPlayerDatas); } }
void ConfigItemGUI(Dictionary <string, SingleField> dict, string key) { EditorGUI.indentLevel = 2; string newContent = ""; SingleField data = dict[key]; EditorGUILayout.LabelField(key); EditorGUI.indentLevel = 3; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("字段类型:", data.m_type.ToString()); if (GUILayout.Button("删除字段")) { if (EditorUtility.DisplayDialog("警告", "确定要删除该字段吗!", "是", "取消")) { dict.Remove(key); return; } } EditorGUILayout.EndHorizontal(); newContent = EditorUtilGUI.FieldGUI_Type(data); if (data.GetString() != newContent) { data.m_content = newContent; } EditorGUILayout.Space(); }
//创建对话部分 private void AddTalkGUI() { if (string.IsNullOrEmpty(playerId)) { return; } if (string.IsNullOrEmpty(m_curChapterId)) { return; } //当前没有选中对话时,才显示 if (m_curTalkIndex != 0) { return; } if (m_playerTalkDatas == null) { return; } EditorGUILayout.Space(); newTalkIsFfold = EditorGUILayout.Foldout(newTalkIsFfold, "创建对话"); if (newTalkIsFfold) { EditorGUI.indentLevel++; var fieldData = new SingleField(FieldType.String, m_inputTalkId, null); m_inputTalkId = EditorUtilGUI.FieldGUI_Type(fieldData, "对话ID"); if (string.IsNullOrEmpty(m_inputTalkId)) { EditorGUILayout.LabelField("输入要添加的ID(对话id从1001开始)=,,="); } else if (m_playerTalkDatas.ContainsKey(m_inputTalkId)) { EditorGUILayout.LabelField("重复啦=..="); } EditorGUILayout.Space(); if (!m_playerTalkDatas.ContainsKey(m_inputTalkId) && !string.IsNullOrEmpty(m_inputTalkId)) { EditorGUILayout.Space(); if (GUILayout.Button("创建")) { CreateNewTalk(m_inputTalkId); m_inputTalkId = string.Empty; } EditorGUILayout.Space(); } EditorGUILayout.Space(); } }
//对话编辑部分 private void EditorTalkContentGUI() { EditorGUI.indentLevel++; for (var j = 0; j < m_maxTalkContentCnt; ++j) { var foldName = string.Format("分支对话{0}", j + 1); m_talkFold[j] = EditorGUILayout.Foldout(m_talkFold[j], foldName); if (m_talkFold[j]) { EditorGUILayout.Space(); //当前玩家对话内容编辑 var fieldData = new SingleField(FieldType.String, m_pTalkText[j], null); m_pTalkText[j] = EditorUtilGUI.FieldGUI_Type(fieldData, string.Format("玩家对话内容")); //当前npc回答对话内容编辑 fieldData = new SingleField(FieldType.String, m_nTalkText[j], null); m_nTalkText[j] = EditorUtilGUI.FieldGUI_Type(fieldData, string.Format("NPC对话内容")); //下一个对话 fieldData = new SingleField(FieldType.String, m_nextTalkId[j], null); m_nextTalkId[j] = EditorUtilGUI.FieldGUI_Type(fieldData, string.Format("下个对话ID")); EditorGUILayout.Space(); //todo 向下一个对话跳转 if (!string.IsNullOrEmpty(m_nextTalkId[j])) { if (GUILayout.Button(string.Format("跳转到:{0}", m_nextTalkId[j]))) { if (!m_playerTalkDatas.ContainsKey(m_nextTalkId[j])) { CreateNewTalk(m_nextTalkId[j]); return; } for (var i = 0; i < m_talkList.Count; ++i) { if (m_nextTalkId[j] == m_talkList[i]) { m_curTalkIndex = i; } } LoadTalkData(m_nextTalkId[j]); } } } } }
public static string FieldGUI_Type(FieldType type, string enumType, string content, string labelContent = "字段内容") { try { SingleField data = new SingleField(type, content, enumType); return(EditorUtilGUI.FieldGUI_Type(data, labelContent)); } catch (Exception e) { EditorGUILayout.LabelField("解析错误:", e.ToString(), "ErrorLabel"); return(content); } }
public static string FieldGUI_TypeValue(SingleField data) { if (data.m_type != FieldType.Enum) { EditorGUILayout.LabelField("字段类型", data.m_type.ToString()); } else { EditorGUILayout.LabelField("字段类型", data.m_type.ToString() + "/" + data.m_enumType); } return(EditorUtilGUI.FieldGUI_Type(data)); }
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(); } }
void ViewItemGUI(string key, object obj) { if (!m_foldDict.ContainsKey(key)) { m_foldDict.Add(key, false); } m_foldDict[key] = EditorGUILayout.Foldout(m_foldDict[key], key + ":"); if (m_foldDict[key]) { EditorGUI.indentLevel++; EditorUtilGUI.DrawClassData(obj, key); EditorGUI.indentLevel--; } }
void AddFieldGUI(Dictionary <string, SingleField> dict) { EditorGUI.indentLevel = 1; isFold = EditorGUILayout.Foldout(isFold, "新增字段"); if (isFold) { EditorGUI.indentLevel = 2; fieldName = EditorGUILayout.TextField("字段名", fieldName); newType = (FieldType)EditorGUILayout.EnumPopup("字段类型", content.m_type); if (content.m_type != newType) { content.m_type = newType; content.Reset(); } content.m_content = EditorUtilGUI.FieldGUI_Type(content); if (!dict.ContainsKey(fieldName) && fieldName != "") { EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button("新增", GUILayout.Width(position.width - 60))) { m_currentConfig.Add(fieldName, content); fieldName = ""; content = new SingleField(); newType = content.m_type; } EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); } else { if (dict.ContainsKey(fieldName)) { EditorGUILayout.LabelField("已存在该字段"); } } } }
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(); } }
void AddFieldGUI() { isAddFoldField = EditorGUILayout.Foldout(isAddFoldField, "新增字段"); EditorGUI.indentLevel++; if (isAddFoldField) { newFieldName = EditorGUILayout.TextField("字段名", newFieldName); FieldType typeTmp = (FieldType)EditorGUILayout.EnumPopup("字段类型", newAddType); if (typeTmp != newAddType) { newAddType = typeTmp; newFieldDefaultValue = new SingleField(newAddType, null).m_content; } bool isShowButton = true; if (newFieldName == "") { isShowButton = false; } if (m_currentData.TableKeys.Contains(newFieldName)) { isShowButton = false; EditorGUILayout.TextField("字段名不能重复!", EditorGUIStyleData.s_WarnMessageLabel); } newFieldDefaultValue = EditorUtilGUI.FieldGUI_Type(newAddType, newFieldDefaultValue, "默认值"); if (isShowButton) { if (GUILayout.Button("新增字段")) { AddField(m_currentData, newFieldName, newAddType, newFieldDefaultValue); newFieldName = ""; newFieldDefaultValue = ""; newAddType = FieldType.String; } } } }
T SelectSDKInterfaceGUI <T>(ref bool isFold, Type SDKType, T sdk, string title) where T : SDKInterfaceBase { isFold = EditorGUILayout.Foldout(isFold, title + ":"); if (isFold) { EditorGUI.indentLevel++; EditorGUILayout.LabelField("接口类型:" + SDKType.Name); string[] mask = GetSDKNameList(SDKType); int currentIndex = GetNameListIndex(mask, sdk); int index = EditorGUILayout.Popup("当前SDK:", currentIndex, mask); if (sdk == null || mask[index] != sdk.GetType().Name) { Type type = Assembly.Load("Assembly-CSharp").GetType(mask[index]); if (type != null) { sdk = (T)Activator.CreateInstance(type); } else { Debug.LogError("Load " + mask[index] + " Fail!"); } } //显示界面 EditorUtilGUI.DrawClassData(sdk); EditorGUI.indentLevel--; EditorGUILayout.Space(); } return(sdk); }
void EditorDataGUI() { isEditorFold = EditorGUILayout.Foldout(isEditorFold, "编辑数据"); EditorGUI.indentLevel++; if (isEditorFold) { List <string> keys = m_currentData.TableKeys; EditorPos = EditorGUILayout.BeginScrollView(EditorPos, GUILayout.ExpandHeight(false)); for (int i = 0; i < keys.Count; i++) { string key = keys[i]; FieldType type = m_currentData.GetFieldType(key); if (i == 0) { EditorGUILayout.LabelField("<主键>字段名", key); EditorGUILayout.LabelField("字段类型", m_currentData.GetFieldType(keys[i]).ToString()); } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("字段名", key); if (GUILayout.Button("删除字段")) { if (EditorUtility.DisplayDialog("警告", "确定要删除该字段吗?", "是", "取消")) { DeleteField(m_currentData, key); continue; } } EditorGUILayout.EndHorizontal(); newType = (FieldType)EditorGUILayout.EnumPopup("字段类型", m_currentData.GetFieldType(keys[i])); if (type != newType) { //弹出警告并重置数据 if (EditorUtility.DisplayDialog("警告", "改变字段类型会重置该字段的所有数据和默认值\n是否继续?", "是", "取消")) { m_currentData.SetFieldType(key, newType); ResetDataField(m_currentData, key, newType); type = newType; content = new SingleData(); } } string newContent = EditorUtilGUI.FieldGUI_Type(type, m_currentData.GetDefault(key), "默认值"); m_currentData.SetDefault(key, newContent); } EditorGUILayout.Space(); } EditorGUILayout.EndScrollView(); AddFieldGUI(); } }
public static string FieldGUI_Type(FieldType type, string enumType, string content, string labelContent = "字段内容") { SingleField data = new SingleField(type, content, enumType); return(EditorUtilGUI.FieldGUI_Type(data, labelContent)); }
public static string FieldGUI_TypeValue(SingleField data) { EditorGUILayout.LabelField("字段类型:", data.m_type.ToString()); return(EditorUtilGUI.FieldGUI_Type(data)); }
public static string FieldGUI_TypeValue(FieldType type, string content, string enumType) { SingleField data = new SingleField(type, content, enumType); return(EditorUtilGUI.FieldGUI_TypeValue(data)); }
void AddFieldGUI(Dictionary <string, SingleField> dict) { EditorGUI.indentLevel = 1; isFold = EditorGUILayout.Foldout(isFold, "新增字段"); if (isFold) { EditorGUI.indentLevel = 2; bool isNewType = false; fieldName = EditorGUILayout.TextField("字段名", fieldName); newType = (FieldType)EditorGUILayout.EnumPopup("字段类型", content.m_type); if (content.m_type != newType) { isNewType = true; } if (newType == FieldType.Enum) { int newIndex = EditorGUILayout.Popup("枚举类型", m_newTypeIndex, EditorTool.GetAllEnumType()); if (newIndex != m_newTypeIndex) { m_newTypeIndex = newIndex; isNewType = true; } } if (isNewType) { content.m_type = newType; content.m_enumType = EditorTool.GetAllEnumType()[m_newTypeIndex]; content.Reset(); } content.m_content = EditorUtilGUI.FieldGUI_Type(content); if (!dict.ContainsKey(fieldName) && fieldName != "") { EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button("新增", GUILayout.Width(position.width - 60))) { m_currentConfig.Add(fieldName, content); fieldName = ""; content = new SingleField(); newType = content.m_type; m_newTypeIndex = 0; } EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); } else { if (dict.ContainsKey(fieldName)) { EditorGUILayout.LabelField("已存在该字段"); } } } }
void AddFieldGUI() { EditorGUILayout.Space(); m_isAddFoldField = EditorGUILayout.Foldout(m_isAddFoldField, "新增字段"); EditorGUI.indentLevel++; if (m_isAddFoldField) { m_newFieldName = EditorGUILayout.TextField("字段名", m_newFieldName); FieldType typeTmp = (FieldType)EditorGUILayout.EnumPopup("字段类型", m_newAddType); bool isNewFieldType = false; if (typeTmp != m_newAddType) { m_newAddType = typeTmp; isNewFieldType = true; } m_addNoteContent = EditorGUILayout.TextField("注释", m_addNoteContent); if (typeTmp == FieldType.Enum) { int newEnumTypeIndex = EditorGUILayout.Popup("枚举类型", m_newEnumTypeIndex, EditorTool.GetAllEnumType()); if (newEnumTypeIndex != m_newEnumTypeIndex) { m_newEnumTypeIndex = newEnumTypeIndex; isNewFieldType = true; } } //更改字段类型重设初始值 if (isNewFieldType) { if (typeTmp == FieldType.Enum) { m_newFieldDefaultValue = new SingleField(m_newAddType, null, EditorTool.GetAllEnumType()[m_newEnumTypeIndex]).m_content; } else { m_newFieldDefaultValue = new SingleField(m_newAddType, null, null).m_content; } } //是否是一个合理的字段名 bool isShowButton = true; if (m_newFieldName == "") { isShowButton = false; } if (m_currentData.TableKeys.Contains(m_newFieldName)) { isShowButton = false; EditorGUILayout.TextField("字段名不能重复!", EditorGUIStyleData.s_WarnMessageLabel); } m_newFieldDefaultValue = EditorUtilGUI.FieldGUI_Type(m_newAddType, EditorTool.GetAllEnumType()[m_newEnumTypeIndex], m_newFieldDefaultValue, "默认值"); if (isShowButton) { if (GUILayout.Button("新增字段")) { if (m_newAddType == FieldType.Enum) { AddField(m_currentData, m_newFieldName, m_newAddType, m_newFieldDefaultValue, EditorTool.GetAllEnumType()[m_newEnumTypeIndex], m_addNoteContent); } else { AddField(m_currentData, m_newFieldName, m_newAddType, m_newFieldDefaultValue, null, m_addNoteContent); } m_newFieldName = ""; m_newFieldDefaultValue = ""; m_addNoteContent = ""; m_newAddType = FieldType.String; m_newEnumTypeIndex = 0; } } } }
void EditorDataGUI() { m_isEditorFold = EditorGUILayout.Foldout(m_isEditorFold, "编辑数据"); EditorGUI.indentLevel++; if (m_isEditorFold) { List <string> keys = m_currentData.TableKeys; m_EditorPos = EditorGUILayout.BeginScrollView(m_EditorPos, GUILayout.ExpandHeight(false)); for (int i = 0; i < keys.Count; i++) { string key = keys[i]; FieldType type = m_currentData.GetFieldType(key); int EnumTypeIndex = EditorTool.GetAllEnumTypeIndex(m_currentData.GetEnumType(key)); if (i == 0) { EditorGUILayout.LabelField("<主键>字段名", key); EditorGUILayout.LabelField("字段类型", m_currentData.GetFieldType(keys[i]).ToString()); } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("字段名", key); if (GUILayout.Button("删除字段")) { if (EditorUtility.DisplayDialog("警告", "确定要删除该字段吗?", "是", "取消")) { DeleteField(m_currentData, key); continue; } } EditorGUILayout.EndHorizontal(); bool isNewType = false; m_editorNoteContent = EditorGUILayout.TextField("注释", m_currentData.GetNote(key)); m_currentData.SetNote(key, m_editorNoteContent); m_editorNewType = (FieldType)EditorGUILayout.EnumPopup("字段类型", type); if (m_editorNewType == FieldType.Enum) { m_editorNewEnumIndex = EditorGUILayout.Popup("枚举类型", EnumTypeIndex, EditorTool.GetAllEnumType()); if (EnumTypeIndex != m_editorNewEnumIndex) { isNewType = true; } } if (type != m_editorNewType) { isNewType = true; } if (isNewType) { //弹出警告并重置数据 if (EditorUtility.DisplayDialog("警告", "改变字段类型会重置该字段的所有数据和默认值\n是否继续?", "是", "取消")) { m_currentData.SetFieldType(key, m_editorNewType, EditorTool.GetAllEnumType()[m_editorNewEnumIndex]); ResetDataField(m_currentData, key, m_editorNewType, EditorTool.GetAllEnumType()[m_editorNewEnumIndex]); type = m_editorNewType; EnumTypeIndex = m_editorNewEnumIndex; content = new SingleData(); } } string newContent; if (type == FieldType.Enum) { newContent = EditorUtilGUI.FieldGUI_Type(type, EditorTool.GetAllEnumType()[EnumTypeIndex], m_currentData.GetDefault(key), "默认值"); } else { newContent = EditorUtilGUI.FieldGUI_Type(type, null, m_currentData.GetDefault(key), "默认值"); } m_currentData.SetDefault(key, newContent); } EditorGUILayout.Space(); } EditorGUILayout.EndScrollView(); AddFieldGUI(); } }
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); }