TMP_EditorPanelUI.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEditor;
  4. namespace TMPro.EditorUtilities
  5. {
  6. [CustomEditor(typeof(TextMeshProUGUI), true), CanEditMultipleObjects]
  7. public class TMP_EditorPanelUI : TMP_BaseEditorPanel
  8. {
  9. static readonly GUIContent k_RaycastTargetLabel = new GUIContent("Raycast Target", "Whether the text blocks raycasts from the Graphic Raycaster.");
  10. static readonly GUIContent k_MaskableLabel = new GUIContent("Maskable", "Determines if the text object will be affected by UI Mask.");
  11. SerializedProperty m_RaycastTargetProp;
  12. private SerializedProperty m_MaskableProp;
  13. protected override void OnEnable()
  14. {
  15. base.OnEnable();
  16. m_RaycastTargetProp = serializedObject.FindProperty("m_RaycastTarget");
  17. m_MaskableProp = serializedObject.FindProperty("m_Maskable");
  18. }
  19. protected override void DrawExtraSettings()
  20. {
  21. Rect rect = EditorGUILayout.GetControlRect(false, 24);
  22. if (GUI.Button(rect, new GUIContent("<b>Extra Settings</b>"), TMP_UIStyleManager.sectionHeader))
  23. Foldout.extraSettings = !Foldout.extraSettings;
  24. GUI.Label(rect, (Foldout.extraSettings ? k_UiStateLabel[0] : k_UiStateLabel[1]), TMP_UIStyleManager.rightLabel);
  25. if (Foldout.extraSettings)
  26. {
  27. //EditorGUI.indentLevel += 1;
  28. DrawMargins();
  29. DrawGeometrySorting();
  30. DrawIsTextObjectScaleStatic();
  31. DrawRichText();
  32. DrawRaycastTarget();
  33. DrawMaskable();
  34. DrawParsing();
  35. DrawSpriteAsset();
  36. DrawStyleSheet();
  37. DrawKerning();
  38. DrawPadding();
  39. //EditorGUI.indentLevel -= 1;
  40. }
  41. }
  42. protected void DrawRaycastTarget()
  43. {
  44. EditorGUI.BeginChangeCheck();
  45. EditorGUILayout.PropertyField(m_RaycastTargetProp, k_RaycastTargetLabel);
  46. if (EditorGUI.EndChangeCheck())
  47. {
  48. // Change needs to propagate to the child sub objects.
  49. Graphic[] graphicComponents = m_TextComponent.GetComponentsInChildren<Graphic>();
  50. for (int i = 1; i < graphicComponents.Length; i++)
  51. graphicComponents[i].raycastTarget = m_RaycastTargetProp.boolValue;
  52. m_HavePropertiesChanged = true;
  53. }
  54. }
  55. protected void DrawMaskable()
  56. {
  57. EditorGUI.BeginChangeCheck();
  58. EditorGUILayout.PropertyField(m_MaskableProp, k_MaskableLabel);
  59. if (EditorGUI.EndChangeCheck())
  60. {
  61. m_TextComponent.maskable = m_MaskableProp.boolValue;
  62. // Change needs to propagate to the child sub objects.
  63. MaskableGraphic[] maskableGraphics = m_TextComponent.GetComponentsInChildren<MaskableGraphic>();
  64. for (int i = 1; i < maskableGraphics.Length; i++)
  65. maskableGraphics[i].maskable = m_MaskableProp.boolValue;
  66. m_HavePropertiesChanged = true;
  67. }
  68. }
  69. // Method to handle multi object selection
  70. protected override bool IsMixSelectionTypes()
  71. {
  72. GameObject[] objects = Selection.gameObjects;
  73. if (objects.Length > 1)
  74. {
  75. for (int i = 0; i < objects.Length; i++)
  76. {
  77. if (objects[i].GetComponent<TextMeshProUGUI>() == null)
  78. return true;
  79. }
  80. }
  81. return false;
  82. }
  83. protected override void OnUndoRedo()
  84. {
  85. int undoEventId = Undo.GetCurrentGroup();
  86. int lastUndoEventId = s_EventId;
  87. if (undoEventId != lastUndoEventId)
  88. {
  89. for (int i = 0; i < targets.Length; i++)
  90. {
  91. //Debug.Log("Undo & Redo Performed detected in Editor Panel. Event ID:" + Undo.GetCurrentGroup());
  92. TMPro_EventManager.ON_TEXTMESHPRO_UGUI_PROPERTY_CHANGED(true, targets[i] as TextMeshProUGUI);
  93. s_EventId = undoEventId;
  94. }
  95. }
  96. }
  97. }
  98. }