TMP_SubMeshUI_Editor.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. namespace TMPro.EditorUtilities
  5. {
  6. [CustomEditor(typeof(TMP_SubMeshUI)), CanEditMultipleObjects]
  7. public class TMP_SubMeshUI_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_SubMeshUI m_SubMeshComponent;
  20. //private CanvasRenderer m_canvasRenderer;
  21. private Editor m_materialEditor;
  22. private Material m_targetMaterial;
  23. public void OnEnable()
  24. {
  25. fontAsset_prop = serializedObject.FindProperty("m_fontAsset");
  26. spriteAsset_prop = serializedObject.FindProperty("m_spriteAsset");
  27. //m_SubMeshComponent = target as TMP_SubMeshUI;
  28. //m_rectTransform = m_SubMeshComponent.rectTransform;
  29. //m_canvasRenderer = m_SubMeshComponent.canvasRenderer;
  30. // Create new Material Editor if one does not exists
  31. /*
  32. if (m_canvasRenderer != null && m_canvasRenderer.GetMaterial() != null)
  33. {
  34. m_materialEditor = Editor.CreateEditor(m_canvasRenderer.GetMaterial());
  35. m_targetMaterial = m_canvasRenderer.GetMaterial();
  36. }
  37. */
  38. }
  39. public void OnDisable()
  40. {
  41. // Destroy material editor if one exists
  42. /*
  43. if (m_materialEditor != null)
  44. {
  45. //Debug.Log("Destroying Inline Material Editor.");
  46. DestroyImmediate(m_materialEditor);
  47. }
  48. */
  49. }
  50. public override void OnInspectorGUI()
  51. {
  52. GUI.enabled = false;
  53. EditorGUILayout.PropertyField(fontAsset_prop);
  54. EditorGUILayout.PropertyField(spriteAsset_prop);
  55. GUI.enabled = true;
  56. EditorGUILayout.Space();
  57. // If a Custom Material Editor exists, we use it.
  58. /*
  59. if (m_canvasRenderer != null && m_canvasRenderer.GetMaterial() != null)
  60. {
  61. Material mat = m_canvasRenderer.GetMaterial();
  62. //Debug.Log(mat + " " + m_targetMaterial);
  63. if (mat != m_targetMaterial)
  64. {
  65. // Destroy previous Material Instance
  66. //Debug.Log("New Material has been assigned.");
  67. m_targetMaterial = mat;
  68. DestroyImmediate(m_materialEditor);
  69. }
  70. if (m_materialEditor == null)
  71. {
  72. m_materialEditor = Editor.CreateEditor(mat);
  73. }
  74. m_materialEditor.DrawHeader();
  75. m_materialEditor.OnInspectorGUI();
  76. }
  77. */
  78. }
  79. }
  80. }