定义特性类BindPre
using System;
[AttributeUsage(AttributeTargets.Class)]//特性使用限定为类
public class BindPre : Attribute
{
public string Path { get; private set; }
public BindPre(string path)
{
Path = path;
}
}
在脚本上添加特性
using UnityEngine;
[BindPre("Prefabs/12Attribute/StartView")]
public class StartView : MonoBehaviour
{
}
绑定路径和类型的工具类
using System;
using System.Collections.Generic;
using UnityEngine;
public class BindUtil
{
private static Dictionary<string, Type> _prefabAndScriptMap = new Dictionary<string, Type>();
public static void Bind(string path, Type type)
{
if (!_prefabAndScriptMap.ContainsKey(path))
{
_prefabAndScriptMap.Add(path, type);
}
else
{