diff --git a/Editor.Extras/Drawers/CustomBuiltInDrawer.cs b/Editor.Extras/Drawers/CustomBuiltInDrawer.cs new file mode 100644 index 0000000..264e02d --- /dev/null +++ b/Editor.Extras/Drawers/CustomBuiltInDrawer.cs @@ -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 + { + public override TriElement CreateElement(TriValue 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); + } + } +} \ No newline at end of file diff --git a/Editor.Extras/Drawers/CustomBuiltInDrawer.cs.meta b/Editor.Extras/Drawers/CustomBuiltInDrawer.cs.meta new file mode 100644 index 0000000..8c8dd16 --- /dev/null +++ b/Editor.Extras/Drawers/CustomBuiltInDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 01398997ba14482caf7fd7c566774973 +timeCreated: 1670393704 \ No newline at end of file diff --git a/Editor/AssemblyInfo.cs b/Editor/AssemblyInfo.cs index 7f6971e..6001719 100644 --- a/Editor/AssemblyInfo.cs +++ b/Editor/AssemblyInfo.cs @@ -1,4 +1,5 @@ using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("TriInspector.Editor.Extras")] [assembly: InternalsVisibleTo("TriInspector.Editor.Samples")] [assembly: InternalsVisibleTo("TriInspector.Editor.Integrations.Odin")] \ No newline at end of file diff --git a/Editor/Elements/TriPropertyElement.cs b/Editor/Elements/TriPropertyElement.cs index f14b3b1..369784a 100644 --- a/Editor/Elements/TriPropertyElement.cs +++ b/Editor/Elements/TriPropertyElement.cs @@ -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)