A game about forced loneliness, made by TACStudios
at master 300 lines 14 kB view raw
1using UnityEngine; 2using UnityEngine.UI; 3using UnityEditor; 4using UnityEditor.UI; 5using UnityEditor.AnimatedValues; 6 7 8namespace TMPro.EditorUtilities 9{ 10 [CanEditMultipleObjects] 11 [CustomEditor(typeof(TMP_InputField), true)] 12 public class TMP_InputFieldEditor : SelectableEditor 13 { 14 private struct m_foldout 15 { // Track Inspector foldout panel states, globally. 16 public static bool textInput = true; 17 public static bool fontSettings = true; 18 public static bool extraSettings = true; 19 //public static bool shadowSetting = false; 20 //public static bool materialEditor = true; 21 } 22 23 SerializedProperty m_TextViewport; 24 SerializedProperty m_TextComponent; 25 SerializedProperty m_Text; 26 SerializedProperty m_ContentType; 27 SerializedProperty m_LineType; 28 SerializedProperty m_LineLimit; 29 SerializedProperty m_InputType; 30 SerializedProperty m_CharacterValidation; 31 SerializedProperty m_InputValidator; 32 SerializedProperty m_RegexValue; 33 SerializedProperty m_KeyboardType; 34 SerializedProperty m_CharacterLimit; 35 SerializedProperty m_CaretBlinkRate; 36 SerializedProperty m_CaretWidth; 37 SerializedProperty m_CaretColor; 38 SerializedProperty m_CustomCaretColor; 39 SerializedProperty m_SelectionColor; 40 SerializedProperty m_HideMobileKeyboard; 41 SerializedProperty m_HideMobileInput; 42 SerializedProperty m_Placeholder; 43 SerializedProperty m_VerticalScrollbar; 44 SerializedProperty m_ScrollbarScrollSensitivity; 45 SerializedProperty m_OnValueChanged; 46 SerializedProperty m_OnEndEdit; 47 SerializedProperty m_OnSelect; 48 SerializedProperty m_OnDeselect; 49 SerializedProperty m_ReadOnly; 50 SerializedProperty m_RichText; 51 SerializedProperty m_RichTextEditingAllowed; 52 SerializedProperty m_ResetOnDeActivation; 53 SerializedProperty m_KeepTextSelectionVisible; 54 SerializedProperty m_RestoreOriginalTextOnEscape; 55 SerializedProperty m_ShouldActivateOnSelect; 56 57 SerializedProperty m_OnFocusSelectAll; 58 SerializedProperty m_GlobalPointSize; 59 SerializedProperty m_GlobalFontAsset; 60 61 AnimBool m_CustomColor; 62 63 //TMP_InputValidator m_ValidationScript; 64 65 protected override void OnEnable() 66 { 67 base.OnEnable(); 68 69 m_TextViewport = serializedObject.FindProperty("m_TextViewport"); 70 m_TextComponent = serializedObject.FindProperty("m_TextComponent"); 71 m_Text = serializedObject.FindProperty("m_Text"); 72 m_ContentType = serializedObject.FindProperty("m_ContentType"); 73 m_LineType = serializedObject.FindProperty("m_LineType"); 74 m_LineLimit = serializedObject.FindProperty("m_LineLimit"); 75 m_InputType = serializedObject.FindProperty("m_InputType"); 76 m_CharacterValidation = serializedObject.FindProperty("m_CharacterValidation"); 77 m_InputValidator = serializedObject.FindProperty("m_InputValidator"); 78 m_RegexValue = serializedObject.FindProperty("m_RegexValue"); 79 m_KeyboardType = serializedObject.FindProperty("m_KeyboardType"); 80 m_CharacterLimit = serializedObject.FindProperty("m_CharacterLimit"); 81 m_CaretBlinkRate = serializedObject.FindProperty("m_CaretBlinkRate"); 82 m_CaretWidth = serializedObject.FindProperty("m_CaretWidth"); 83 m_CaretColor = serializedObject.FindProperty("m_CaretColor"); 84 m_CustomCaretColor = serializedObject.FindProperty("m_CustomCaretColor"); 85 m_SelectionColor = serializedObject.FindProperty("m_SelectionColor"); 86 87 m_HideMobileKeyboard = serializedObject.FindProperty("m_HideSoftKeyboard"); 88 m_HideMobileInput = serializedObject.FindProperty("m_HideMobileInput"); 89 90 m_Placeholder = serializedObject.FindProperty("m_Placeholder"); 91 m_VerticalScrollbar = serializedObject.FindProperty("m_VerticalScrollbar"); 92 m_ScrollbarScrollSensitivity = serializedObject.FindProperty("m_ScrollSensitivity"); 93 94 m_OnValueChanged = serializedObject.FindProperty("m_OnValueChanged"); 95 m_OnEndEdit = serializedObject.FindProperty("m_OnEndEdit"); 96 m_OnSelect = serializedObject.FindProperty("m_OnSelect"); 97 m_OnDeselect = serializedObject.FindProperty("m_OnDeselect"); 98 m_ReadOnly = serializedObject.FindProperty("m_ReadOnly"); 99 m_RichText = serializedObject.FindProperty("m_RichText"); 100 m_RichTextEditingAllowed = serializedObject.FindProperty("m_isRichTextEditingAllowed"); 101 m_ResetOnDeActivation = serializedObject.FindProperty("m_ResetOnDeActivation"); 102 m_KeepTextSelectionVisible = serializedObject.FindProperty("m_KeepTextSelectionVisible"); 103 m_RestoreOriginalTextOnEscape = serializedObject.FindProperty("m_RestoreOriginalTextOnEscape"); 104 105 m_OnFocusSelectAll = serializedObject.FindProperty("m_OnFocusSelectAll"); 106 m_ShouldActivateOnSelect = serializedObject.FindProperty("m_ShouldActivateOnSelect"); 107 108 m_GlobalPointSize = serializedObject.FindProperty("m_GlobalPointSize"); 109 m_GlobalFontAsset = serializedObject.FindProperty("m_GlobalFontAsset"); 110 111 m_CustomColor = new AnimBool(m_CustomCaretColor.boolValue); 112 m_CustomColor.valueChanged.AddListener(Repaint); 113 } 114 115 protected override void OnDisable() 116 { 117 base.OnDisable(); 118 m_CustomColor.valueChanged.RemoveListener(Repaint); 119 } 120 121 public override void OnInspectorGUI() 122 { 123 serializedObject.Update(); 124 125 base.OnInspectorGUI(); 126 127 EditorGUILayout.Space(); 128 129 EditorGUILayout.PropertyField(m_TextViewport); 130 131 EditorGUILayout.PropertyField(m_TextComponent); 132 133 TextMeshProUGUI text = null; 134 if (m_TextComponent != null && m_TextComponent.objectReferenceValue != null) 135 { 136 text = m_TextComponent.objectReferenceValue as TextMeshProUGUI; 137 //if (text.supportRichText) 138 //{ 139 // EditorGUILayout.HelpBox("Using Rich Text with input is unsupported.", MessageType.Warning); 140 //} 141 } 142 143 EditorGUI.BeginDisabledGroup(m_TextComponent == null || m_TextComponent.objectReferenceValue == null); 144 145 // TEXT INPUT BOX 146 EditorGUILayout.PropertyField(m_Text); 147 148 // INPUT FIELD SETTINGS 149 #region INPUT FIELD SETTINGS 150 151 m_foldout.fontSettings = EditorGUILayout.Foldout(m_foldout.fontSettings, "Input Field Settings", true, TMP_UIStyleManager.boldFoldout); 152 153 if (m_foldout.fontSettings) 154 { 155 EditorGUI.indentLevel++; 156 EditorGUI.BeginChangeCheck(); 157 EditorGUILayout.PropertyField(m_GlobalFontAsset, new GUIContent("Font Asset", "Set the Font Asset for both Placeholder and Input Field text object.")); 158 if (EditorGUI.EndChangeCheck()) 159 { 160 TMP_InputField inputField = target as TMP_InputField; 161 inputField.SetGlobalFontAsset(m_GlobalFontAsset.objectReferenceValue as TMP_FontAsset); 162 } 163 164 165 EditorGUI.BeginChangeCheck(); 166 EditorGUILayout.PropertyField(m_GlobalPointSize, new GUIContent("Point Size", "Set the point size of both Placeholder and Input Field text object.")); 167 if (EditorGUI.EndChangeCheck()) 168 { 169 TMP_InputField inputField = target as TMP_InputField; 170 inputField.SetGlobalPointSize(m_GlobalPointSize.floatValue); 171 } 172 173 EditorGUI.BeginChangeCheck(); 174 EditorGUILayout.PropertyField(m_CharacterLimit); 175 176 EditorGUILayout.Space(); 177 178 EditorGUILayout.PropertyField(m_ContentType); 179 if (!m_ContentType.hasMultipleDifferentValues) 180 { 181 EditorGUI.indentLevel++; 182 183 if (m_ContentType.enumValueIndex == (int)TMP_InputField.ContentType.Standard || 184 m_ContentType.enumValueIndex == (int)TMP_InputField.ContentType.Autocorrected || 185 m_ContentType.enumValueIndex == (int)TMP_InputField.ContentType.Custom) 186 { 187 EditorGUI.BeginChangeCheck(); 188 EditorGUILayout.PropertyField(m_LineType); 189 if (EditorGUI.EndChangeCheck()) 190 { 191 if (text != null) 192 { 193 if (m_LineType.enumValueIndex == (int)TMP_InputField.LineType.SingleLine) 194 text.textWrappingMode = TextWrappingModes.PreserveWhitespaceNoWrap; 195 else 196 { 197 text.textWrappingMode = TextWrappingModes.Normal; 198 } 199 } 200 } 201 202 if (m_LineType.enumValueIndex != (int)TMP_InputField.LineType.SingleLine) 203 { 204 EditorGUILayout.PropertyField(m_LineLimit); 205 } 206 } 207 208 if (m_ContentType.enumValueIndex == (int)TMP_InputField.ContentType.Custom) 209 { 210 EditorGUILayout.PropertyField(m_InputType); 211 EditorGUILayout.PropertyField(m_KeyboardType); 212 EditorGUILayout.PropertyField(m_CharacterValidation); 213 if (m_CharacterValidation.enumValueIndex == (int)TMP_InputField.CharacterValidation.Regex) 214 { 215 EditorGUILayout.PropertyField(m_RegexValue); 216 } 217 else if (m_CharacterValidation.enumValueIndex == (int)TMP_InputField.CharacterValidation.CustomValidator) 218 { 219 EditorGUILayout.PropertyField(m_InputValidator); 220 } 221 } 222 223 EditorGUI.indentLevel--; 224 } 225 226 EditorGUILayout.Space(); 227 228 EditorGUILayout.PropertyField(m_Placeholder); 229 EditorGUILayout.PropertyField(m_VerticalScrollbar); 230 231 if (m_VerticalScrollbar.objectReferenceValue != null) 232 EditorGUILayout.PropertyField(m_ScrollbarScrollSensitivity); 233 234 EditorGUILayout.PropertyField(m_CaretBlinkRate); 235 EditorGUILayout.PropertyField(m_CaretWidth); 236 237 EditorGUILayout.PropertyField(m_CustomCaretColor); 238 239 m_CustomColor.target = m_CustomCaretColor.boolValue; 240 241 if (EditorGUILayout.BeginFadeGroup(m_CustomColor.faded)) 242 { 243 EditorGUILayout.PropertyField(m_CaretColor); 244 } 245 EditorGUILayout.EndFadeGroup(); 246 247 EditorGUILayout.PropertyField(m_SelectionColor); 248 249 EditorGUI.indentLevel--; 250 } 251 #endregion 252 253 254 // CONTROL SETTINGS 255 #region CONTROL SETTINGS 256 m_foldout.extraSettings = EditorGUILayout.Foldout(m_foldout.extraSettings, "Control Settings", true, TMP_UIStyleManager.boldFoldout); 257 258 if (m_foldout.extraSettings) 259 { 260 EditorGUI.indentLevel++; 261 262 EditorGUILayout.PropertyField(m_OnFocusSelectAll, new GUIContent("OnFocus - Select All", "Should all the text be selected when the Input Field is selected?")); 263 EditorGUILayout.PropertyField(m_ResetOnDeActivation, new GUIContent("Reset On Deactivation", "Should the Text and Caret position be reset when Input Field looses focus and is Deactivated?")); 264 265 EditorGUI.indentLevel++; 266 GUI.enabled = !m_ResetOnDeActivation.boolValue; 267 EditorGUILayout.PropertyField(m_KeepTextSelectionVisible, new GUIContent("Keep Text Selection Visible", "Should the text selection remain visible when the input field looses focus and is deactivated?")); 268 GUI.enabled = true; 269 EditorGUI.indentLevel--; 270 271 EditorGUILayout.PropertyField(m_RestoreOriginalTextOnEscape, new GUIContent("Restore On ESC Key", "Should the original text be restored when pressing ESC? (Property not applicable for HoloLens)")); 272 EditorGUILayout.PropertyField(m_ShouldActivateOnSelect, new GUIContent("Should Activate On Select", "Determines if the Input Field will be activated when selected.")); 273 EditorGUILayout.PropertyField(m_HideMobileKeyboard, new GUIContent("Hide Soft Keyboard", "Controls the visibility of the mobile virtual keyboard.")); 274 275 EditorGUI.BeginDisabledGroup(m_HideMobileKeyboard.boolValue); 276 EditorGUILayout.PropertyField(m_HideMobileInput, new GUIContent("Hide Mobile Input", "Controls the visibility of the editable text field above the mobile virtual keyboard.")); 277 EditorGUI.EndDisabledGroup(); 278 279 EditorGUILayout.PropertyField(m_ReadOnly); 280 EditorGUILayout.PropertyField(m_RichText); 281 EditorGUILayout.PropertyField(m_RichTextEditingAllowed, new GUIContent("Allow Rich Text Editing")); 282 283 EditorGUI.indentLevel--; 284 } 285 #endregion 286 287 288 EditorGUILayout.Space(); 289 290 EditorGUILayout.PropertyField(m_OnValueChanged); 291 EditorGUILayout.PropertyField(m_OnEndEdit); 292 EditorGUILayout.PropertyField(m_OnSelect); 293 EditorGUILayout.PropertyField(m_OnDeselect); 294 295 EditorGUI.EndDisabledGroup(); 296 297 serializedObject.ApplyModifiedProperties(); 298 } 299 } 300}