Example #1
0
 protected void Add([NotNull] IFixedUpdateSystem system)
 {
     if (system == null)
     {
         throw new ArgumentNullException(nameof(system));
     }
     GetOrCreateListAndAdd(ref _fixedUpdateSystems, system);
 }
Example #2
0
        public EventSystem()
        {
            this.types.Clear();

            List <Type> ts = ETModel.Game.Hotfix.GetHotfixTypes();

            foreach (Type type in ts)
            {
                // ILRuntime无法判断是否有Attribute
                //if (type.GetCustomAttributes(typeof (Attribute), false).Length == 0)
                //{
                //	continue;
                //}

                this.types.Add(type);
            }

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(ObjectSystemAttribute), false);

                if (attrs.Length == 0)
                {
                    continue;
                }

                object obj = Activator.CreateInstance(type);

                IAwakeSystem objectSystem = obj as IAwakeSystem;
                if (objectSystem != null)
                {
                    this.awakeSystems.Add(objectSystem.Type(), objectSystem);
                }

                IFixedUpdateSystem fixedUpdateSystem = obj as IFixedUpdateSystem;
                if (fixedUpdateSystem != null)
                {
                    this.fixedUpdateSystems.Add(fixedUpdateSystem.Type(), fixedUpdateSystem);
                }

                IUpdateSystem updateSystem = obj as IUpdateSystem;
                if (updateSystem != null)
                {
                    this.updateSystems.Add(updateSystem.Type(), updateSystem);
                }

                ILateUpdateSystem lateUpdateSystem = obj as ILateUpdateSystem;
                if (lateUpdateSystem != null)
                {
                    this.lateUpdateSystems.Add(lateUpdateSystem.Type(), lateUpdateSystem);
                }

                IStartSystem startSystem = obj as IStartSystem;
                if (startSystem != null)
                {
                    this.startSystems.Add(startSystem.Type(), startSystem);
                }

                IDestroySystem destroySystem = obj as IDestroySystem;
                if (destroySystem != null)
                {
                    this.destroySystems.Add(destroySystem.Type(), destroySystem);
                }

                ILoadSystem loadSystem = obj as ILoadSystem;
                if (loadSystem != null)
                {
                    this.loadSystems.Add(loadSystem.Type(), loadSystem);
                }

                IChangeSystem changeSystem = obj as IChangeSystem;
                if (changeSystem != null)
                {
                    this.changeSystems.Add(changeSystem.Type(), changeSystem);
                }
            }

            this.allEvents.Clear();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);

                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;
                    object         obj             = Activator.CreateInstance(type);
                    IEvent         iEvent          = obj as IEvent;
                    if (iEvent == null)
                    {
                        Log.Error($"{obj.GetType().Name} 没有继承IEvent");
                    }
                    this.RegisterEvent(aEventAttribute.Type, iEvent);

                    // hotfix的事件也要注册到mono层,hotfix可以订阅mono层的事件
                    Action <List <object> > action = list => { Handle(iEvent, list); };
                    ETModel.Game.EventSystem.RegisterEvent(aEventAttribute.Type, new EventProxy(action));
                }
            }

            this.Load();
        }
Example #3
0
        public void Add(DLLType dllType, Assembly assembly)
        {
            this.assemblies[dllType] = assembly;
            this.types.Clear();
            foreach (Assembly value in this.assemblies.Values)
            {
                foreach (Type type in value.GetTypes())
                {
                    object[] objects = type.GetCustomAttributes(typeof(BaseAttribute), false);
                    if (objects.Length == 0)
                    {
                        continue;
                    }

                    BaseAttribute baseAttribute = (BaseAttribute)objects[0];
                    this.types.Add(baseAttribute.AttributeType, type);
                }
            }

            this.awakeSystems.Clear();
            this.fixedUpdateSystems.Clear();
            this.lateUpdateSystems.Clear();
            this.updateSystems.Clear();
            this.startSystems.Clear();
            this.loadSystems.Clear();
            this.changeSystems.Clear();
            this.destroySystems.Clear();

            foreach (Type type in types[typeof(ObjectSystemAttribute)])
            {
                object[] attrs = type.GetCustomAttributes(typeof(ObjectSystemAttribute), false);

                if (attrs.Length == 0)
                {
                    continue;
                }

                object obj = Activator.CreateInstance(type);

                IAwakeSystem objectSystem = obj as IAwakeSystem;
                if (objectSystem != null)
                {
                    this.awakeSystems.Add(objectSystem.Type(), objectSystem);
                }

                IFixedUpdateSystem fixedUpdateSystem = obj as IFixedUpdateSystem;
                if (fixedUpdateSystem != null)
                {
                    this.fixedUpdateSystems.Add(fixedUpdateSystem.Type(), fixedUpdateSystem);
                }

                IUpdateSystem updateSystem = obj as IUpdateSystem;
                if (updateSystem != null)
                {
                    this.updateSystems.Add(updateSystem.Type(), updateSystem);
                }

                ILateUpdateSystem lateUpdateSystem = obj as ILateUpdateSystem;
                if (lateUpdateSystem != null)
                {
                    this.lateUpdateSystems.Add(lateUpdateSystem.Type(), lateUpdateSystem);
                }

                IStartSystem startSystem = obj as IStartSystem;
                if (startSystem != null)
                {
                    this.startSystems.Add(startSystem.Type(), startSystem);
                }

                IDestroySystem destroySystem = obj as IDestroySystem;
                if (destroySystem != null)
                {
                    this.destroySystems.Add(destroySystem.Type(), destroySystem);
                }

                ILoadSystem loadSystem = obj as ILoadSystem;
                if (loadSystem != null)
                {
                    this.loadSystems.Add(loadSystem.Type(), loadSystem);
                }

                IChangeSystem changeSystem = obj as IChangeSystem;
                if (changeSystem != null)
                {
                    this.changeSystems.Add(changeSystem.Type(), changeSystem);
                }
            }

            this.allEvents.Clear();
            foreach (Type type in types[typeof(EventAttribute)])
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);

                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;
                    object         obj             = Activator.CreateInstance(type);
                    IEvent         iEvent          = obj as IEvent;
                    if (iEvent == null)
                    {
                        Log.Error($"{obj.GetType().Name} 没有继承IEvent");
                    }
                    this.RegisterEvent(aEventAttribute.Type, iEvent);
                }
            }

            this.Load();
        }