@@ -8,83 +8,19 @@ namespace ScriptableObjectArchitecture.Editor
88 [ CustomPropertyDrawer ( typeof ( Quaternion ) ) ]
99 public class QuaternionDrawer : PropertyDrawer
1010 {
11- private const int ElementsInQuaternion = 4 ;
12- private const float ElementLabelWidth = 13 ;
13- private const float ElementSpacing = 2 ;
11+ private const float Height = 20 ;
1412
1513 public override void OnGUI ( Rect position , SerializedProperty property , GUIContent label )
1614 {
17- if ( HasLabel ( label ) )
18- {
19- Rect labelRect = GetLabelRect ( position ) ;
20- Rect valueRect = GetValueRect ( position ) ;
15+ Vector4 vector = property . quaternionValue . ToVector4 ( ) ;
2116
22- EditorGUI . LabelField ( labelRect , label ) ;
23- DrawValue ( valueRect , property ) ;
24- }
25- else
26- {
27- DrawValue ( position , property ) ;
28- }
29- }
30- private void DrawValue ( Rect rect , SerializedProperty property )
31- {
32- float oldLabelWidth = EditorGUIUtility . labelWidth ;
33- EditorGUIUtility . labelWidth = ElementLabelWidth ;
34-
35- Quaternion quaternion = property . quaternionValue ;
36-
37- quaternion . x = DrawElement ( GetElementRect ( rect , 0 ) , quaternion . x , new GUIContent ( "X" ) ) ;
38- quaternion . y = DrawElement ( GetElementRect ( rect , 1 ) , quaternion . y , new GUIContent ( "Y" ) ) ;
39- quaternion . z = DrawElement ( GetElementRect ( rect , 2 ) , quaternion . z , new GUIContent ( "Z" ) ) ;
40- quaternion . w = DrawElement ( GetElementRect ( rect , 3 ) , quaternion . w , new GUIContent ( "W" ) ) ;
17+ EditorGUI . Vector4Field ( position , label , vector ) ;
4118
42- property . quaternionValue = quaternion ;
43- EditorGUIUtility . labelWidth = oldLabelWidth ;
44- }
45- private float DrawElement ( Rect rect , float value , GUIContent label )
46- {
47- return EditorGUI . FloatField ( rect , label , value ) ;
48- }
49- private Rect GetElementRect ( Rect parentRect , int index )
50- {
51- float widthPerElement = parentRect . width / ElementsInQuaternion ;
52-
53- return new Rect ( )
54- {
55- x = parentRect . x + widthPerElement * index ,
56- y = parentRect . y ,
57- width = widthPerElement - ElementSpacing ,
58- height = parentRect . height ,
59- } ;
60- }
61- private Rect GetLabelRect ( Rect parentRect )
62- {
63- return new Rect ( )
64- {
65- x = parentRect . x ,
66- y = parentRect . y ,
67- width = EditorGUIUtility . labelWidth ,
68- height = parentRect . height ,
69- } ;
70- }
71- private Rect GetValueRect ( Rect parentRect )
72- {
73- return new Rect ( )
74- {
75- x = parentRect . x + EditorGUIUtility . labelWidth + ElementSpacing ,
76- y = parentRect . y ,
77- width = parentRect . width - EditorGUIUtility . labelWidth ,
78- height = parentRect . height ,
79- } ;
80- }
81- private bool HasLabel ( GUIContent label )
82- {
83- return label != GUIContent . none ;
19+ property . quaternionValue = new Quaternion ( vector . x , vector . y , vector . z , vector . w ) ;
8420 }
8521 public override float GetPropertyHeight ( SerializedProperty property , GUIContent label )
8622 {
87- return EditorGUIUtility . singleLineHeight ;
23+ return Height ;
8824 }
8925 }
9026}
0 commit comments