GlyphInfoDrawer.cs 3.3 KB

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