GlyphMetricsPropertyDrawer.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using UnityEngine;
  2. using UnityEngine.TextCore;
  3. using UnityEditor;
  4. using System.Collections;
  5. namespace TMPro.EditorUtilities
  6. {
  7. [CustomPropertyDrawer(typeof(GlyphMetrics))]
  8. public class GlyphMetricsPropertyDrawer : PropertyDrawer
  9. {
  10. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  11. {
  12. SerializedProperty prop_Width = property.FindPropertyRelative("m_Width");
  13. SerializedProperty prop_Height = property.FindPropertyRelative("m_Height");
  14. SerializedProperty prop_HoriBearingX = property.FindPropertyRelative("m_HorizontalBearingX");
  15. SerializedProperty prop_HoriBearingY = property.FindPropertyRelative("m_HorizontalBearingY");
  16. SerializedProperty prop_HoriAdvance = property.FindPropertyRelative("m_HorizontalAdvance");
  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(rect, new GUIContent("Glyph Metrics"));
  20. EditorGUIUtility.labelWidth = 30f;
  21. EditorGUIUtility.fieldWidth = 10f;
  22. //GUI.enabled = false;
  23. float width = (rect.width - 75f) / 2;
  24. EditorGUI.PropertyField(new Rect(rect.x + width * 0, rect.y + 20, width - 5f, 18), prop_Width, new GUIContent("W:"));
  25. EditorGUI.PropertyField(new Rect(rect.x + width * 1, rect.y + 20, width - 5f, 18), prop_Height, new GUIContent("H:"));
  26. //GUI.enabled = true;
  27. width = (rect.width - 75f) / 3;
  28. EditorGUI.BeginChangeCheck();
  29. EditorGUI.PropertyField(new Rect(rect.x + width * 0, rect.y + 40, width - 5f, 18), prop_HoriBearingX, new GUIContent("BX:"));
  30. EditorGUI.PropertyField(new Rect(rect.x + width * 1, rect.y + 40, width - 5f, 18), prop_HoriBearingY, new GUIContent("BY:"));
  31. EditorGUI.PropertyField(new Rect(rect.x + width * 2, rect.y + 40, width - 5f, 18), prop_HoriAdvance, new GUIContent("AD:"));
  32. if (EditorGUI.EndChangeCheck())
  33. {
  34. }
  35. }
  36. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  37. {
  38. return 65f;
  39. }
  40. }
  41. }