public static Quaternion Draw(GUIContent label, Quaternion quaternion, AngleDisplayType type) { var height = GetHeight(label, type); var rect = EditorGUILayout.GetControlRect(false, height); return(Draw(rect, label, quaternion, type)); }
public static void Draw(GUIContent label, SerializedProperty property, AngleDisplayType type) { var height = GetHeight(label, type); var rect = EditorGUILayout.GetControlRect(false, height); Draw(rect, label, property, type); }
public static float GetHeight(GUIContent label, AngleDisplayType type) { var height = EditorGUIUtility.singleLineHeight; if (type == AngleDisplayType.Look) { return(height + EditorGUIUtility.standardVerticalSpacing + height); } return(height); }
public static void Draw(Rect position, GUIContent label, SerializedProperty property, AngleDisplayType type) { if (property.propertyType == SerializedPropertyType.Quaternion) { property.quaternionValue = Draw(position, label, property.quaternionValue, type); } else { Debug.LogWarningFormat(_invalidTypeWarning, property.propertyPath); EditorGUI.PropertyField(position, property, label); } }
public static Quaternion Draw(Rect position, GUIContent label, Quaternion quaternion, AngleDisplayType type) { switch (type) { case AngleDisplayType.Raw: { _rawValues[0] = quaternion.x; _rawValues[1] = quaternion.y; _rawValues[2] = quaternion.z; _rawValues[3] = quaternion.w; using (var changes = new EditorGUI.ChangeCheckScope()) { EditorGUI.MultiFloatField(position, label, _rawLabels, _rawValues); if (changes.changed) { quaternion.Set(_rawValues[0], _rawValues[1], _rawValues[2], _rawValues[3]); } } break; } case AngleDisplayType.Euler: { var euler = quaternion.eulerAngles; _eulerValues[0] = euler.z; _eulerValues[1] = euler.x; _eulerValues[2] = euler.y; using (var changes = new EditorGUI.ChangeCheckScope()) { EditorGUI.MultiFloatField(position, label, _eulerLabels, _eulerValues); if (changes.changed) { quaternion.eulerAngles = new Vector3(_eulerValues[1], _eulerValues[2], _eulerValues[0]); } } break; } case AngleDisplayType.AxisAngle: { quaternion.ToAngleAxis(out var angle, out var axis); _axisAngleValues[0] = axis.x; _axisAngleValues[1] = axis.y; _axisAngleValues[2] = axis.z; _axisAngleValues[3] = angle; using (var changes = new EditorGUI.ChangeCheckScope()) { EditorGUI.MultiFloatField(position, label, _axisAngleLabels, _axisAngleValues); if (changes.changed) { quaternion = Quaternion.AngleAxis(_axisAngleValues[3], new Vector3(_axisAngleValues[0], _axisAngleValues[1], _axisAngleValues[2])); } } break; } case AngleDisplayType.Look: { position = EditorGUI.PrefixLabel(position, label); var forward = quaternion * Vector3.forward; var up = quaternion * Vector3.up; _lookForwardValues[0] = forward.x; _lookForwardValues[1] = forward.y; _lookForwardValues[2] = forward.z; _lookUpValues[0] = up.x; _lookUpValues[1] = up.y; _lookUpValues[2] = up.z; var height = EditorGUIUtility.singleLineHeight; var forwardRect = RectHelper.TakeHeight(ref position, height); RectHelper.TakeHeight(ref position, EditorGUIUtility.standardVerticalSpacing); var upRect = position; using (var changes = new EditorGUI.ChangeCheckScope()) { EditorGUI.MultiFloatField(forwardRect, _lookForwardLabels, _lookForwardValues); EditorGUI.MultiFloatField(upRect, _lookUpLabels, _lookUpValues); if (changes.changed) { quaternion = Quaternion.LookRotation(new Vector3(_lookForwardValues[0], _lookForwardValues[1], _lookForwardValues[2]), new Vector3(_lookUpValues[0], _lookUpValues[1], _lookUpValues[2])); } } break; } } return(quaternion); }