2022-01-07 12:21:36 -05:00
|
|
|
|
using TriInspector;
|
|
|
|
|
using TriInspector.Drawers;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-07-14 05:51:08 -04:00
|
|
|
|
[assembly: RegisterTriValueDrawer(typeof(ObjectReferenceDrawer), TriDrawerOrder.Fallback)]
|
2022-01-07 12:21:36 -05:00
|
|
|
|
|
|
|
|
|
namespace TriInspector.Drawers
|
|
|
|
|
{
|
2022-07-14 05:51:08 -04:00
|
|
|
|
public class ObjectReferenceDrawer : TriValueDrawer<Object>
|
2022-01-07 12:21:36 -05:00
|
|
|
|
{
|
2022-07-14 05:51:08 -04:00
|
|
|
|
public override TriElement CreateElement(TriValue<Object> value, TriElement next)
|
2022-01-07 12:21:36 -05:00
|
|
|
|
{
|
2022-12-07 02:38:25 -05:00
|
|
|
|
if (value.Property.IsRootProperty || value.Property.TryGetSerializedProperty(out _))
|
2022-06-01 03:35:33 -04:00
|
|
|
|
{
|
|
|
|
|
return next;
|
|
|
|
|
}
|
2022-01-07 12:21:36 -05:00
|
|
|
|
|
|
|
|
|
return new ObjectReferenceDrawerElement(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class ObjectReferenceDrawerElement : TriElement
|
|
|
|
|
{
|
2022-07-14 05:51:08 -04:00
|
|
|
|
private TriValue<Object> _propertyValue;
|
2022-06-10 08:33:05 -04:00
|
|
|
|
private readonly bool _allowSceneObjects;
|
2022-01-07 12:21:36 -05:00
|
|
|
|
|
2022-07-14 05:51:08 -04:00
|
|
|
|
public ObjectReferenceDrawerElement(TriValue<Object> propertyValue)
|
2022-01-07 12:21:36 -05:00
|
|
|
|
{
|
|
|
|
|
_propertyValue = propertyValue;
|
2022-12-07 02:38:25 -05:00
|
|
|
|
_allowSceneObjects = propertyValue.Property.PropertyTree.TargetIsPersistent == false;
|
2022-01-07 12:21:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override float GetHeight(float width)
|
|
|
|
|
{
|
|
|
|
|
return EditorGUIUtility.singleLineHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnGUI(Rect position)
|
|
|
|
|
{
|
2022-12-07 02:38:25 -05:00
|
|
|
|
var value = _propertyValue.SmartValue;
|
2022-01-07 12:21:36 -05:00
|
|
|
|
|
2022-06-10 08:33:05 -04:00
|
|
|
|
EditorGUI.BeginChangeCheck();
|
2022-01-07 12:21:36 -05:00
|
|
|
|
|
2022-06-10 08:33:05 -04:00
|
|
|
|
value = EditorGUI.ObjectField(position, _propertyValue.Property.DisplayNameContent, value,
|
|
|
|
|
_propertyValue.Property.FieldType, _allowSceneObjects);
|
2022-01-07 12:21:36 -05:00
|
|
|
|
|
|
|
|
|
if (EditorGUI.EndChangeCheck())
|
|
|
|
|
{
|
2024-01-24 04:58:07 -05:00
|
|
|
|
_propertyValue.SetValue(value);
|
2022-01-07 12:21:36 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|