InputFieldEditor.cs 6.0 KB

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