Move unity property drawer logic to CustombBuiltinDrawer

This commit is contained in:
VladV 2022-12-07 10:44:11 +04:00
parent 5b7697b59f
commit adb64bd3f8
4 changed files with 54 additions and 34 deletions

View File

@ -0,0 +1,34 @@
using TriInspector;
using TriInspector.Drawers;
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)
{
return new TriBuiltInPropertyElement(property, serializedProperty, handler);
}
}
return base.CreateElement(propertyValue, next);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 01398997ba14482caf7fd7c566774973
timeCreated: 1670393704

View File

@ -1,4 +1,5 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("TriInspector.Editor.Extras")]
[assembly: InternalsVisibleTo("TriInspector.Editor.Samples")]
[assembly: InternalsVisibleTo("TriInspector.Editor.Integrations.Odin")]

View File

@ -1,6 +1,4 @@
using System;
using TriInspector.Utilities;
using TriInspectorUnityInternalBridge;
using UnityEditor;
using UnityEngine;
@ -70,44 +68,28 @@ namespace TriInspector.Elements
private static TriElement CreateElement(TriProperty property, Props props)
{
var isSerializedProperty = property.TryGetSerializedProperty(out var serializedProperty);
var handler = isSerializedProperty
? ScriptAttributeUtilityProxy.GetHandler(serializedProperty)
: default(PropertyHandlerProxy?);
var drawWithUnity = handler.HasValue && handler.Value.hasPropertyDrawer ||
handler.HasValue && TriUnityInspectorUtilities.MustDrawWithUnity(property);
if (!drawWithUnity)
switch (property.PropertyType)
{
var propertyType = property.PropertyType;
switch (propertyType)
case TriPropertyType.Array:
{
case TriPropertyType.Array:
{
return CreateArrayElement(property);
}
return CreateArrayElement(property);
}
case TriPropertyType.Reference:
{
return CreateReferenceElement(property, props);
}
case TriPropertyType.Reference:
{
return CreateReferenceElement(property, props);
}
case TriPropertyType.Generic:
{
return CreateGenericElement(property, props);
}
case TriPropertyType.Generic:
{
return CreateGenericElement(property, props);
}
default:
{
return new TriNoDrawerElement(property);
}
}
if (isSerializedProperty)
{
return new TriBuiltInPropertyElement(property, serializedProperty, handler.Value);
}
return new TriNoDrawerElement(property);
}
private static TriElement CreateArrayElement(TriProperty property)