public void Load() { this.UiTypes.Clear(); Type[] types = DllHelper.GetMonoTypes(); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(UIFactoryAttribute), false); if (attrs.Length == 0) { continue; } UIFactoryAttribute attribute = attrs[0] as UIFactoryAttribute; if (UiTypes.ContainsKey((UIType)attribute.Type)) { Log.Debug($"已经存在同类UI Factory: {attribute.Type}"); throw new Exception($"已经存在同类UI Factory: {attribute.Type}"); } object o = Activator.CreateInstance(type); IUIFactory factory = o as IUIFactory; if (factory == null) { Log.Error($"{o.GetType().FullName} 没有继承 IUIFactory"); continue; } this.UiTypes.Add((UIType)attribute.Type, factory); } }
public void Load() { this.UiTypes = new Dictionary <UIType, IUIFactory>(); Assembly[] assemblies = ObjectManager.Instance.GetAssemblies(); foreach (Assembly assembly in assemblies) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(UIFactoryAttribute), false); if (attrs.Length == 0) { continue; } UIFactoryAttribute attribute = attrs[0] as UIFactoryAttribute; if (this.UiTypes.ContainsKey(attribute.Type)) { throw new GameException($"已经存在同类UI Factory: {attribute.Type}"); } IUIFactory iIuiFactory = Activator.CreateInstance(type) as IUIFactory; if (iIuiFactory == null) { throw new GameException("UI Factory没有继承IUIFactory"); } this.UiTypes.Add(attribute.Type, iIuiFactory); } } }
private void Load() { this.UiTypes = new Dictionary <int, IUIFactory>(); Type[] types = DllHelper.GetHotfixTypes(); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(UIFactoryAttribute), false); if (attrs.Length == 0) { continue; } UIFactoryAttribute attribute = attrs[0] as UIFactoryAttribute; if (this.UiTypes.ContainsKey(attribute.Type)) { throw new GameException($"已经存在同类UI Factory: {attribute.Type}"); } IUIFactory iuiFactory = new IUIFactoryMethod(type); this.UiTypes.Add(attribute.Type, iuiFactory); } }