public static void BindSave(PrefabBind data, Type prefabtype) { string path = data.Path; //若是第一次获取这个路径,则添加一个新元素 if (!_uiPrefabDic.ContainsKey(path)) { _uiPrefabDic.Add(path, new List <Type>()); } //再将这个路径的元素添加入List中 if (!_uiPrefabDic[path].Contains(prefabtype)) { _uiPrefabDic[path].Add(prefabtype); //存储的是脚本与data.Priority的大小 _sizePriority.Add(prefabtype, data.Priority); _uiPrefabDic[path].Sort(new BindPriorityComparer()); } }
public void Init() { Assembly assembly = Assembly.GetAssembly(typeof(PrefabBind)); Type[] types = assembly.GetExportedTypes(); foreach (Type type in types) { //true用来表示是否可以继承 foreach (Attribute attribute in Attribute.GetCustomAttributes(type, true)) { if (attribute is PrefabBind) { PrefabBind data = attribute as PrefabBind; //存储脚本的信息与类型 BindUtil.BindSave(data, type); } } } }