TextSwitcherDrawer.cs 1.1 KB

123456789101112131415161718192021222324252627282930
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEngine.Playables;
  4. using UnityEngine.UI;
  5. [CustomPropertyDrawer(typeof(TextSwitcherBehaviour))]
  6. public class TextSwitcherDrawer : PropertyDrawer
  7. {
  8. public override float GetPropertyHeight (SerializedProperty property, GUIContent label)
  9. {
  10. int fieldCount = 3;
  11. return fieldCount * EditorGUIUtility.singleLineHeight;
  12. }
  13. public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
  14. {
  15. SerializedProperty colorProp = property.FindPropertyRelative("color");
  16. SerializedProperty fontSizeProp = property.FindPropertyRelative("fontSize");
  17. SerializedProperty textProp = property.FindPropertyRelative("text");
  18. Rect singleFieldRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
  19. EditorGUI.PropertyField(singleFieldRect, colorProp);
  20. singleFieldRect.y += EditorGUIUtility.singleLineHeight;
  21. EditorGUI.PropertyField(singleFieldRect, fontSizeProp);
  22. singleFieldRect.y += EditorGUIUtility.singleLineHeight;
  23. EditorGUI.PropertyField(singleFieldRect, textProp);
  24. }
  25. }