summaryrefslogtreecommitdiff
path: root/Assets/Plugins/Editor/AdvancedInspector/FieldEditors/StringEditor.cs
blob: 573450d935de7ac9e2b10f6dd434aad82522b9ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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();
        }
    }
}