Skip to content

Instantly share code, notes, and snippets.

@eral
Last active August 29, 2015 14:03
Show Gist options
  • Save eral/f64399a2b6859a29f9f3 to your computer and use it in GitHub Desktop.
Save eral/f64399a2b6859a29f9f3 to your computer and use it in GitHub Desktop.
Quaternion Euler Property Drawer
// (C) 2014 ERAL
// Distributed under the Boost Software License, Version 1.0.
// (See copy at http://www.boost.org/LICENSE_1_0.txt)
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
[CustomPropertyDrawer(typeof(QuaternionEulerAttribute))]
public class QuaternionEulerPropertyDrawer : PropertyDrawer {
private Vector3 value = Vector3.one;
private Quaternion last = Quaternion.identity;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
if (SerializedPropertyType.Quaternion == property.propertyType) {
EditorGUIUtility.LookLikeControls();
var is_update = (!last.Equals(property.quaternionValue));
is_update = is_update || (Quaternion.Euler(value) != last);
if (is_update) {
value = property.quaternionValue.eulerAngles;
last = Quaternion.Euler(value);
}
EditorGUI.BeginChangeCheck();
value = EditorGUI.Vector3Field(position, label, value);
if (EditorGUI.EndChangeCheck()) {
last = property.quaternionValue = Quaternion.Euler(value);
}
} else {
EditorGUI.LabelField(position, label, new GUIContent("This type has not supported."));
}
}
}
#endif
public class QuaternionEulerAttribute : PropertyAttribute {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment