Tri-Inspector/Editor.Extras/Drawers/CustomBuiltInDrawer.cs

50 lines
1.9 KiB
C#
Raw Normal View History

using TriInspector;
using TriInspector.Drawers;
2023-07-29 05:08:53 -04:00
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)
{
2023-10-25 10:34:50 -04:00
if (property.TryGetAttribute(out DrawWithUnityAttribute withUnityAttribute) &&
withUnityAttribute.WithUiToolkit)
{
handler.SetPreferredLabel(property.DisplayName);
2023-10-15 04:56:15 -04:00
2023-10-25 10:34:50 -04:00
var visualElement = handler.CreatePropertyGUI(serializedProperty);
2023-07-29 05:08:53 -04:00
2023-10-25 10:34:50 -04:00
if (visualElement != null &&
TriEditorCore.UiElementsRoots.TryGetValue(property.PropertyTree, out var rootElement))
{
return new TriUiToolkitPropertyElement(property, serializedProperty,
visualElement, rootElement);
}
2023-07-29 05:08:53 -04:00
}
return new TriBuiltInPropertyElement(property, serializedProperty, handler);
}
}
return base.CreateElement(propertyValue, next);
}
}
}