mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 00:08:51 -05:00
Move unity property drawer logic to CustombBuiltinDrawer
This commit is contained in:
parent
5b7697b59f
commit
adb64bd3f8
34
Editor.Extras/Drawers/CustomBuiltInDrawer.cs
Normal file
34
Editor.Extras/Drawers/CustomBuiltInDrawer.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
Editor.Extras/Drawers/CustomBuiltInDrawer.cs.meta
Normal file
3
Editor.Extras/Drawers/CustomBuiltInDrawer.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 01398997ba14482caf7fd7c566774973
|
||||||
|
timeCreated: 1670393704
|
@ -1,4 +1,5 @@
|
|||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
[assembly: InternalsVisibleTo("TriInspector.Editor.Extras")]
|
||||||
[assembly: InternalsVisibleTo("TriInspector.Editor.Samples")]
|
[assembly: InternalsVisibleTo("TriInspector.Editor.Samples")]
|
||||||
[assembly: InternalsVisibleTo("TriInspector.Editor.Integrations.Odin")]
|
[assembly: InternalsVisibleTo("TriInspector.Editor.Integrations.Odin")]
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using TriInspector.Utilities;
|
|
||||||
using TriInspectorUnityInternalBridge;
|
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -70,44 +68,28 @@ namespace TriInspector.Elements
|
|||||||
|
|
||||||
private static TriElement CreateElement(TriProperty property, Props props)
|
private static TriElement CreateElement(TriProperty property, Props props)
|
||||||
{
|
{
|
||||||
var isSerializedProperty = property.TryGetSerializedProperty(out var serializedProperty);
|
switch (property.PropertyType)
|
||||||
|
|
||||||
var handler = isSerializedProperty
|
|
||||||
? ScriptAttributeUtilityProxy.GetHandler(serializedProperty)
|
|
||||||
: default(PropertyHandlerProxy?);
|
|
||||||
|
|
||||||
var drawWithUnity = handler.HasValue && handler.Value.hasPropertyDrawer ||
|
|
||||||
handler.HasValue && TriUnityInspectorUtilities.MustDrawWithUnity(property);
|
|
||||||
|
|
||||||
if (!drawWithUnity)
|
|
||||||
{
|
{
|
||||||
var propertyType = property.PropertyType;
|
case TriPropertyType.Array:
|
||||||
|
|
||||||
switch (propertyType)
|
|
||||||
{
|
{
|
||||||
case TriPropertyType.Array:
|
return CreateArrayElement(property);
|
||||||
{
|
}
|
||||||
return CreateArrayElement(property);
|
|
||||||
}
|
|
||||||
|
|
||||||
case TriPropertyType.Reference:
|
case TriPropertyType.Reference:
|
||||||
{
|
{
|
||||||
return CreateReferenceElement(property, props);
|
return CreateReferenceElement(property, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
case TriPropertyType.Generic:
|
case TriPropertyType.Generic:
|
||||||
{
|
{
|
||||||
return CreateGenericElement(property, props);
|
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)
|
private static TriElement CreateArrayElement(TriProperty property)
|
||||||
|
Loading…
Reference in New Issue
Block a user