Attribute代码
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public class ResourceTypeAttribute : Attribute
{
public ResourceTypeAttribute(Type type)
{
ResourceType = type;
}
public Type ResourceType;
}
Inspector代码
var attrs = fieldInfo.GetCustomAttributes(typeof(ResourceTypeAttribute), false);
Type allowedObjType = typeof(Object);
foreach (var attr in attrs)
{
var att = (attr as ResourceTypeAttribute);
if (att != null)
{
allowedObjType = (attr as ResourceTypeAttribute).ResourceType;
break;
}
}
assetObj = EditorGUI.ObjectField(_, _, _, allowedObjType, _);