diff options
author | chai <chaifix@163.com> | 2020-10-15 07:24:10 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-10-15 07:24:10 +0800 |
commit | e846c64d6f927879cb8a095e62d773a8d7b3c9f4 (patch) | |
tree | 7882744bbf2b6c7096ec15fb300f088c5a0807c5 /Assets/Plugins/Editor/AdvancedInspector/FieldEditors/StringEditor.cs | |
parent | cd12e74241678ee3c0752484d310b202187ba24c (diff) |
*ability system
Diffstat (limited to 'Assets/Plugins/Editor/AdvancedInspector/FieldEditors/StringEditor.cs')
-rw-r--r-- | Assets/Plugins/Editor/AdvancedInspector/FieldEditors/StringEditor.cs | 89 |
1 files changed, 89 insertions, 0 deletions
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<TextFieldAttribute>(); + MultilineAttribute multiline = field.GetAttribute<MultilineAttribute>(); + TextAreaAttribute area = field.GetAttribute<TextAreaAttribute>(); + + 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 |