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 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 (newType == FieldType.Enum) { int newIndex = EditorGUILayout.Popup("枚举类型", m_newTypeIndex, EditorTool.GetAllEnumType()); if (newIndex != m_newTypeIndex) { m_newTypeIndex = newIndex; isNewType = true; } } if (content.m_type != newType) { 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_currentRecord.Add(fieldName, content); fieldName = ""; content = new SingleField(); newType = content.m_type; } EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); } else { if (dict.ContainsKey(fieldName)) { EditorGUILayout.LabelField("已存在该字段"); } } } }
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(); } }