TMP_SubMesh_Editor.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. namespace TMPro.EditorUtilities
  5. {
  6. [CustomEditor(typeof(TMP_SubMesh)), CanEditMultipleObjects]
  7. public class TMP_SubMesh_Editor : Editor
  8. {
  9. private struct m_foldout
  10. { // Track Inspector foldout panel states, globally.
  11. //public static bool textInput = true;
  12. public static bool fontSettings = true;
  13. //public static bool extraSettings = false;
  14. //public static bool shadowSetting = false;
  15. //public static bool materialEditor = true;
  16. }
  17. private SerializedProperty fontAsset_prop;
  18. private SerializedProperty spriteAsset_prop;
  19. private TMP_SubMesh m_SubMeshComponent;
  20. private Renderer m_Renderer;
  21. public void OnEnable()
  22. {
  23. fontAsset_prop = serializedObject.FindProperty("m_fontAsset");
  24. spriteAsset_prop = serializedObject.FindProperty("m_spriteAsset");
  25. m_SubMeshComponent = target as TMP_SubMesh;
  26. m_Renderer = m_SubMeshComponent.renderer;
  27. }
  28. public override void OnInspectorGUI()
  29. {
  30. EditorGUI.indentLevel = 0;
  31. GUI.enabled = false;
  32. EditorGUILayout.PropertyField(fontAsset_prop);
  33. EditorGUILayout.PropertyField(spriteAsset_prop);
  34. GUI.enabled = true;
  35. EditorGUI.BeginChangeCheck();
  36. // SORTING LAYERS
  37. var sortingLayerNames = SortingLayerHelper.sortingLayerNames;
  38. // Look up the layer name using the current layer ID
  39. string oldName = SortingLayerHelper.GetSortingLayerNameFromID(m_Renderer.sortingLayerID);
  40. // Use the name to look up our array index into the names list
  41. int oldLayerIndex = System.Array.IndexOf(sortingLayerNames, oldName);
  42. // Show the pop-up for the names
  43. int newLayerIndex = EditorGUILayout.Popup("Sorting Layer", oldLayerIndex, sortingLayerNames);
  44. // If the index changes, look up the ID for the new index to store as the new ID
  45. if (newLayerIndex != oldLayerIndex)
  46. {
  47. //Undo.RecordObject(renderer, "Edit Sorting Layer");
  48. m_Renderer.sortingLayerID = SortingLayerHelper.GetSortingLayerIDForIndex(newLayerIndex);
  49. //EditorUtility.SetDirty(renderer);
  50. }
  51. // Expose the manual sorting order
  52. int newSortingLayerOrder = EditorGUILayout.IntField("Order in Layer", m_Renderer.sortingOrder);
  53. if (newSortingLayerOrder != m_Renderer.sortingOrder)
  54. {
  55. //Undo.RecordObject(renderer, "Edit Sorting Order");
  56. m_Renderer.sortingOrder = newSortingLayerOrder;
  57. }
  58. }
  59. }
  60. }