1.9.0: Added support for attributes for drawing handles in the scene
This commit is contained in:
parent
81906d49dd
commit
5ce34bde70
48 changed files with 1354 additions and 8 deletions
40
Editor/Handles/RotationHandleAttributeDrawer.cs
Normal file
40
Editor/Handles/RotationHandleAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(RotationHandleAttribute))]
|
||||
internal sealed class RotationHandleAttributeDrawer : HandlePropertyDrawer
|
||||
{
|
||||
public override void Draw(HandleDrawerPropertyAttribute attribute, SerializedProperty serializedProperty)
|
||||
{
|
||||
var att = (RotationHandleAttribute)attribute;
|
||||
bool hasPositionField = EditorHandleUtility.TryGetWorldPosition(serializedProperty, att.fieldPosition, att.space, out Vector3 worldPosition);
|
||||
Quaternion worldRotation = EditorHandleUtility.GetWorldRotation(serializedProperty, att.space);
|
||||
Color color = Handles.color;
|
||||
|
||||
if (hasPositionField)
|
||||
worldPosition = EditorHandleUtility.PositionHandle(worldPosition, worldRotation);
|
||||
|
||||
worldRotation = EditorHandleUtility.RotationHandle(worldPosition, worldRotation);
|
||||
|
||||
if (hasPositionField)
|
||||
EditorHandleUtility.SetWorldPosition(serializedProperty, att.fieldPosition, worldPosition, att.space);
|
||||
|
||||
EditorHandleUtility.SetWorldRotation(serializedProperty, worldRotation, att.space);
|
||||
Handles.color = color;
|
||||
}
|
||||
|
||||
public override bool IsValidFor(SerializedProperty serializedProperty)
|
||||
{
|
||||
switch (serializedProperty.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Quaternion:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue