Açıklama Yok
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.7KB

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