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

TMP_EditorPanelUI.cs 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. DrawMargins();
  28. DrawGeometrySorting();
  29. DrawIsTextObjectScaleStatic();
  30. DrawRichText();
  31. DrawRaycastTarget();
  32. DrawMaskable();
  33. DrawParsing();
  34. DrawEmojiFallbackSupport();
  35. DrawSpriteAsset();
  36. DrawStyleSheet();
  37. DrawFontFeatures();
  38. DrawPadding();
  39. }
  40. }
  41. protected void DrawRaycastTarget()
  42. {
  43. EditorGUI.BeginChangeCheck();
  44. EditorGUILayout.PropertyField(m_RaycastTargetProp, k_RaycastTargetLabel);
  45. if (EditorGUI.EndChangeCheck())
  46. {
  47. // Change needs to propagate to the child sub objects.
  48. Graphic[] graphicComponents = m_TextComponent.GetComponentsInChildren<Graphic>();
  49. for (int i = 1; i < graphicComponents.Length; i++)
  50. graphicComponents[i].raycastTarget = m_RaycastTargetProp.boolValue;
  51. m_HavePropertiesChanged = true;
  52. }
  53. }
  54. protected void DrawMaskable()
  55. {
  56. if (m_MaskableProp == null)
  57. return;
  58. EditorGUI.BeginChangeCheck();
  59. EditorGUILayout.PropertyField(m_MaskableProp, k_MaskableLabel);
  60. if (EditorGUI.EndChangeCheck())
  61. {
  62. m_TextComponent.maskable = m_MaskableProp.boolValue;
  63. // Change needs to propagate to the child sub objects.
  64. MaskableGraphic[] maskableGraphics = m_TextComponent.GetComponentsInChildren<MaskableGraphic>();
  65. for (int i = 1; i < maskableGraphics.Length; i++)
  66. maskableGraphics[i].maskable = m_MaskableProp.boolValue;
  67. m_HavePropertiesChanged = true;
  68. }
  69. }
  70. // Method to handle multi object selection
  71. protected override bool IsMixSelectionTypes()
  72. {
  73. GameObject[] objects = Selection.gameObjects;
  74. if (objects.Length > 1)
  75. {
  76. for (int i = 0; i < objects.Length; i++)
  77. {
  78. if (objects[i].GetComponent<TextMeshProUGUI>() == null)
  79. return true;
  80. }
  81. }
  82. return false;
  83. }
  84. protected override void OnUndoRedo()
  85. {
  86. int undoEventId = Undo.GetCurrentGroup();
  87. int lastUndoEventId = s_EventId;
  88. if (undoEventId != lastUndoEventId)
  89. {
  90. for (int i = 0; i < targets.Length; i++)
  91. {
  92. //Debug.Log("Undo & Redo Performed detected in Editor Panel. Event ID:" + Undo.GetCurrentGroup());
  93. TMPro_EventManager.ON_TEXTMESHPRO_UGUI_PROPERTY_CHANGED(true, targets[i] as TextMeshProUGUI);
  94. s_EventId = undoEventId;
  95. }
  96. }
  97. }
  98. }
  99. }