From e846c64d6f927879cb8a095e62d773a8d7b3c9f4 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 15 Oct 2020 07:24:10 +0800 Subject: *ability system --- .../AdvancedInspector/FieldEditors/StringEditor.cs | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 Assets/Plugins/Editor/AdvancedInspector/FieldEditors/StringEditor.cs (limited to 'Assets/Plugins/Editor/AdvancedInspector/FieldEditors/StringEditor.cs') diff --git a/Assets/Plugins/Editor/AdvancedInspector/FieldEditors/StringEditor.cs b/Assets/Plugins/Editor/AdvancedInspector/FieldEditors/StringEditor.cs new file mode 100644 index 00000000..573450d9 --- /dev/null +++ b/Assets/Plugins/Editor/AdvancedInspector/FieldEditors/StringEditor.cs @@ -0,0 +1,89 @@ +using UnityEngine; +using UnityEditor; +using System; +using System.Collections; + +namespace AdvancedInspector +{ + public class StringEditor : FieldEditor + { + public override Type[] EditedTypes + { + get { return new Type[] { typeof(string) }; } + } + + public override void Draw(InspectorField field, GUIStyle style) + { + GUILayout.BeginHorizontal(); + + float width = EditorGUIUtility.labelWidth; + EditorGUIUtility.labelWidth = 0; + + TextFieldAttribute text = field.GetAttribute(); + MultilineAttribute multiline = field.GetAttribute(); + TextAreaAttribute area = field.GetAttribute(); + + object value = GetValue(field); + + EditorGUI.BeginChangeCheck(); + GUIUtility.GetControlID(field.Path.GetHashCode(), FocusType.Passive); + + string result = ""; + if ((text == null && multiline == null && area == null) || (text != null && text.Type == TextFieldType.Standard)) + { + if (style != null) + result = EditorGUILayout.TextField((string)value, style); + else + result = EditorGUILayout.TextField((string)value); + } + else if (multiline != null || area != null || text.Type == TextFieldType.Area) + { + if (style != null) + result = EditorGUILayout.TextArea((string)value, style); + else + result = EditorGUILayout.TextArea((string)value); + } + else if (text.Type == TextFieldType.Password) + { + if (style != null) + result = EditorGUILayout.PasswordField((string)value, style); + else + result = EditorGUILayout.PasswordField((string)value); + } + else if (text.Type == TextFieldType.Tag) + { + if (style != null) + result = EditorGUILayout.TagField((string)value, style); + else + result = EditorGUILayout.TagField((string)value); + } + else if (text.Type == TextFieldType.File) + { + if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2))) + result = EditorUtility.OpenFilePanel(text.Title, text.Path, text.Extension); + + if (field.Mixed) + GUILayout.Label("---"); + else + GUILayout.Label((string)value); + } + else if (text.Type == TextFieldType.Folder) + { + if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2))) + result = EditorUtility.OpenFolderPanel(text.Title, "", ""); + + if (field.Mixed) + GUILayout.Label("---"); + else + GUILayout.Label((string)value); + } + + if (EditorGUI.EndChangeCheck()) + field.SetValue(result); + + EditorGUIUtility.labelWidth = width; + + GUILayout.EndHorizontal(); + } + } +} \ No newline at end of file -- cgit v1.1-26-g67d0