2022-05-21 04:49:12 -04:00
|
|
|
|
using System;
|
2022-05-25 03:05:29 -04:00
|
|
|
|
using Sirenix.Utilities;
|
2022-05-21 04:49:12 -04:00
|
|
|
|
using Sirenix.OdinInspector.Editor;
|
2022-11-11 12:17:12 -05:00
|
|
|
|
using Sirenix.Utilities.Editor;
|
2022-05-25 04:33:34 -04:00
|
|
|
|
using TriInspector.Utilities;
|
2022-05-21 04:49:12 -04:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace TriInspector.Editor.Integrations.Odin
|
|
|
|
|
{
|
|
|
|
|
[DrawerPriority(0.0, 10000.0, 1.0)]
|
2022-05-25 03:05:29 -04:00
|
|
|
|
public class OdinObjectDrawer<T> : OdinValueDrawer<T>, IDisposable
|
2022-05-21 04:49:12 -04:00
|
|
|
|
where T : UnityEngine.Object
|
|
|
|
|
{
|
2022-06-06 12:17:31 -04:00
|
|
|
|
private bool _initialized;
|
2022-05-21 04:49:12 -04:00
|
|
|
|
private TriPropertyTree _propertyTree;
|
|
|
|
|
|
2022-05-25 03:05:29 -04:00
|
|
|
|
public override bool CanDrawTypeFilter(Type type)
|
|
|
|
|
{
|
2022-06-06 12:17:31 -04:00
|
|
|
|
if (type == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-28 08:29:49 -04:00
|
|
|
|
if (!TriOdinUtility.IsDrawnByTri(type))
|
2022-05-25 03:05:29 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool CanDrawValueProperty(InspectorProperty property)
|
2022-05-21 04:49:12 -04:00
|
|
|
|
{
|
|
|
|
|
if (!property.IsTreeRoot)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (property.Tree.UnitySerializedObject == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_propertyTree?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void DrawPropertyLayout(GUIContent label)
|
|
|
|
|
{
|
2022-05-25 04:33:34 -04:00
|
|
|
|
if (TriGuiHelper.IsEditorTargetPushed(ValueEntry.SmartValue))
|
|
|
|
|
{
|
|
|
|
|
GUILayout.Label("Recursive inline editors not supported");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 12:17:31 -04:00
|
|
|
|
if (!_initialized)
|
|
|
|
|
{
|
|
|
|
|
_initialized = true;
|
|
|
|
|
var serializedObject = Property.Tree.UnitySerializedObject;
|
|
|
|
|
_propertyTree = new TriPropertyTreeForSerializedObject(serializedObject);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-21 04:49:12 -04:00
|
|
|
|
_propertyTree.Update();
|
2023-03-22 03:49:53 -04:00
|
|
|
|
_propertyTree.RunValidationIfRequired();
|
2022-05-21 04:49:12 -04:00
|
|
|
|
|
2022-05-25 04:33:34 -04:00
|
|
|
|
using (TriGuiHelper.PushEditorTarget(ValueEntry.SmartValue))
|
|
|
|
|
{
|
|
|
|
|
_propertyTree.Draw();
|
|
|
|
|
}
|
2022-11-11 12:17:12 -05:00
|
|
|
|
|
|
|
|
|
if (_propertyTree.RepaintRequired)
|
|
|
|
|
{
|
|
|
|
|
GUIHelper.RequestRepaint();
|
|
|
|
|
}
|
2022-05-21 04:49:12 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|