public void CreateSystem(ECSSystem system)
        {
            m_entityManager.OnEntityCreated           += system.OnEntityCreated;
            m_entityManager.OnEntityDestroyedPre      += system.OnEntityDestroyedPre;
            m_entityManager.OnEntityDestroyedPost     += system.OnEntityDestroyedPost;
            m_componentManager.OnComponentAdded       += system.OnComponentAdded;
            m_componentManager.OnComponentRemovedPre  += system.OnComponentRemovedPre;
            m_componentManager.OnComponentRemovedPost += system.OnComponentRemovedPost;

            m_systems.Set(SafeGetSystemID(system.GetType()), system);
            system.Provide(m_queryManager, m_entityManager);
            SortSystems();
        }
        private void SortSystems()
        {
            m_sortedSystems = new List <ECSSystem>();

            Bag <ECSSystem> bag = m_systems.Clone();

            bag.ResizeToFit();

            List <ECSSystem> systems         = new List <ECSSystem>(bag.GetAll());
            List <ECSSystem> disabledSystems = new List <ECSSystem>();

            for (int i = systems.Count - 1; i >= 0; i--)
            {
                if (systems[i].IsEnabled() == false)
                {
                    disabledSystems.Add(systems[i]);
                    systems.RemoveAt(i);
                }
            }

            int       highestPriority       = int.MinValue;
            ECSSystem highestPriotitySystem = null;

            while (systems.Count > 0)
            {
                highestPriority       = int.MinValue;
                highestPriotitySystem = null;

                foreach (ECSSystem system in systems)
                {
                    if (system.UpdatePriority > highestPriority)
                    {
                        highestPriority       = system.UpdatePriority;
                        highestPriotitySystem = system;
                    }
                }

                systems.Remove(highestPriotitySystem);
                m_sortedSystems.Add(highestPriotitySystem);
            }

            foreach (ECSSystem disabledSystem in disabledSystems)
            {
                m_sortedSystems.Add(disabledSystem);
            }

            for (int i = 0; i < m_sortedSystems.Count; i++)
            {
                ECSDebug.Log(i + " - " + m_sortedSystems[i]);
            }
        }
        public void RemoveSystem <T>() where T : ECSSystem
        {
            int       systemID = GetSystemID(typeof(T));
            ECSSystem system   = m_systems.Get(systemID);

            m_entityManager.OnEntityCreated           -= system.OnEntityCreated;
            m_entityManager.OnEntityDestroyedPre      -= system.OnEntityDestroyedPre;
            m_entityManager.OnEntityDestroyedPost     -= system.OnEntityDestroyedPost;
            m_componentManager.OnComponentAdded       -= system.OnComponentAdded;
            m_componentManager.OnComponentRemovedPre  -= system.OnComponentRemovedPre;
            m_componentManager.OnComponentRemovedPost -= system.OnComponentRemovedPost;
            m_systems.Set(systemID, null);
            SortSystems();
        }