Tri-Inspector/Editor.Integrations/Odin/OdinObjectDrawer.cs

81 lines
2.0 KiB
C#
Raw Normal View History

using System;
using Sirenix.Utilities;
using Sirenix.OdinInspector.Editor;
2022-11-11 12:17:12 -05:00
using Sirenix.Utilities.Editor;
using TriInspector.Utilities;
using UnityEngine;
namespace TriInspector.Editor.Integrations.Odin
{
[DrawerPriority(0.0, 10000.0, 1.0)]
public class OdinObjectDrawer<T> : OdinValueDrawer<T>, IDisposable
where T : UnityEngine.Object
{
2022-06-06 12:17:31 -04:00
private bool _initialized;
private TriPropertyTree _propertyTree;
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))
{
return false;
}
return true;
}
protected override bool CanDrawValueProperty(InspectorProperty property)
{
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)
{
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);
}
_propertyTree.Update();
2023-03-22 03:49:53 -04:00
_propertyTree.RunValidationIfRequired();
using (TriGuiHelper.PushEditorTarget(ValueEntry.SmartValue))
{
_propertyTree.Draw();
}
2022-11-11 12:17:12 -05:00
if (_propertyTree.RepaintRequired)
{
GUIHelper.RequestRepaint();
}
}
}
}