在其他CustomPropertyDrawer中获取CustomPropertyDrawer进行自定义绘制
然后写了个下面的Helper类,需要配合Friend
使用,如果创建Unity Friend
可以看这里UnityToolchainsTrick/Example_49_Friend
,当然也可以反射.
//Create: Icarus
//ヾ(•ω•`)o
//2022-03-18 11:13
//Unity.InternalAPIEngineBridge.024
using System;
using System.Linq;
using System.Reflection;
using UnityEditor;
namespace CabinIcarus.EditorFrame.UnityBind
{
public static class PropertyDrawerHelper
{
public static PropertyDrawer CreatePropertyDrawer(FieldInfo fieldInfo)
{
var types = TypeCache.GetTypesWithAttribute<CustomPropertyDrawer>();
var drawType = types.FirstOrDefault(x =>
{
var attr = x.GetCustomAttributes<CustomPropertyDrawer>();
foreach (var drawer in attr)
{
if (drawer.m_Type == fieldInfo.FieldType || (drawer.m_UseForChildren && drawer.m_Type.IsAssignableFrom(fieldInfo.FieldType)))
{
return true;
}
}
return false;
});
if (drawType != null)
{
var ins = (PropertyDrawer) Activator.CreateInstance(drawType);
ins.m_FieldInfo = fieldInfo;
return ins;
}
return null;
}
}
}