Exemplo n.º 1
0
        public void Load()
        {
            this.UiTypes.Clear();

            List <Type> types = Game.EventSystem.GetTypes(typeof(UIFactoryAttribute));

            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(attribute.Type))
                {
                    Log.Debug($"已经存在同类UI Factory: {attribute.Type}");
                    throw new Exception($"已经存在同类UI Factory: {attribute.Type}");
                }
                object           o       = Activator.CreateInstance(type);
                IUIFactoryExtend factory = o as IUIFactoryExtend;
                if (factory == null)
                {
                    Log.Error($"{o.GetType().FullName} 没有继承 IUIFactory");
                    continue;
                }
                this.UiTypes.Add(attribute.Type, factory);
            }
        }
Exemplo n.º 2
0
        public IUIFactoryExtend GetUIFactory(string type)
        {
            IUIFactoryExtend uiFactory = null;

            this.UiTypes.TryGetValue(type, out uiFactory);
            return(uiFactory);
        }