설명 없음
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.

TMP_EditorPanel.cs 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEditor.Presets;
  4. namespace TMPro.EditorUtilities
  5. {
  6. [CustomEditor(typeof(TextMeshPro), true), CanEditMultipleObjects]
  7. public class TMP_EditorPanel : TMP_BaseEditorPanel
  8. {
  9. static readonly GUIContent k_SortingLayerLabel = new GUIContent("Sorting Layer", "Name of the Renderer's sorting layer.");
  10. static readonly GUIContent k_OrderInLayerLabel = new GUIContent("Order in Layer", "Renderer's order within a sorting layer.");
  11. 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.");
  12. 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.");
  13. private static string[] k_SortingLayerNames;
  14. bool IsPreset;
  15. SerializedProperty m_IsVolumetricTextProp;
  16. SerializedProperty m_IsOrthographicProp;
  17. Object[] m_Renderers;
  18. SerializedObject m_RendererSerializedObject;
  19. SerializedProperty m_RendererSortingLayerProp;
  20. SerializedProperty m_RendererSortingLayerIDProp;
  21. SerializedProperty m_RendererSortingOrderProp;
  22. SerializedProperty m_TextSortingLayerProp;
  23. SerializedProperty m_TextSortingLayerIDProp;
  24. SerializedProperty m_TextSortingOrderProp;
  25. protected override void OnEnable()
  26. {
  27. base.OnEnable();
  28. // Determine if the inspected object is a Preset
  29. IsPreset = (int)(target as Component).gameObject.hideFlags == 93;
  30. m_IsOrthographicProp = serializedObject.FindProperty("m_isOrthographic");
  31. m_IsVolumetricTextProp = serializedObject.FindProperty("m_isVolumetricText");
  32. m_Renderers = new Object[targets.Length];
  33. for (int i = 0; i < m_Renderers.Length; i++)
  34. m_Renderers[i] = (targets[i] as TextMeshPro)?.GetComponent<Renderer>();
  35. m_RendererSerializedObject = new SerializedObject(m_Renderers);
  36. m_RendererSortingLayerProp = m_RendererSerializedObject.FindProperty("m_SortingLayer");
  37. m_RendererSortingLayerIDProp = m_RendererSerializedObject.FindProperty("m_SortingLayerID");
  38. m_RendererSortingOrderProp = m_RendererSerializedObject.FindProperty("m_SortingOrder");
  39. m_TextSortingLayerProp = serializedObject.FindProperty("_SortingLayer");
  40. m_TextSortingLayerIDProp = serializedObject.FindProperty("_SortingLayerID");
  41. m_TextSortingOrderProp = serializedObject.FindProperty("_SortingOrder");
  42. // Populate Sorting Layer Names
  43. k_SortingLayerNames = SortingLayerHelper.sortingLayerNames;
  44. }
  45. protected override void DrawExtraSettings()
  46. {
  47. Rect rect = EditorGUILayout.GetControlRect(false, 24);
  48. if (GUI.Button(rect, new GUIContent("<b>Extra Settings</b>"), TMP_UIStyleManager.sectionHeader))
  49. Foldout.extraSettings = !Foldout.extraSettings;
  50. GUI.Label(rect, (Foldout.extraSettings ? "" : k_UiStateLabel[1]), TMP_UIStyleManager.rightLabel);
  51. if (Foldout.extraSettings)
  52. {
  53. //EditorGUI.indentLevel += 1;
  54. DrawMargins();
  55. DrawSortingLayer();
  56. DrawGeometrySorting();
  57. DrawIsTextObjectScaleStatic();
  58. DrawOrthographicMode();
  59. DrawRichText();
  60. DrawParsing();
  61. DrawSpriteAsset();
  62. DrawStyleSheet();
  63. //DrawVolumetricSetup();
  64. DrawKerning();
  65. DrawPadding();
  66. //EditorGUI.indentLevel -= 1;
  67. }
  68. }
  69. private void DrawSortingLayer()
  70. {
  71. m_RendererSerializedObject.Update();
  72. Rect rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight);
  73. // Special handling for Presets where the sorting layer, id and order is serialized with the text object instead of on the MeshRenderer.
  74. SerializedProperty sortingLayerProp = IsPreset ? m_TextSortingLayerProp : m_RendererSortingLayerProp;
  75. SerializedProperty sortingLayerIDProp = IsPreset ? m_TextSortingLayerIDProp : m_RendererSortingLayerIDProp;
  76. EditorGUI.BeginProperty(rect, k_SortingLayerLabel, sortingLayerIDProp);
  77. EditorGUI.BeginChangeCheck();
  78. int currentLayerIndex = SortingLayerHelper.GetSortingLayerIndexFromSortingLayerID(sortingLayerIDProp.intValue);
  79. int newLayerIndex = EditorGUI.Popup(rect, k_SortingLayerLabel, currentLayerIndex, k_SortingLayerNames);
  80. if (EditorGUI.EndChangeCheck())
  81. {
  82. sortingLayerIDProp.intValue = SortingLayer.NameToID(k_SortingLayerNames[newLayerIndex]);
  83. sortingLayerProp.intValue = SortingLayer.GetLayerValueFromName(k_SortingLayerNames[newLayerIndex]);
  84. m_HavePropertiesChanged = true;
  85. // Sync Sorting Layer ID change on potential sub text object.
  86. TextMeshPro textComponent = m_TextComponent as TextMeshPro;
  87. textComponent.UpdateSubMeshSortingLayerID(sortingLayerIDProp.intValue);
  88. }
  89. EditorGUI.EndProperty();
  90. // Sorting Order
  91. SerializedProperty sortingOrderLayerProp = IsPreset ? m_TextSortingOrderProp : m_RendererSortingOrderProp;
  92. EditorGUI.BeginChangeCheck();
  93. EditorGUILayout.PropertyField(sortingOrderLayerProp, k_OrderInLayerLabel);
  94. if (EditorGUI.EndChangeCheck())
  95. {
  96. m_HavePropertiesChanged = true;
  97. TextMeshPro textComponent = m_TextComponent as TextMeshPro;
  98. textComponent.UpdateSubMeshSortingOrder(sortingOrderLayerProp.intValue);
  99. }
  100. m_RendererSerializedObject.ApplyModifiedProperties();
  101. EditorGUILayout.Space();
  102. }
  103. private void DrawOrthographicMode()
  104. {
  105. EditorGUI.BeginChangeCheck();
  106. EditorGUILayout.PropertyField(m_IsOrthographicProp, k_OrthographicLabel);
  107. if (EditorGUI.EndChangeCheck())
  108. m_HavePropertiesChanged = true;
  109. }
  110. protected void DrawVolumetricSetup()
  111. {
  112. EditorGUI.BeginChangeCheck();
  113. EditorGUILayout.PropertyField(m_IsVolumetricTextProp, k_VolumetricLabel);
  114. if (EditorGUI.EndChangeCheck())
  115. {
  116. m_HavePropertiesChanged = true;
  117. m_TextComponent.textInfo.ResetVertexLayout(m_IsVolumetricTextProp.boolValue);
  118. }
  119. EditorGUILayout.Space();
  120. }
  121. // Method to handle multi object selection
  122. protected override bool IsMixSelectionTypes()
  123. {
  124. GameObject[] objects = Selection.gameObjects;
  125. if (objects.Length > 1)
  126. {
  127. for (int i = 0; i < objects.Length; i++)
  128. {
  129. if (objects[i].GetComponent<TextMeshPro>() == null)
  130. return true;
  131. }
  132. }
  133. return false;
  134. }
  135. protected override void OnUndoRedo()
  136. {
  137. int undoEventId = Undo.GetCurrentGroup();
  138. int lastUndoEventId = s_EventId;
  139. if (undoEventId != lastUndoEventId)
  140. {
  141. for (int i = 0; i < targets.Length; i++)
  142. {
  143. //Debug.Log("Undo & Redo Performed detected in Editor Panel. Event ID:" + Undo.GetCurrentGroup());
  144. TMPro_EventManager.ON_TEXTMESHPRO_PROPERTY_CHANGED(true, targets[i] as TextMeshPro);
  145. s_EventId = undoEventId;
  146. }
  147. }
  148. }
  149. }
  150. }