Tri-Inspector/Editor.Extras/Drawers/CustomBuiltInDrawer.cs
2023-08-02 20:32:24 +04:00

44 lines
1.6 KiB
C#

using TriInspector;
using TriInspector.Drawers;
using TriInspector.Editors;
using TriInspector.Elements;
using TriInspector.Utilities;
using TriInspectorUnityInternalBridge;
[assembly: RegisterTriValueDrawer(typeof(CustomBuiltInDrawer), TriDrawerOrder.Fallback - 999)]
namespace TriInspector.Drawers
{
public class CustomBuiltInDrawer : TriValueDrawer<object>
{
public override TriElement CreateElement(TriValue<object> propertyValue, TriElement next)
{
var property = propertyValue.Property;
if (property.TryGetSerializedProperty(out var serializedProperty))
{
var handler = ScriptAttributeUtilityProxy.GetHandler(serializedProperty);
var drawWithHandler = handler.hasPropertyDrawer ||
property.PropertyType == TriPropertyType.Primitive ||
TriUnityInspectorUtilities.MustDrawWithUnity(property);
if (drawWithHandler)
{
var visualElement = handler.CreatePropertyGUI(serializedProperty);
if (visualElement != null &&
TriEditor.UiElementsRoots.TryGetValue(property.PropertyTree, out var rootElement))
{
return new TriUiToolkitPropertyElement(property, serializedProperty,
visualElement, rootElement);
}
return new TriBuiltInPropertyElement(property, serializedProperty, handler);
}
}
return base.CreateElement(propertyValue, next);
}
}
}