TMP_SubMesh_Editor.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. private string[] m_SortingLayerNames;
  22. public void OnEnable()
  23. {
  24. fontAsset_prop = serializedObject.FindProperty("m_fontAsset");
  25. spriteAsset_prop = serializedObject.FindProperty("m_spriteAsset");
  26. m_SubMeshComponent = target as TMP_SubMesh;
  27. m_Renderer = m_SubMeshComponent.renderer;
  28. m_SortingLayerNames = SortingLayerHelper.sortingLayerNames;
  29. }
  30. public override void OnInspectorGUI()
  31. {
  32. EditorGUI.indentLevel = 0;
  33. GUI.enabled = false;
  34. EditorGUILayout.PropertyField(fontAsset_prop);
  35. EditorGUILayout.PropertyField(spriteAsset_prop);
  36. GUI.enabled = true;
  37. EditorGUI.BeginChangeCheck();
  38. // Look up the layer name using the current layer ID
  39. string oldName = SortingLayer.IDToName(m_Renderer.sortingLayerID);
  40. // Use the name to look up our array index into the names list
  41. int oldLayerIndex = System.Array.IndexOf(m_SortingLayerNames, oldName);
  42. // Show the pop-up for the names
  43. int newLayerIndex = EditorGUILayout.Popup("Sorting Layer", oldLayerIndex, m_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. m_Renderer.sortingLayerID = SortingLayer.NameToID(m_SortingLayerNames[newLayerIndex]);
  47. // Expose the manual sorting order
  48. int newSortingLayerOrder = EditorGUILayout.IntField("Order in Layer", m_Renderer.sortingOrder);
  49. if (newSortingLayerOrder != m_Renderer.sortingOrder)
  50. m_Renderer.sortingOrder = newSortingLayerOrder;
  51. }
  52. }
  53. }