暫無描述
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.

GlyphRectPropertyDrawer.cs 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. private static readonly GUIContent k_GlyphRectLabel = new GUIContent("Glyph Rect", "A rectangle (rect) that represents the position of the glyph in the atlas texture.");
  11. private static readonly GUIContent k_XPropertyLabel = new GUIContent("X:", "The X coordinate of the glyph in the atlas texture.");
  12. private static readonly GUIContent k_YPropertyLabel = new GUIContent("Y:", "The Y coordinate of the glyph in the atlas texture.");
  13. private static readonly GUIContent k_WidthPropertyLabel = new GUIContent("W:", "The width of the glyph in the atlas texture.");
  14. private static readonly GUIContent k_HeightPropertyLabel = new GUIContent("H:", "The height of the glyph in the atlas texture.");
  15. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  16. {
  17. //EditorGUI.BeginProperty(position, label, property);
  18. SerializedProperty prop_X = property.FindPropertyRelative("m_X");
  19. SerializedProperty prop_Y = property.FindPropertyRelative("m_Y");
  20. SerializedProperty prop_Width = property.FindPropertyRelative("m_Width");
  21. SerializedProperty prop_Height = property.FindPropertyRelative("m_Height");
  22. // We get Rect since a valid position may not be provided by the caller.
  23. Rect rect = new Rect(position.x, position.y, position.width, 49);
  24. EditorGUI.LabelField(new Rect(rect.x, rect.y - 2.5f, rect.width, 18), k_GlyphRectLabel);
  25. EditorGUIUtility.labelWidth = 20f;
  26. EditorGUIUtility.fieldWidth = 20f;
  27. //GUI.enabled = false;
  28. float width = (rect.width - 75f) / 4;
  29. EditorGUI.PropertyField(new Rect(rect.x + width * 0, rect.y + 20, width - 5f, 18), prop_X, k_XPropertyLabel);
  30. EditorGUI.PropertyField(new Rect(rect.x + width * 1, rect.y + 20, width - 5f, 18), prop_Y, k_YPropertyLabel);
  31. EditorGUI.PropertyField(new Rect(rect.x + width * 2, rect.y + 20, width - 5f, 18), prop_Width, k_WidthPropertyLabel);
  32. EditorGUI.PropertyField(new Rect(rect.x + width * 3, rect.y + 20, width - 5f, 18), prop_Height, k_HeightPropertyLabel);
  33. //EditorGUI.EndProperty();
  34. }
  35. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  36. {
  37. return 45f;
  38. }
  39. }
  40. }