You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
3.3 KiB

  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. namespace TMPro.EditorUtilities
  5. {
  6. [CustomPropertyDrawer(typeof(TMP_Glyph))]
  7. public class GlyphInfoDrawer : PropertyDrawer
  8. {
  9. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  10. {
  11. SerializedProperty prop_id = property.FindPropertyRelative("id");
  12. SerializedProperty prop_x = property.FindPropertyRelative("x");
  13. SerializedProperty prop_y = property.FindPropertyRelative("y");
  14. SerializedProperty prop_width = property.FindPropertyRelative("width");
  15. SerializedProperty prop_height = property.FindPropertyRelative("height");
  16. SerializedProperty prop_xOffset = property.FindPropertyRelative("xOffset");
  17. SerializedProperty prop_yOffset = property.FindPropertyRelative("yOffset");
  18. SerializedProperty prop_xAdvance = property.FindPropertyRelative("xAdvance");
  19. SerializedProperty prop_scale = property.FindPropertyRelative("scale");
  20. // We get Rect since a valid position may not be provided by the caller.
  21. Rect rect = GUILayoutUtility.GetRect(position.width, 48);
  22. rect.y -= 15;
  23. //GUI.enabled = false;
  24. EditorGUIUtility.labelWidth = 40f;
  25. EditorGUIUtility.fieldWidth = 45f;
  26. bool prevGuiState = GUI.enabled;
  27. GUI.enabled = true;
  28. EditorGUI.LabelField(new Rect(rect.x + 5f, rect.y, 80f, 18), new GUIContent("Ascii: <color=#FFFF80>" + prop_id.intValue + "</color>"), TMP_UIStyleManager.label);
  29. EditorGUI.LabelField(new Rect(rect.x + 90f, rect.y, 80f, 18), new GUIContent("Hex: <color=#FFFF80>" + prop_id.intValue.ToString("X") + "</color>"), TMP_UIStyleManager.label);
  30. EditorGUI.LabelField(new Rect(rect.x + 170f, rect.y, 80, 18), "Char: [ <color=#FFFF80>" + (char)prop_id.intValue + "</color> ]", TMP_UIStyleManager.label);
  31. GUI.enabled = prevGuiState;
  32. EditorGUIUtility.labelWidth = 35f;
  33. EditorGUIUtility.fieldWidth = 10f;
  34. float width = (rect.width - 5f) / 4;
  35. EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 0, rect.y + 22, width - 5f, 18), prop_x, new GUIContent("X:"));
  36. EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 1, rect.y + 22, width - 5f, 18), prop_y, new GUIContent("Y:"));
  37. EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 2, rect.y + 22, width - 5f, 18), prop_width, new GUIContent("W:"));
  38. EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 3, rect.y + 22, width - 5f, 18), prop_height, new GUIContent("H:"));
  39. //GUI.enabled = true;
  40. EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 0, rect.y + 44, width - 5f, 18), prop_xOffset, new GUIContent("OX:"));
  41. EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 1, rect.y + 44, width - 5f, 18), prop_yOffset, new GUIContent("OY:"));
  42. //GUI.enabled = true;
  43. EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 2, rect.y + 44, width - 5f, 18), prop_xAdvance, new GUIContent("ADV:"));
  44. EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 3, rect.y + 44, width - 5f, 18), prop_scale, new GUIContent("SF:"));
  45. }
  46. }
  47. }