SymbolTextEditor.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using UnityEditor;
  2. using UnityEditor.UI;
  3. using UnityEngine.UI;
  4. using System.Collections.Generic;
  5. namespace WXB
  6. {
  7. [CanEditMultipleObjects]
  8. [CustomEditor(typeof(SymbolText), true)]
  9. public class SymbolTextEditor : TextEditor
  10. {
  11. protected SerializedProperty m_Text;
  12. protected SerializedProperty m_FontData;
  13. protected SerializedProperty m_ElementSegment;
  14. protected SerializedProperty m_MinLineHeight;
  15. protected SerializedProperty m_isCheckFontY;
  16. protected SerializedProperty m_LineAlignment;
  17. protected override void OnEnable()
  18. {
  19. base.OnEnable();
  20. m_Text = serializedObject.FindProperty("m_Text");
  21. m_FontData = serializedObject.FindProperty("m_FontData");
  22. m_ElementSegment = serializedObject.FindProperty("m_ElementSegment");
  23. m_MinLineHeight = serializedObject.FindProperty("m_MinLineHeight");
  24. m_isCheckFontY = serializedObject.FindProperty("m_isCheckFontY");
  25. m_LineAlignment = serializedObject.FindProperty("m_LineAlignment");
  26. }
  27. protected virtual void OnGUIFontData()
  28. {
  29. EditorGUILayout.PropertyField(m_Text);
  30. EditorGUILayout.PropertyField(m_FontData);
  31. }
  32. protected virtual void OnGUIOther()
  33. {
  34. }
  35. public override void OnInspectorGUI()
  36. {
  37. serializedObject.Update();
  38. OnGUIFontData();
  39. AppearanceControlsGUI();
  40. RaycastControlsGUI();
  41. EditorGUILayout.PropertyField(m_LineAlignment);
  42. // 元素分割类型
  43. {
  44. List<string> alles = new List<string>();
  45. alles.Add("Empty");
  46. alles.AddRange(ESFactory.GetAllName());
  47. int current = alles.IndexOf(m_ElementSegment.stringValue);
  48. if (current == -1)
  49. current = 0;
  50. int[] optionValues = new int[alles.Count];
  51. for (int i = 0; i < optionValues.Length; ++i)
  52. optionValues[i] = i;
  53. current = EditorGUILayout.IntPopup("Element Segment", current, alles.ToArray(), optionValues);
  54. if (current <= 0)
  55. m_ElementSegment.stringValue = null;
  56. else
  57. m_ElementSegment.stringValue = alles[current];
  58. }
  59. // 最小行高
  60. EditorGUILayout.PropertyField(m_MinLineHeight);
  61. // 是否开启字体高度修正
  62. EditorGUILayout.PropertyField(m_isCheckFontY);
  63. OnGUIOther();
  64. if (serializedObject.ApplyModifiedProperties())
  65. {
  66. SymbolText st = target as SymbolText;
  67. st.SetAllDirty();
  68. }
  69. }
  70. }
  71. }