You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
5.2 KiB

  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace TMPro.EditorUtilities
  4. {
  5. [CustomEditor(typeof(TextMeshPro)), 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. protected override void OnEnable()
  15. {
  16. base.OnEnable();
  17. m_IsOrthographicProp = serializedObject.FindProperty("m_isOrthographic");
  18. m_IsVolumetricTextProp = serializedObject.FindProperty("m_isVolumetricText");
  19. }
  20. protected override void DrawExtraSettings()
  21. {
  22. Foldout.extraSettings = EditorGUILayout.Foldout(Foldout.extraSettings, k_ExtraSettingsLabel, true, TMP_UIStyleManager.boldFoldout);
  23. if (Foldout.extraSettings)
  24. {
  25. EditorGUI.indentLevel += 1;
  26. DrawMargins();
  27. DrawSortingLayer();
  28. DrawGeometrySorting();
  29. DrawOrthographicMode();
  30. DrawRichText();
  31. DrawParsing();
  32. DrawVolumetricSetup();
  33. DrawKerning();
  34. DrawPadding();
  35. EditorGUI.indentLevel -= 1;
  36. }
  37. }
  38. protected void DrawSortingLayer()
  39. {
  40. EditorGUI.BeginChangeCheck();
  41. // SORTING LAYERS
  42. var sortingLayerNames = SortingLayerHelper.sortingLayerNames;
  43. var textComponent = (TextMeshPro)m_TextComponent;
  44. // Look up the layer name using the current layer ID
  45. string oldName = SortingLayerHelper.GetSortingLayerNameFromID(textComponent.sortingLayerID);
  46. // Use the name to look up our array index into the names list
  47. int oldLayerIndex = System.Array.IndexOf(sortingLayerNames, oldName);
  48. // Show the pop-up for the names
  49. EditorGUIUtility.fieldWidth = 0f;
  50. int newLayerIndex = EditorGUILayout.Popup(k_SortingLayerLabel, oldLayerIndex, sortingLayerNames);
  51. // If the index changes, look up the ID for the new index to store as the new ID
  52. if (newLayerIndex != oldLayerIndex)
  53. {
  54. textComponent.sortingLayerID = SortingLayerHelper.GetSortingLayerIDForIndex(newLayerIndex);
  55. }
  56. // Expose the manual sorting order
  57. int newSortingLayerOrder = EditorGUILayout.IntField(k_OrderInLayerLabel, textComponent.sortingOrder);
  58. if (newSortingLayerOrder != textComponent.sortingOrder)
  59. {
  60. textComponent.sortingOrder = newSortingLayerOrder;
  61. }
  62. if (EditorGUI.EndChangeCheck())
  63. m_HavePropertiesChanged = true;
  64. EditorGUILayout.Space();
  65. }
  66. protected void DrawOrthographicMode()
  67. {
  68. EditorGUI.BeginChangeCheck();
  69. EditorGUILayout.PropertyField(m_IsOrthographicProp, k_OrthographicLabel);
  70. if (EditorGUI.EndChangeCheck())
  71. m_HavePropertiesChanged = true;
  72. }
  73. protected void DrawVolumetricSetup()
  74. {
  75. EditorGUI.BeginChangeCheck();
  76. EditorGUILayout.PropertyField(m_IsVolumetricTextProp, k_VolumetricLabel);
  77. if (EditorGUI.EndChangeCheck())
  78. {
  79. m_HavePropertiesChanged = true;
  80. m_TextComponent.textInfo.ResetVertexLayout(m_IsVolumetricTextProp.boolValue);
  81. }
  82. EditorGUILayout.Space();
  83. }
  84. // Method to handle multi object selection
  85. protected override bool IsMixSelectionTypes()
  86. {
  87. GameObject[] objects = Selection.gameObjects;
  88. if (objects.Length > 1)
  89. {
  90. for (int i = 0; i < objects.Length; i++)
  91. {
  92. if (objects[i].GetComponent<TextMeshPro>() == null)
  93. return true;
  94. }
  95. }
  96. return false;
  97. }
  98. protected override void OnUndoRedo()
  99. {
  100. int undoEventId = Undo.GetCurrentGroup();
  101. int lastUndoEventId = s_EventId;
  102. if (undoEventId != lastUndoEventId)
  103. {
  104. for (int i = 0; i < targets.Length; i++)
  105. {
  106. //Debug.Log("Undo & Redo Performed detected in Editor Panel. Event ID:" + Undo.GetCurrentGroup());
  107. TMPro_EventManager.ON_TEXTMESHPRO_PROPERTY_CHANGED(true, targets[i] as TextMeshPro);
  108. s_EventId = undoEventId;
  109. }
  110. }
  111. }
  112. }
  113. }