2022-05-21 04:49:12 -04:00
|
|
|
|
using System;
|
|
|
|
|
using Sirenix.OdinInspector.Editor;
|
2022-11-11 12:17:12 -05:00
|
|
|
|
using Sirenix.Utilities.Editor;
|
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 OdinFieldDrawer<T> : OdinValueDrawer<T>, IDisposable
|
2022-05-21 04:49:12 -04:00
|
|
|
|
{
|
2022-06-06 12:17:31 -04:00
|
|
|
|
private bool _initialized;
|
2022-05-21 04:49:12 -04:00
|
|
|
|
private TriPropertyTree _propertyTree;
|
2022-06-01 03:35:33 -04:00
|
|
|
|
private LabelOverrideContext _labelOverrideContext;
|
2022-05-21 04:49:12 -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-21 04:49:12 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-28 08:29:49 -04:00
|
|
|
|
if (typeof(UnityEngine.Object).IsAssignableFrom(type))
|
2022-05-25 03:05:29 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-21 04:49:12 -04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-25 03:05:29 -04:00
|
|
|
|
protected override bool CanDrawValueProperty(InspectorProperty property)
|
2022-05-21 04:49:12 -04:00
|
|
|
|
{
|
|
|
|
|
if (property.IsTreeRoot)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-25 04:33:34 -04:00
|
|
|
|
for (var parent = property.Parent; parent != null; parent = parent.Parent)
|
|
|
|
|
{
|
|
|
|
|
var parentType = parent.ValueEntry.TypeOfValue;
|
2022-08-28 08:29:49 -04:00
|
|
|
|
if (TriOdinUtility.IsDrawnByTri(parentType))
|
2022-05-25 04:33:34 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-21 04:49:12 -04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_propertyTree?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void DrawPropertyLayout(GUIContent label)
|
|
|
|
|
{
|
2022-06-06 12:17:31 -04:00
|
|
|
|
if (!_initialized)
|
|
|
|
|
{
|
|
|
|
|
_initialized = true;
|
|
|
|
|
_propertyTree = new TriPropertyTreeForOdin<T>(ValueEntry);
|
|
|
|
|
_labelOverrideContext = new LabelOverrideContext(_propertyTree);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-01 03:35:33 -04:00
|
|
|
|
_propertyTree.Update();
|
2023-03-22 03:49:53 -04:00
|
|
|
|
_propertyTree.RunValidationIfRequired();
|
2022-05-21 04:49:12 -04:00
|
|
|
|
|
2022-06-01 03:35:33 -04:00
|
|
|
|
_labelOverrideContext.Label = label ?? GUIContent.none;
|
|
|
|
|
|
|
|
|
|
using (TriPropertyOverrideContext.BeginOverride(_labelOverrideContext))
|
2022-05-21 04:49:12 -04:00
|
|
|
|
{
|
2022-06-01 03:35:33 -04:00
|
|
|
|
_propertyTree.Draw();
|
|
|
|
|
}
|
2022-11-11 12:17:12 -05:00
|
|
|
|
|
|
|
|
|
if (_propertyTree.RepaintRequired)
|
|
|
|
|
{
|
|
|
|
|
GUIHelper.RequestRepaint();
|
|
|
|
|
}
|
2022-06-01 03:35:33 -04:00
|
|
|
|
}
|
2022-05-21 04:49:12 -04:00
|
|
|
|
|
2022-06-01 03:35:33 -04:00
|
|
|
|
private class LabelOverrideContext : TriPropertyOverrideContext
|
|
|
|
|
{
|
|
|
|
|
private readonly TriPropertyTree _tree;
|
2022-05-21 04:49:12 -04:00
|
|
|
|
|
2022-06-01 03:35:33 -04:00
|
|
|
|
public LabelOverrideContext(TriPropertyTree tree)
|
|
|
|
|
{
|
|
|
|
|
_tree = tree;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GUIContent Label { get; set; }
|
|
|
|
|
|
|
|
|
|
public override bool TryGetDisplayName(TriProperty property, out GUIContent displayName)
|
|
|
|
|
{
|
|
|
|
|
if (property == _tree.RootProperty)
|
|
|
|
|
{
|
|
|
|
|
displayName = Label;
|
|
|
|
|
return true;
|
2022-05-21 04:49:12 -04:00
|
|
|
|
}
|
2022-06-01 03:35:33 -04:00
|
|
|
|
|
|
|
|
|
displayName = default;
|
|
|
|
|
return false;
|
2022-05-21 04:49:12 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|