Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

GlyphMetricsPropertyDrawer.cs 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using UnityEngine;
  2. using UnityEngine.TextCore;
  3. using UnityEditor;
  4. using System.Collections;
  5. namespace TMPro.EditorUtilities
  6. {
  7. [CustomPropertyDrawer(typeof(GlyphMetrics))]
  8. internal class GlyphMetricsPropertyDrawer : PropertyDrawer
  9. {
  10. private static readonly GUIContent k_GlyphMetricLabel = new GUIContent("Glyph Metrics", "The layout metrics of the glyph.");
  11. private static readonly GUIContent k_WidthPropertyLabel = new GUIContent("W:", "The width of the glyph.");
  12. private static readonly GUIContent k_HeightPropertyLabel = new GUIContent("H:", "The height of the glyph.");
  13. private static readonly GUIContent k_BearingXPropertyLabel = new GUIContent("BX:", "The horizontal bearing X of the glyph.");
  14. private static readonly GUIContent k_BearingYPropertyLabel = new GUIContent("BY:", "The horizontal bearing Y of the glyph.");
  15. private static readonly GUIContent k_HorizontalAdvancePropertyLabel = new GUIContent("AD:", "The horizontal advance of the glyph.");
  16. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  17. {
  18. SerializedProperty prop_Width = property.FindPropertyRelative("m_Width");
  19. SerializedProperty prop_Height = property.FindPropertyRelative("m_Height");
  20. SerializedProperty prop_HoriBearingX = property.FindPropertyRelative("m_HorizontalBearingX");
  21. SerializedProperty prop_HoriBearingY = property.FindPropertyRelative("m_HorizontalBearingY");
  22. SerializedProperty prop_HoriAdvance = property.FindPropertyRelative("m_HorizontalAdvance");
  23. // We get Rect since a valid position may not be provided by the caller.
  24. Rect rect = new Rect(position.x, position.y, position.width, 49);
  25. EditorGUI.LabelField(new Rect(rect.x, rect.y - 2.5f, rect.width, 18), k_GlyphMetricLabel);
  26. EditorGUIUtility.labelWidth = 20f;
  27. EditorGUIUtility.fieldWidth = 15f;
  28. //GUI.enabled = false;
  29. float width = (rect.width - 75f) / 2;
  30. EditorGUI.PropertyField(new Rect(rect.x + width * 0, rect.y + 20, width - 5f, 18), prop_Width, k_WidthPropertyLabel);
  31. EditorGUI.PropertyField(new Rect(rect.x + width * 1, rect.y + 20, width - 5f, 18), prop_Height, k_HeightPropertyLabel);
  32. //GUI.enabled = true;
  33. width = (rect.width - 75f) / 3;
  34. EditorGUI.BeginChangeCheck();
  35. EditorGUI.PropertyField(new Rect(rect.x + width * 0, rect.y + 40, width - 5f, 18), prop_HoriBearingX, k_BearingXPropertyLabel);
  36. EditorGUI.PropertyField(new Rect(rect.x + width * 1, rect.y + 40, width - 5f, 18), prop_HoriBearingY, k_BearingYPropertyLabel);
  37. EditorGUI.PropertyField(new Rect(rect.x + width * 2, rect.y + 40, width - 5f, 18), prop_HoriAdvance, k_HorizontalAdvancePropertyLabel);
  38. if (EditorGUI.EndChangeCheck())
  39. {
  40. }
  41. }
  42. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  43. {
  44. return 65f;
  45. }
  46. }
  47. }