コード例 #1
0
        /// <summary>
        /// Closes registration for new systems, initialize all registered.
        /// </summary>
        public void Initialize()
        {
#if DEBUG
            if (_inited)
            {
                throw new Exception("EcsSystems instance already initialized");
            }
            for (var i = 0; i < _runSystemsCount; i++)
            {
                DisabledInDebugSystems.Add(false);
            }
            _inited = true;
#endif
#if !LEOECS_DISABLE_INJECT
            for (var i = 0; i < _injectSystemsCount; i++)
            {
                EcsInjections.Inject(_injectSystems[i], _world, _injections);
            }
#endif
            for (var i = 0; i < _preInitSystemsCount; i++)
            {
                _preInitSystems[i].PreInitialize();
                _world.ProcessDelayedUpdates();
            }

            for (var i = 0; i < _initSystemsCount; i++)
            {
                _initSystems[i].Initialize();
                _world.ProcessDelayedUpdates();
            }
        }
コード例 #2
0
 /// <summary>
 /// Processes injections immediately.
 /// Can be used to DI before Initialize() call.
 /// </summary>
 public EcsSystems ProcessInjects()
 {
     if (!_injected)
     {
         _injected = true;
         for (var i = 0; i < _injectSystemsCount; i++)
         {
             // injection for nested EcsSystems.
             var nestedSystems = _injectSystems[i] as EcsSystems;
             if (nestedSystems != null)
             {
                 foreach (var pair in _injections)
                 {
                     nestedSystems._injections[pair.Key] = pair.Value;
                 }
             }
             EcsInjections.Inject(_injectSystems[i], _world, _injections);
         }
     }
     return(this);
 }
コード例 #3
0
ファイル: EcsSystems.cs プロジェクト: sizzles/ecs
        /// <summary>
        /// Closes registration for new systems, initialize all registered.
        /// </summary>
        public void Initialize()
        {
#if DEBUG
            if (_inited)
            {
                throw new Exception("EcsSystems instance already initialized");
            }
            for (var i = 0; i < _runSystemsCount; i++)
            {
                DisabledInDebugSystems.Add(false);
            }
            _inited = true;
#endif
#if !LEOECS_DISABLE_INJECT
            for (var i = 0; i < _injectSystemsCount; i++)
            {
                // injection for nested EcsSystems.
                var nestedSystems = _injectSystems[i] as EcsSystems;
                if (nestedSystems != null)
                {
                    foreach (var pair in _injections)
                    {
                        nestedSystems._injections[pair.Key] = pair.Value;
                    }
                }
                EcsInjections.Inject(_injectSystems[i], _world, _injections);
            }
#endif
            for (int i = 0, iMax = _preInitSystemsCount; i < iMax; i++)
            {
                _preInitSystems[i].PreInitialize();
                _world.ProcessDelayedUpdates();
            }

            for (int i = 0, iMax = _initSystemsCount; i < iMax; i++)
            {
                _initSystems[i].Initialize();
                _world.ProcessDelayedUpdates();
            }
        }
コード例 #4
0
        /// <summary>
        /// Adds new system to processing.
        /// </summary>
        /// <param name="system">System instance.</param>
        public EcsSystems Add(IEcsSystem system)
        {
            Internals.EcsHelpers.Assert(system != null, "system is null");
#if !LEOECS_DISABLE_INJECT
            EcsInjections.Inject(system, _world);
#endif
            var preInitSystem = system as IEcsPreInitSystem;
            if (preInitSystem != null)
            {
                if (_preInitSystemsCount == _preInitSystems.Length)
                {
                    Array.Resize(ref _preInitSystems, _preInitSystemsCount << 1);
                }
                _preInitSystems[_preInitSystemsCount++] = preInitSystem;
            }

            var initSystem = system as IEcsInitSystem;
            if (initSystem != null)
            {
                if (_initSystemsCount == _initSystems.Length)
                {
                    Array.Resize(ref _initSystems, _initSystemsCount << 1);
                }
                _initSystems[_initSystemsCount++] = initSystem;
            }

            var runSystem = system as IEcsRunSystem;
            if (runSystem != null)
            {
                if (_runSystemsCount == _runSystems.Length)
                {
                    Array.Resize(ref _runSystems, _runSystemsCount << 1);
                }
                _runSystems[_runSystemsCount++] = runSystem;
            }
            return(this);
        }