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/PositionHandleAttributeDrawer.cs
Normal file
40
Editor/Handles/PositionHandleAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(PositionHandleAttribute))]
|
||||
internal sealed class PositionHandleAttributeDrawer : HandlePropertyDrawer
|
||||
{
|
||||
public override void Draw(HandleDrawerPropertyAttribute attribute, SerializedProperty serializedProperty)
|
||||
{
|
||||
var att = (PositionHandleAttribute)attribute;
|
||||
Vector3 worldPosition = EditorHandleUtility.GetWorldPosition(serializedProperty, att.space);
|
||||
Quaternion worldRotation = EditorHandleUtility.GetWorldRotation(serializedProperty, att.space);
|
||||
Color color = Handles.color;
|
||||
|
||||
worldPosition = EditorHandleUtility.PositionHandle(worldPosition, worldRotation, att.axiis);
|
||||
EditorHandleUtility.SetWorldPosition(serializedProperty, worldPosition, att.space);
|
||||
Handles.color = color;
|
||||
}
|
||||
|
||||
public override bool IsValidFor(SerializedProperty serializedProperty)
|
||||
{
|
||||
switch (serializedProperty.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
case SerializedPropertyType.Float:
|
||||
case SerializedPropertyType.Vector2:
|
||||
case SerializedPropertyType.Vector3:
|
||||
case SerializedPropertyType.Vector2Int:
|
||||
case SerializedPropertyType.Vector3Int:
|
||||
return true;
|
||||
case SerializedPropertyType.ObjectReference:
|
||||
return serializedProperty.objectReferenceValue != null && serializedProperty.objectReferenceValue is Transform;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue