TMP_UiEditorPanel.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_UiEditorPanel : TMP_BaseEditorPanel
  8. {
  9. static readonly GUIContent k_RaycastTargetLabel = new GUIContent("Raycast Target", "Whether the text blocks raycasts from the Graphic Raycaster.");
  10. SerializedProperty m_RaycastTargetProp;
  11. protected override void OnEnable()
  12. {
  13. base.OnEnable();
  14. m_RaycastTargetProp = serializedObject.FindProperty("m_RaycastTarget");
  15. }
  16. protected override void DrawExtraSettings()
  17. {
  18. Foldout.extraSettings = EditorGUILayout.Foldout(Foldout.extraSettings, k_ExtraSettingsLabel, true, TMP_UIStyleManager.boldFoldout);
  19. if (Foldout.extraSettings)
  20. {
  21. EditorGUI.indentLevel += 1;
  22. DrawMargins();
  23. DrawGeometrySorting();
  24. DrawRichText();
  25. DrawRaycastTarget();
  26. DrawParsing();
  27. DrawKerning();
  28. DrawPadding();
  29. EditorGUI.indentLevel -= 1;
  30. }
  31. }
  32. protected void DrawRaycastTarget()
  33. {
  34. EditorGUI.BeginChangeCheck();
  35. EditorGUILayout.PropertyField(m_RaycastTargetProp, k_RaycastTargetLabel);
  36. if (EditorGUI.EndChangeCheck())
  37. {
  38. // Change needs to propagate to the child sub objects.
  39. Graphic[] graphicComponents = m_TextComponent.GetComponentsInChildren<Graphic>();
  40. for (int i = 1; i < graphicComponents.Length; i++)
  41. graphicComponents[i].raycastTarget = m_RaycastTargetProp.boolValue;
  42. m_HavePropertiesChanged = true;
  43. }
  44. }
  45. // Method to handle multi object selection
  46. protected override bool IsMixSelectionTypes()
  47. {
  48. GameObject[] objects = Selection.gameObjects;
  49. if (objects.Length > 1)
  50. {
  51. for (int i = 0; i < objects.Length; i++)
  52. {
  53. if (objects[i].GetComponent<TextMeshProUGUI>() == null)
  54. return true;
  55. }
  56. }
  57. return false;
  58. }
  59. protected override void OnUndoRedo()
  60. {
  61. int undoEventId = Undo.GetCurrentGroup();
  62. int lastUndoEventId = s_EventId;
  63. if (undoEventId != lastUndoEventId)
  64. {
  65. for (int i = 0; i < targets.Length; i++)
  66. {
  67. //Debug.Log("Undo & Redo Performed detected in Editor Panel. Event ID:" + Undo.GetCurrentGroup());
  68. TMPro_EventManager.ON_TEXTMESHPRO_UGUI_PROPERTY_CHANGED(true, targets[i] as TextMeshProUGUI);
  69. s_EventId = undoEventId;
  70. }
  71. }
  72. }
  73. }
  74. }