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
103
Editor/Handles/BoxHandleAttributeDrawer.cs
Normal file
103
Editor/Handles/BoxHandleAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(BoxHandleAttribute))]
|
||||
internal sealed class BoxHandleAttributeDrawer : HandlePropertyDrawer
|
||||
{
|
||||
public override void Draw(HandleDrawerPropertyAttribute attribute, SerializedProperty serializedProperty)
|
||||
{
|
||||
var att = (BoxHandleAttribute)attribute;
|
||||
bool hasPositionField = EditorHandleUtility.TryGetWorldPosition(serializedProperty, att.fieldPosition, att.space, out Vector3 worldPosition);
|
||||
bool hasRotationField = EditorHandleUtility.TryGetWorldRotation(serializedProperty, att.fieldRotation, att.space, out Quaternion worldRotation);
|
||||
Vector3 size = GetValue(serializedProperty, out EAxis axii);
|
||||
Color color = Handles.color;
|
||||
|
||||
if (hasPositionField)
|
||||
worldPosition = EditorHandleUtility.PositionHandle(worldPosition, worldRotation);
|
||||
if (hasRotationField)
|
||||
worldRotation = EditorHandleUtility.RotationHandle(worldPosition, worldRotation);
|
||||
|
||||
size = EditorHandleUtility.BoxHandle(worldPosition, worldRotation, size, axii);
|
||||
|
||||
if (hasPositionField)
|
||||
EditorHandleUtility.SetWorldPosition(serializedProperty, att.fieldPosition, worldPosition, att.space);
|
||||
if (hasRotationField)
|
||||
EditorHandleUtility.SetWorldRotation(serializedProperty, att.fieldRotation, worldRotation, att.space);
|
||||
|
||||
SetValue(serializedProperty, size);
|
||||
Handles.color = color;
|
||||
}
|
||||
|
||||
private Vector3 GetValue(SerializedProperty serializedProperty, out EAxis axii)
|
||||
{
|
||||
switch (serializedProperty.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
axii = EAxis.X;
|
||||
return new Vector3(serializedProperty.intValue, serializedProperty.intValue, serializedProperty.intValue);
|
||||
case SerializedPropertyType.Float:
|
||||
axii = EAxis.X;
|
||||
return new Vector3(serializedProperty.floatValue, serializedProperty.floatValue, serializedProperty.floatValue);
|
||||
case SerializedPropertyType.Vector2:
|
||||
axii = EAxis.X | EAxis.Y;
|
||||
return new Vector3(serializedProperty.vector2Value.x, serializedProperty.vector2Value.y, 0f);
|
||||
case SerializedPropertyType.Vector3:
|
||||
axii = EAxis.All;
|
||||
return serializedProperty.vector3Value;
|
||||
case SerializedPropertyType.Vector2Int:
|
||||
axii = EAxis.X | EAxis.Y;
|
||||
return new Vector3(serializedProperty.vector2IntValue.x, serializedProperty.vector2IntValue.y, 0f);
|
||||
case SerializedPropertyType.Vector3Int:
|
||||
axii = EAxis.All;
|
||||
return serializedProperty.vector3IntValue;
|
||||
default:
|
||||
axii = EAxis.X;
|
||||
return Vector3.one;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetValue(SerializedProperty serializedProperty, Vector3 value)
|
||||
{
|
||||
switch (serializedProperty.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
serializedProperty.intValue = Mathf.RoundToInt(value.x);
|
||||
break;
|
||||
case SerializedPropertyType.Float:
|
||||
serializedProperty.floatValue = value.x;
|
||||
break;
|
||||
case SerializedPropertyType.Vector2:
|
||||
serializedProperty.vector2Value = new Vector2(value.x, value.y);
|
||||
break;
|
||||
case SerializedPropertyType.Vector3:
|
||||
serializedProperty.vector3Value = value;
|
||||
break;
|
||||
case SerializedPropertyType.Vector2Int:
|
||||
serializedProperty.vector2IntValue = new Vector2Int(Mathf.RoundToInt(value.x), Mathf.RoundToInt(value.y));
|
||||
break;
|
||||
case SerializedPropertyType.Vector3Int:
|
||||
serializedProperty.vector3IntValue = new Vector3Int(Mathf.RoundToInt(value.x), Mathf.RoundToInt(value.y), Mathf.RoundToInt(value.z));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Handles/BoxHandleAttributeDrawer.cs.meta
Normal file
3
Editor/Handles/BoxHandleAttributeDrawer.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3dfa4467da7444549585b2992516427e
|
||||
timeCreated: 1669475655
|
||||
72
Editor/Handles/CircleHandleAttributeDrawer.cs
Normal file
72
Editor/Handles/CircleHandleAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(CircleHandleAttribute))]
|
||||
internal sealed class CircleHandleAttributeDrawer : HandlePropertyDrawer
|
||||
{
|
||||
public override void Draw(HandleDrawerPropertyAttribute attribute, SerializedProperty serializedProperty)
|
||||
{
|
||||
var att = (CircleHandleAttribute)attribute;
|
||||
bool hasPositionField = EditorHandleUtility.TryGetWorldPosition(serializedProperty, att.fieldPosition, att.space, out Vector3 worldPosition);
|
||||
bool hasRotationField = EditorHandleUtility.TryGetWorldRotation(serializedProperty, att.fieldRotation, att.space, out Quaternion worldRotation);
|
||||
float size = GetValue(serializedProperty);
|
||||
Color color = Handles.color;
|
||||
|
||||
if (hasPositionField)
|
||||
worldPosition = EditorHandleUtility.PositionHandle(worldPosition, worldRotation);
|
||||
if (hasRotationField)
|
||||
worldRotation = EditorHandleUtility.RotationHandle(worldPosition, worldRotation);
|
||||
|
||||
size = EditorHandleUtility.CircleHandle(worldPosition, worldRotation, size);
|
||||
|
||||
if (hasPositionField)
|
||||
EditorHandleUtility.SetWorldPosition(serializedProperty, att.fieldPosition, worldPosition, att.space);
|
||||
if (hasRotationField)
|
||||
EditorHandleUtility.SetWorldRotation(serializedProperty, att.fieldRotation, worldRotation, att.space);
|
||||
|
||||
SetValue(serializedProperty, size);
|
||||
Handles.color = color;
|
||||
}
|
||||
|
||||
private float GetValue(SerializedProperty serializedProperty)
|
||||
{
|
||||
switch (serializedProperty.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
return serializedProperty.intValue;
|
||||
case SerializedPropertyType.Float:
|
||||
return serializedProperty.floatValue;
|
||||
default:
|
||||
return 1f;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetValue(SerializedProperty serializedProperty, float value)
|
||||
{
|
||||
switch (serializedProperty.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
serializedProperty.intValue = Mathf.RoundToInt(value);
|
||||
break;
|
||||
case SerializedPropertyType.Float:
|
||||
serializedProperty.floatValue = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsValidFor(SerializedProperty serializedProperty)
|
||||
{
|
||||
switch (serializedProperty.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
case SerializedPropertyType.Float:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Handles/CircleHandleAttributeDrawer.cs.meta
Normal file
3
Editor/Handles/CircleHandleAttributeDrawer.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1ec82d143086477aa01a1ce9634b2689
|
||||
timeCreated: 1669475467
|
||||
46
Editor/Handles/LabelHandleAttributeDrawer.cs
Normal file
46
Editor/Handles/LabelHandleAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System.Text;
|
||||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(LabelHandleAttribute))]
|
||||
internal sealed class LabelHandleAttributeDrawer : HandlePropertyDrawer
|
||||
{
|
||||
private readonly StringBuilder builder = new StringBuilder();
|
||||
private GUIStyle style;
|
||||
|
||||
public override void Draw(HandleDrawerPropertyAttribute attribute, SerializedProperty serializedProperty)
|
||||
{
|
||||
var att = (LabelHandleAttribute)attribute;
|
||||
Vector3 wp = EditorHandleUtility.GetWorldPosition(serializedProperty, att.fieldPosition, att.space);
|
||||
|
||||
if (style == null)
|
||||
{
|
||||
style = new GUIStyle(GUI.skin.label);
|
||||
style.alignment = TextAnchor.MiddleCenter;
|
||||
}
|
||||
|
||||
builder.Clear();
|
||||
|
||||
if ((att.type & ELabelType.Field) != 0)
|
||||
builder.Append(serializedProperty.displayName);
|
||||
|
||||
if ((att.type & ELabelType.Value) != 0)
|
||||
{
|
||||
if ((att.type & ELabelType.Field) != 0)
|
||||
builder.Append('\n');
|
||||
|
||||
builder.Append(serializedProperty.GetValueAsString());
|
||||
}
|
||||
|
||||
Handles.Label(wp, builder.ToString(), style);
|
||||
}
|
||||
|
||||
public override bool IsValidFor(SerializedProperty serializedProperty)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Handles/LabelHandleAttributeDrawer.cs.meta
Normal file
3
Editor/Handles/LabelHandleAttributeDrawer.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9a9cc06839c34083a5e8793dab6ac651
|
||||
timeCreated: 1669475780
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Handles/PositionHandleAttributeDrawer.cs.meta
Normal file
3
Editor/Handles/PositionHandleAttributeDrawer.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 517a50351ebe49549d55dfe6c037941c
|
||||
timeCreated: 1669408276
|
||||
103
Editor/Handles/RectangleHandleAttributeDrawer.cs
Normal file
103
Editor/Handles/RectangleHandleAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(RectangleHandleAttribute))]
|
||||
internal sealed class RectangleHandleAttributeDrawer : HandlePropertyDrawer
|
||||
{
|
||||
public override void Draw(HandleDrawerPropertyAttribute attribute, SerializedProperty serializedProperty)
|
||||
{
|
||||
var att = (RectangleHandleAttribute)attribute;
|
||||
bool hasPositionField = EditorHandleUtility.TryGetWorldPosition(serializedProperty, att.fieldPosition, att.space, out Vector3 worldPosition);
|
||||
bool hasRotationField = EditorHandleUtility.TryGetWorldRotation(serializedProperty, att.fieldRotation, att.space, out Quaternion worldRotation);
|
||||
Vector2 size = GetValue(serializedProperty, out EAxis axii);
|
||||
Color color = Handles.color;
|
||||
|
||||
if (hasPositionField)
|
||||
worldPosition = EditorHandleUtility.PositionHandle(worldPosition, worldRotation);
|
||||
if (hasRotationField)
|
||||
worldRotation = EditorHandleUtility.RotationHandle(worldPosition, worldRotation);
|
||||
|
||||
size = EditorHandleUtility.RectHandle(worldPosition, worldRotation, size, axii);
|
||||
|
||||
if (hasPositionField)
|
||||
EditorHandleUtility.SetWorldPosition(serializedProperty, att.fieldPosition, worldPosition, att.space);
|
||||
if (hasRotationField)
|
||||
EditorHandleUtility.SetWorldRotation(serializedProperty, att.fieldRotation, worldRotation, att.space);
|
||||
|
||||
SetValue(serializedProperty, size);
|
||||
Handles.color = color;
|
||||
}
|
||||
|
||||
private Vector2 GetValue(SerializedProperty serializedProperty, out EAxis axii)
|
||||
{
|
||||
switch (serializedProperty.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
axii = EAxis.X;
|
||||
return new Vector2(serializedProperty.intValue, serializedProperty.intValue);
|
||||
case SerializedPropertyType.Float:
|
||||
axii = EAxis.X;
|
||||
return new Vector2(serializedProperty.floatValue, serializedProperty.floatValue);
|
||||
case SerializedPropertyType.Vector2:
|
||||
axii = EAxis.All;
|
||||
return serializedProperty.vector2Value;
|
||||
case SerializedPropertyType.Vector3:
|
||||
axii = EAxis.All;
|
||||
return serializedProperty.vector3Value;
|
||||
case SerializedPropertyType.Vector2Int:
|
||||
axii = EAxis.All;
|
||||
return serializedProperty.vector2IntValue;
|
||||
case SerializedPropertyType.Vector3Int:
|
||||
axii = EAxis.All;
|
||||
return new Vector2(serializedProperty.vector3IntValue.x, serializedProperty.vector3IntValue.y);
|
||||
default:
|
||||
axii = EAxis.None;
|
||||
return Vector2.one;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetValue(SerializedProperty serializedProperty, Vector2 value)
|
||||
{
|
||||
switch (serializedProperty.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
serializedProperty.intValue = Mathf.RoundToInt(value.x);
|
||||
break;
|
||||
case SerializedPropertyType.Float:
|
||||
serializedProperty.floatValue = value.x;
|
||||
break;
|
||||
case SerializedPropertyType.Vector2:
|
||||
serializedProperty.vector2Value = value;
|
||||
break;
|
||||
case SerializedPropertyType.Vector3:
|
||||
serializedProperty.vector3Value = value;
|
||||
break;
|
||||
case SerializedPropertyType.Vector2Int:
|
||||
serializedProperty.vector2IntValue = new Vector2Int(Mathf.RoundToInt(value.x), Mathf.RoundToInt(value.y));
|
||||
break;
|
||||
case SerializedPropertyType.Vector3Int:
|
||||
serializedProperty.vector3IntValue = new Vector3Int(Mathf.RoundToInt(value.x), Mathf.RoundToInt(value.y), 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Handles/RectangleHandleAttributeDrawer.cs.meta
Normal file
3
Editor/Handles/RectangleHandleAttributeDrawer.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: add3ba2b5b1c46088aaf8604ce8929f8
|
||||
timeCreated: 1669475681
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Handles/RotationHandleAttributeDrawer.cs.meta
Normal file
3
Editor/Handles/RotationHandleAttributeDrawer.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9193d6531ba843749d9fd78bc6b166d7
|
||||
timeCreated: 1669475582
|
||||
72
Editor/Handles/SphereHandleAttributeDrawer.cs
Normal file
72
Editor/Handles/SphereHandleAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(SphereHandleAttribute))]
|
||||
internal sealed class SphereHandleAttributeDrawer : HandlePropertyDrawer
|
||||
{
|
||||
public override void Draw(HandleDrawerPropertyAttribute attribute, SerializedProperty serializedProperty)
|
||||
{
|
||||
var att = (SphereHandleAttribute)attribute;
|
||||
bool hasPositionField = EditorHandleUtility.TryGetWorldPosition(serializedProperty, att.fieldPosition, att.space, out Vector3 worldPosition);
|
||||
bool hasRotationField = EditorHandleUtility.TryGetWorldRotation(serializedProperty, att.fieldRotation, att.space, out Quaternion worldRotation);
|
||||
float size = GetValue(serializedProperty);
|
||||
Color color = Handles.color;
|
||||
|
||||
if (hasPositionField)
|
||||
worldPosition = EditorHandleUtility.PositionHandle(worldPosition, worldRotation);
|
||||
if (hasRotationField)
|
||||
worldRotation = EditorHandleUtility.RotationHandle(worldPosition, worldRotation);
|
||||
|
||||
size = EditorHandleUtility.SphereHandle(worldPosition, worldRotation, size);
|
||||
|
||||
if (hasPositionField)
|
||||
EditorHandleUtility.SetWorldPosition(serializedProperty, att.fieldPosition, worldPosition, att.space);
|
||||
if (hasRotationField)
|
||||
EditorHandleUtility.SetWorldRotation(serializedProperty, att.fieldRotation, worldRotation, att.space);
|
||||
|
||||
SetValue(serializedProperty, size);
|
||||
Handles.color = color;
|
||||
}
|
||||
|
||||
private float GetValue(SerializedProperty serializedProperty)
|
||||
{
|
||||
switch (serializedProperty.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
return serializedProperty.intValue;
|
||||
case SerializedPropertyType.Float:
|
||||
return serializedProperty.floatValue;
|
||||
default:
|
||||
return 1f;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetValue(SerializedProperty serializedProperty, float value)
|
||||
{
|
||||
switch (serializedProperty.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
serializedProperty.intValue = Mathf.RoundToInt(value);
|
||||
break;
|
||||
case SerializedPropertyType.Float:
|
||||
serializedProperty.floatValue = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsValidFor(SerializedProperty serializedProperty)
|
||||
{
|
||||
switch (serializedProperty.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
case SerializedPropertyType.Float:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Handles/SphereHandleAttributeDrawer.cs.meta
Normal file
3
Editor/Handles/SphereHandleAttributeDrawer.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 199eb743ed1846d498b6bbba499cf9f6
|
||||
timeCreated: 1669475521
|
||||
Loading…
Add table
Add a link
Reference in a new issue