module-inspector/Editor/Drawers/QuaternionToEulerAttributeDrawer.cs
Anders Ejlersen 7d99d62e11 1.5.0: Added IntToLayerMask, marked QuaternionToEuler as obsolete as of 2021 and fixed a couple of bugs
- Drawer: Added IntToLayerMaskAttribute, if a raw int is wanted instead of LayerMask
- Drawer: Added option to either use full or short type name, when using SerializeReferenceTo
- Extension: Fixed issue, where GetValueType and GetValue for SerializedProperty would throw exceptions, if field is private
2022-06-26 15:06:52 +02:00

38 lines
1.3 KiB
C#

#if !UNITY_2021_1_OR_NEWER
using Module.Inspector.Editor.Utilities;
using UnityEditor;
using UnityEngine;
namespace Module.Inspector.Editor
{
[CustomPropertyDrawer(typeof(QuaternionToEulerAttribute))]
internal sealed class QuaternionToEulerAttributeDrawer : DrawerPropertyDrawer
{
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
{
if (property.propertyType != SerializedPropertyType.Quaternion)
return false;
EditorGUI.BeginChangeCheck();
EditorGUI.BeginProperty(position, label, property);
{
Vector3 euler = property.quaternionValue.eulerAngles;
Vector3 temp = EditorGUI.Vector3Field(position, label, euler);
property.quaternionValue = Quaternion.Euler(temp);
}
EditorGUI.EndProperty();
bool changed = EditorGUI.EndChangeCheck();
if (changed)
property.serializedObject.ApplyModifiedProperties();
return true;
}
public override string GetErrorMessage(SerializedProperty property)
{
return "Only supports quaternions";
}
}
}
#endif