public T Register <T>(T system) where T : GameSystem
        {
            LogHelper.Log($"GameSystemManager: Registering System {typeof(T)}");
            SystemAdded?.Invoke(this, new GameSystemAddedEventArgs(this, system));

            system.GameSystemManager = this;
            system.IsWorking         = true;
            _gameSystems.Add(system);

            return(system);
        }
Beispiel #2
0
        private void RegisterManagers()
        {
            // Entity events
            EntityManager.Register(this);
            EntityManager.EntityAdded      += EntityManagerOnEntityAdded;
            EntityManager.EntityRemoved    += EntityManagerOnEntityRemoved;
            EntityManager.ComponentAdded   += EntityManagerOnComponentAdded;
            EntityManager.ComponentRemoved += EntityManagerOnComponentRemoved;

            // Systems events
            Systems.Register(this);
            Systems.SystemAdded   += (sender, args) => SystemAdded?.Invoke(sender, args);
            Systems.SystemStarted += (sender, args) => SystemStarted?.Invoke(sender, args);
            Systems.SystemRemoved += (sender, args) => SystemRemoved?.Invoke(sender, args);
            Systems.SystemStopped += (sender, args) => SystemStopped?.Invoke(sender, args);
        }
Beispiel #3
0
        public void RegisterSystem <T>(T system) where T : ISystem
        {
            system.SystemManager = this;
            system.IsActive      = true;

            if (system is IUpdateSystem updateSystem)
            {
                _updateSystems.Add(updateSystem);
            }
            if (system is IDrawSystem drawSystem)
            {
                _drawSystems.Add(drawSystem);
            }

            SystemAdded?.Invoke(this, new SystemAddedEventArgs(this, system));
            system.Initialize(this);
        }
Beispiel #4
0
        public void Add(ISystem system)
        {
            if (ContainsSystem(system))
            {
                throw new InvalidOperationException($"System {system.GetType().Name} already added to game manager.");
            }

            _systems.Add(system);
            _systems.Sort();

            var drawableSystem = system as IDrawableSystem;

            if (drawableSystem != null)
            {
                _drawableSystems.Add(drawableSystem);
                _drawableSystems.Sort();
            }

            system.AddToGameManager(_gameManager);

            SystemAdded?.Invoke(this, new SystemChangedEventArgs(system));
        }