GlyphRectPropertyDrawer.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEngine;
  2. using UnityEngine.TextCore;
  3. using UnityEditor;
  4. using System.Collections;
  5. namespace TMPro.EditorUtilities
  6. {
  7. [CustomPropertyDrawer(typeof(GlyphRect))]
  8. public class GlyphRectPropertyDrawer : PropertyDrawer
  9. {
  10. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  11. {
  12. //EditorGUI.BeginProperty(position, label, property);
  13. SerializedProperty prop_X = property.FindPropertyRelative("m_X");
  14. SerializedProperty prop_Y = property.FindPropertyRelative("m_Y");
  15. SerializedProperty prop_Width = property.FindPropertyRelative("m_Width");
  16. SerializedProperty prop_Height = property.FindPropertyRelative("m_Height");
  17. // We get Rect since a valid position may not be provided by the caller.
  18. Rect rect = new Rect(position.x, position.y, position.width, 49);
  19. EditorGUI.LabelField(new Rect(rect.x, rect.y - 2.5f, rect.width, 18), new GUIContent("Glyph Rect"));
  20. EditorGUIUtility.labelWidth = 50f;
  21. EditorGUIUtility.fieldWidth = 20f;
  22. //GUI.enabled = false;
  23. float width = (rect.width - 75f) / 4;
  24. EditorGUI.PropertyField(new Rect(rect.x + width * 0, rect.y + 20, width - 5f, 18), prop_X, new GUIContent("X:"));
  25. EditorGUI.PropertyField(new Rect(rect.x + width * 1, rect.y + 20, width - 5f, 18), prop_Y, new GUIContent("Y:"));
  26. EditorGUI.PropertyField(new Rect(rect.x + width * 2, rect.y + 20, width - 5f, 18), prop_Width, new GUIContent("W:"));
  27. EditorGUI.PropertyField(new Rect(rect.x + width * 3, rect.y + 20, width - 5f, 18), prop_Height, new GUIContent("H:"));
  28. //EditorGUI.EndProperty();
  29. }
  30. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  31. {
  32. return 45f;
  33. }
  34. }
  35. }