A game about forced loneliness, made by TACStudios
1using UnityEditor.AnimatedValues;
2using UnityEngine;
3using UnityEngine.UI;
4
5namespace UnityEditor.UI
6{
7 [CanEditMultipleObjects]
8 [CustomEditor(typeof(InputField), true)]
9 /// <summary>
10 /// Custom Editor for the InputField Component.
11 /// Extend this class to write a custom editor for a component derived from InputField.
12 /// </summary>
13 public class InputFieldEditor : SelectableEditor
14 {
15 SerializedProperty m_TextComponent;
16 SerializedProperty m_Text;
17 SerializedProperty m_ContentType;
18 SerializedProperty m_LineType;
19 SerializedProperty m_InputType;
20 SerializedProperty m_CharacterValidation;
21 SerializedProperty m_KeyboardType;
22 SerializedProperty m_CharacterLimit;
23 SerializedProperty m_CaretBlinkRate;
24 SerializedProperty m_CaretWidth;
25 SerializedProperty m_CaretColor;
26 SerializedProperty m_CustomCaretColor;
27 SerializedProperty m_SelectionColor;
28 SerializedProperty m_HideMobileInput;
29 SerializedProperty m_Placeholder;
30 SerializedProperty m_OnValueChanged;
31 SerializedProperty m_OnSubmit;
32 SerializedProperty m_OnDidEndEdit;
33 SerializedProperty m_ReadOnly;
34 SerializedProperty m_ShouldActivateOnSelect;
35
36 AnimBool m_CustomColor;
37
38 GUIContent m_EndEditContent = new GUIContent("On End Edit");
39
40 protected override void OnEnable()
41 {
42 base.OnEnable();
43 m_TextComponent = serializedObject.FindProperty("m_TextComponent");
44 m_Text = serializedObject.FindProperty("m_Text");
45 m_ContentType = serializedObject.FindProperty("m_ContentType");
46 m_LineType = serializedObject.FindProperty("m_LineType");
47 m_InputType = serializedObject.FindProperty("m_InputType");
48 m_CharacterValidation = serializedObject.FindProperty("m_CharacterValidation");
49 m_KeyboardType = serializedObject.FindProperty("m_KeyboardType");
50 m_CharacterLimit = serializedObject.FindProperty("m_CharacterLimit");
51 m_CaretBlinkRate = serializedObject.FindProperty("m_CaretBlinkRate");
52 m_CaretWidth = serializedObject.FindProperty("m_CaretWidth");
53 m_CaretColor = serializedObject.FindProperty("m_CaretColor");
54 m_CustomCaretColor = serializedObject.FindProperty("m_CustomCaretColor");
55 m_SelectionColor = serializedObject.FindProperty("m_SelectionColor");
56 m_HideMobileInput = serializedObject.FindProperty("m_HideMobileInput");
57 m_Placeholder = serializedObject.FindProperty("m_Placeholder");
58 m_OnValueChanged = serializedObject.FindProperty("m_OnValueChanged");
59 m_OnSubmit = serializedObject.FindProperty("m_OnSubmit");
60 m_OnDidEndEdit = serializedObject.FindProperty("m_OnDidEndEdit");
61 m_ReadOnly = serializedObject.FindProperty("m_ReadOnly");
62 m_ShouldActivateOnSelect = serializedObject.FindProperty("m_ShouldActivateOnSelect");
63
64 m_CustomColor = new AnimBool(m_CustomCaretColor.boolValue);
65 m_CustomColor.valueChanged.AddListener(Repaint);
66 }
67
68 protected override void OnDisable()
69 {
70 base.OnDisable();
71 m_CustomColor.valueChanged.RemoveListener(Repaint);
72 }
73
74 public override void OnInspectorGUI()
75 {
76 serializedObject.Update();
77
78 base.OnInspectorGUI();
79
80 EditorGUILayout.Space();
81
82 EditorGUILayout.PropertyField(m_TextComponent);
83
84 if (m_TextComponent != null && m_TextComponent.objectReferenceValue != null)
85 {
86 Text text = m_TextComponent.objectReferenceValue as Text;
87 if (text.supportRichText)
88 {
89 EditorGUILayout.HelpBox("Using Rich Text with input is unsupported.", MessageType.Warning);
90 }
91 }
92
93 using (new EditorGUI.DisabledScope(m_TextComponent == null || m_TextComponent.objectReferenceValue == null))
94 {
95 EditorGUILayout.PropertyField(m_Text);
96 EditorGUILayout.PropertyField(m_CharacterLimit);
97
98 EditorGUILayout.Space();
99
100 EditorGUILayout.PropertyField(m_ContentType);
101 if (!m_ContentType.hasMultipleDifferentValues)
102 {
103 EditorGUI.indentLevel++;
104
105 if (m_ContentType.enumValueIndex == (int)InputField.ContentType.Standard ||
106 m_ContentType.enumValueIndex == (int)InputField.ContentType.Autocorrected ||
107 m_ContentType.enumValueIndex == (int)InputField.ContentType.Custom)
108 EditorGUILayout.PropertyField(m_LineType);
109
110 if (m_ContentType.enumValueIndex == (int)InputField.ContentType.Custom)
111 {
112 EditorGUILayout.PropertyField(m_InputType);
113 EditorGUILayout.PropertyField(m_KeyboardType);
114 EditorGUILayout.PropertyField(m_CharacterValidation);
115 }
116
117 EditorGUI.indentLevel--;
118 }
119
120 EditorGUILayout.Space();
121
122 EditorGUILayout.PropertyField(m_Placeholder);
123 EditorGUILayout.PropertyField(m_CaretBlinkRate);
124 EditorGUILayout.PropertyField(m_CaretWidth);
125
126 EditorGUILayout.PropertyField(m_CustomCaretColor);
127
128 m_CustomColor.target = m_CustomCaretColor.boolValue;
129
130 if (EditorGUILayout.BeginFadeGroup(m_CustomColor.faded))
131 {
132 EditorGUILayout.PropertyField(m_CaretColor);
133 }
134 EditorGUILayout.EndFadeGroup();
135
136 EditorGUILayout.PropertyField(m_SelectionColor);
137 EditorGUILayout.PropertyField(m_HideMobileInput);
138 EditorGUILayout.PropertyField(m_ReadOnly);
139 EditorGUILayout.PropertyField(m_ShouldActivateOnSelect);
140
141 EditorGUILayout.Space();
142
143 EditorGUILayout.PropertyField(m_OnValueChanged);
144 EditorGUILayout.PropertyField(m_OnSubmit);
145 EditorGUILayout.PropertyField(m_OnDidEndEdit, m_EndEditContent);
146 }
147
148 serializedObject.ApplyModifiedProperties();
149 }
150 }
151}