暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

InputFieldEditor.cs 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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_OnSubmit;
  31. SerializedProperty m_OnDidEndEdit;
  32. SerializedProperty m_ReadOnly;
  33. SerializedProperty m_ShouldActivateOnSelect;
  34. AnimBool m_CustomColor;
  35. GUIContent m_EndEditContent = new GUIContent("On End Edit");
  36. protected override void OnEnable()
  37. {
  38. base.OnEnable();
  39. m_TextComponent = serializedObject.FindProperty("m_TextComponent");
  40. m_Text = serializedObject.FindProperty("m_Text");
  41. m_ContentType = serializedObject.FindProperty("m_ContentType");
  42. m_LineType = serializedObject.FindProperty("m_LineType");
  43. m_InputType = serializedObject.FindProperty("m_InputType");
  44. m_CharacterValidation = serializedObject.FindProperty("m_CharacterValidation");
  45. m_KeyboardType = serializedObject.FindProperty("m_KeyboardType");
  46. m_CharacterLimit = serializedObject.FindProperty("m_CharacterLimit");
  47. m_CaretBlinkRate = serializedObject.FindProperty("m_CaretBlinkRate");
  48. m_CaretWidth = serializedObject.FindProperty("m_CaretWidth");
  49. m_CaretColor = serializedObject.FindProperty("m_CaretColor");
  50. m_CustomCaretColor = serializedObject.FindProperty("m_CustomCaretColor");
  51. m_SelectionColor = serializedObject.FindProperty("m_SelectionColor");
  52. m_HideMobileInput = serializedObject.FindProperty("m_HideMobileInput");
  53. m_Placeholder = serializedObject.FindProperty("m_Placeholder");
  54. m_OnValueChanged = serializedObject.FindProperty("m_OnValueChanged");
  55. m_OnSubmit = serializedObject.FindProperty("m_OnSubmit");
  56. m_OnDidEndEdit = serializedObject.FindProperty("m_OnDidEndEdit");
  57. m_ReadOnly = serializedObject.FindProperty("m_ReadOnly");
  58. m_ShouldActivateOnSelect = serializedObject.FindProperty("m_ShouldActivateOnSelect");
  59. m_CustomColor = new AnimBool(m_CustomCaretColor.boolValue);
  60. m_CustomColor.valueChanged.AddListener(Repaint);
  61. }
  62. protected override void OnDisable()
  63. {
  64. base.OnDisable();
  65. m_CustomColor.valueChanged.RemoveListener(Repaint);
  66. }
  67. public override void OnInspectorGUI()
  68. {
  69. serializedObject.Update();
  70. base.OnInspectorGUI();
  71. EditorGUILayout.Space();
  72. EditorGUILayout.PropertyField(m_TextComponent);
  73. if (m_TextComponent != null && m_TextComponent.objectReferenceValue != null)
  74. {
  75. Text text = m_TextComponent.objectReferenceValue as Text;
  76. if (text.supportRichText)
  77. {
  78. EditorGUILayout.HelpBox("Using Rich Text with input is unsupported.", MessageType.Warning);
  79. }
  80. }
  81. using (new EditorGUI.DisabledScope(m_TextComponent == null || m_TextComponent.objectReferenceValue == null))
  82. {
  83. EditorGUILayout.PropertyField(m_Text);
  84. EditorGUILayout.PropertyField(m_CharacterLimit);
  85. EditorGUILayout.Space();
  86. EditorGUILayout.PropertyField(m_ContentType);
  87. if (!m_ContentType.hasMultipleDifferentValues)
  88. {
  89. EditorGUI.indentLevel++;
  90. if (m_ContentType.enumValueIndex == (int)InputField.ContentType.Standard ||
  91. m_ContentType.enumValueIndex == (int)InputField.ContentType.Autocorrected ||
  92. m_ContentType.enumValueIndex == (int)InputField.ContentType.Custom)
  93. EditorGUILayout.PropertyField(m_LineType);
  94. if (m_ContentType.enumValueIndex == (int)InputField.ContentType.Custom)
  95. {
  96. EditorGUILayout.PropertyField(m_InputType);
  97. EditorGUILayout.PropertyField(m_KeyboardType);
  98. EditorGUILayout.PropertyField(m_CharacterValidation);
  99. }
  100. EditorGUI.indentLevel--;
  101. }
  102. EditorGUILayout.Space();
  103. EditorGUILayout.PropertyField(m_Placeholder);
  104. EditorGUILayout.PropertyField(m_CaretBlinkRate);
  105. EditorGUILayout.PropertyField(m_CaretWidth);
  106. EditorGUILayout.PropertyField(m_CustomCaretColor);
  107. m_CustomColor.target = m_CustomCaretColor.boolValue;
  108. if (EditorGUILayout.BeginFadeGroup(m_CustomColor.faded))
  109. {
  110. EditorGUILayout.PropertyField(m_CaretColor);
  111. }
  112. EditorGUILayout.EndFadeGroup();
  113. EditorGUILayout.PropertyField(m_SelectionColor);
  114. EditorGUILayout.PropertyField(m_HideMobileInput);
  115. EditorGUILayout.PropertyField(m_ReadOnly);
  116. EditorGUILayout.PropertyField(m_ShouldActivateOnSelect);
  117. EditorGUILayout.Space();
  118. EditorGUILayout.PropertyField(m_OnValueChanged);
  119. EditorGUILayout.PropertyField(m_OnSubmit);
  120. EditorGUILayout.PropertyField(m_OnDidEndEdit, m_EndEditContent);
  121. }
  122. serializedObject.ApplyModifiedProperties();
  123. }
  124. }
  125. }