TMP_EditorPanel.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace TMPro.EditorUtilities
  4. {
  5. [CustomEditor(typeof(TextMeshPro), true), CanEditMultipleObjects]
  6. public class TMP_EditorPanel : TMP_BaseEditorPanel
  7. {
  8. static readonly GUIContent k_SortingLayerLabel = new GUIContent("Sorting Layer", "Name of the Renderer's sorting layer.");
  9. static readonly GUIContent k_OrderInLayerLabel = new GUIContent("Order in Layer", "Renderer's order within a sorting layer.");
  10. static readonly GUIContent k_OrthographicLabel = new GUIContent("Orthographic Mode", "Should be enabled when using an orthographic camera. Instructs the shader to not perform any perspective correction.");
  11. static readonly GUIContent k_VolumetricLabel = new GUIContent("Volumetric Setup", "Use cubes rather than quads to render the text. Allows for volumetric rendering when combined with a compatible shader.");
  12. SerializedProperty m_IsVolumetricTextProp;
  13. SerializedProperty m_IsOrthographicProp;
  14. Renderer m_Renderer;
  15. protected override void OnEnable()
  16. {
  17. base.OnEnable();
  18. m_IsOrthographicProp = serializedObject.FindProperty("m_isOrthographic");
  19. m_IsVolumetricTextProp = serializedObject.FindProperty("m_isVolumetricText");
  20. m_Renderer = m_TextComponent.GetComponent<Renderer>();
  21. }
  22. protected override void DrawExtraSettings()
  23. {
  24. Foldout.extraSettings = EditorGUILayout.Foldout(Foldout.extraSettings, k_ExtraSettingsLabel, true, TMP_UIStyleManager.boldFoldout);
  25. if (Foldout.extraSettings)
  26. {
  27. EditorGUI.indentLevel += 1;
  28. DrawMargins();
  29. DrawSortingLayer();
  30. DrawGeometrySorting();
  31. DrawOrthographicMode();
  32. DrawRichText();
  33. DrawParsing();
  34. DrawVolumetricSetup();
  35. DrawKerning();
  36. DrawPadding();
  37. EditorGUI.indentLevel -= 1;
  38. }
  39. }
  40. protected void DrawSortingLayer()
  41. {
  42. Undo.RecordObject(m_Renderer, "Sorting Layer Change");
  43. EditorGUI.BeginChangeCheck();
  44. // SORTING LAYERS
  45. var sortingLayerNames = SortingLayerHelper.sortingLayerNames;
  46. var textComponent = (TextMeshPro)m_TextComponent;
  47. // Look up the layer name using the current layer ID
  48. string oldName = SortingLayerHelper.GetSortingLayerNameFromID(textComponent.sortingLayerID);
  49. // Use the name to look up our array index into the names list
  50. int oldLayerIndex = System.Array.IndexOf(sortingLayerNames, oldName);
  51. // Show the pop-up for the names
  52. EditorGUIUtility.fieldWidth = 0f;
  53. int newLayerIndex = EditorGUILayout.Popup(k_SortingLayerLabel, oldLayerIndex, sortingLayerNames);
  54. // If the index changes, look up the ID for the new index to store as the new ID
  55. if (newLayerIndex != oldLayerIndex)
  56. {
  57. textComponent.sortingLayerID = SortingLayerHelper.GetSortingLayerIDForIndex(newLayerIndex);
  58. }
  59. // Expose the manual sorting order
  60. int newSortingLayerOrder = EditorGUILayout.IntField(k_OrderInLayerLabel, textComponent.sortingOrder);
  61. if (newSortingLayerOrder != textComponent.sortingOrder)
  62. {
  63. textComponent.sortingOrder = newSortingLayerOrder;
  64. }
  65. if (EditorGUI.EndChangeCheck())
  66. m_HavePropertiesChanged = true;
  67. EditorGUILayout.Space();
  68. }
  69. protected void DrawOrthographicMode()
  70. {
  71. EditorGUI.BeginChangeCheck();
  72. EditorGUILayout.PropertyField(m_IsOrthographicProp, k_OrthographicLabel);
  73. if (EditorGUI.EndChangeCheck())
  74. m_HavePropertiesChanged = true;
  75. }
  76. protected void DrawVolumetricSetup()
  77. {
  78. EditorGUI.BeginChangeCheck();
  79. EditorGUILayout.PropertyField(m_IsVolumetricTextProp, k_VolumetricLabel);
  80. if (EditorGUI.EndChangeCheck())
  81. {
  82. m_HavePropertiesChanged = true;
  83. m_TextComponent.textInfo.ResetVertexLayout(m_IsVolumetricTextProp.boolValue);
  84. }
  85. EditorGUILayout.Space();
  86. }
  87. // Method to handle multi object selection
  88. protected override bool IsMixSelectionTypes()
  89. {
  90. GameObject[] objects = Selection.gameObjects;
  91. if (objects.Length > 1)
  92. {
  93. for (int i = 0; i < objects.Length; i++)
  94. {
  95. if (objects[i].GetComponent<TextMeshPro>() == null)
  96. return true;
  97. }
  98. }
  99. return false;
  100. }
  101. protected override void OnUndoRedo()
  102. {
  103. int undoEventId = Undo.GetCurrentGroup();
  104. int lastUndoEventId = s_EventId;
  105. if (undoEventId != lastUndoEventId)
  106. {
  107. for (int i = 0; i < targets.Length; i++)
  108. {
  109. //Debug.Log("Undo & Redo Performed detected in Editor Panel. Event ID:" + Undo.GetCurrentGroup());
  110. TMPro_EventManager.ON_TEXTMESHPRO_PROPERTY_CHANGED(true, targets[i] as TextMeshPro);
  111. s_EventId = undoEventId;
  112. }
  113. }
  114. }
  115. }
  116. }