FrameRangeDrawer.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. using UnityEditor;
  3. using Flux;
  4. [CustomPropertyDrawer(typeof(FrameRange))]
  5. public class FrameRangeDrawer : PropertyDrawer {
  6. private const int PREFIX_WIDTH = 15;
  7. private const int ELEMENT_SPACE = 10;
  8. private const int HALF_ELEMENT_SPACE = ELEMENT_SPACE / 2;
  9. public override float GetPropertyHeight( SerializedProperty property, GUIContent label )
  10. {
  11. return base.GetPropertyHeight (property, label);
  12. }
  13. public override void OnGUI( Rect position, SerializedProperty property, GUIContent label )
  14. {
  15. SerializedProperty start = property.FindPropertyRelative( "_start" );
  16. SerializedProperty end = property.FindPropertyRelative( "_end" );
  17. Rect r = position;
  18. r.height = EditorGUIUtility.singleLineHeight;
  19. r.width = EditorGUIUtility.labelWidth;
  20. EditorGUI.PrefixLabel( r, label );
  21. float fieldWidth = (position.width - EditorGUIUtility.labelWidth - PREFIX_WIDTH - PREFIX_WIDTH - ELEMENT_SPACE) * 0.5f;
  22. r.xMin = r.xMax;
  23. r.width = PREFIX_WIDTH;
  24. GUI.Label( r, "S:", EditorStyles.label );
  25. r.xMin = r.xMax;
  26. r.width = fieldWidth;
  27. start.intValue = EditorGUI.IntField( r, start.intValue );
  28. r.xMin = r.xMax + ELEMENT_SPACE;
  29. r.width = PREFIX_WIDTH;
  30. GUI.Label( r, "E:", EditorStyles.label );
  31. r.xMin = r.xMax;
  32. r.width = fieldWidth;
  33. end.intValue = EditorGUI.IntField( r, end.intValue );
  34. }
  35. }