Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 59b8b9d

Browse files
Switched quaternion drawer to use EditorGUI.Vector4 instead
1 parent d19f46f commit 59b8b9d

2 files changed

Lines changed: 8 additions & 70 deletions

File tree

Assets/SO Architecture/Editor/Drawers/BaseReferenceDrawer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public sealed class BaseReferenceDrawer : PropertyDrawer
1818
"Use Variable"
1919
};
2020

21+
private const float MultilineThreshold = 20;
22+
2123
// Property Names
2224
private const string VARIABLE_PROPERTY_NAME = "_variable";
2325
private const string CONSTANT_VALUE_PROPERTY_NAME = "_constantValue";
@@ -55,7 +57,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
5557
}
5658
private bool IsConstantValueMultiline(SerializedProperty property)
5759
{
58-
return GenericPropertyDrawer.GetHeight(property, ValueType) > EditorGUIUtility.singleLineHeight;
60+
return GenericPropertyDrawer.GetHeight(property, ValueType) > MultilineThreshold;
5961
}
6062
private Rect DrawLabel(Rect position, SerializedProperty property, GUIContent label)
6163
{

Assets/SO Architecture/Editor/Drawers/QuaternionDrawer.cs

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)