Esempio n. 1
0
        /// <summary>
        /// Adds new system to processing.
        /// </summary>
        /// <param name="system">System instance.</param>
        public EcsSystems Add(IEcsSystem system, string namedRunSystem = null)
        {
#if DEBUG
            if (system == null)
            {
                throw new Exception("System is null.");
            }
            if (_inited)
            {
                throw new Exception("Cant add system after initialization.");
            }
            if (_destroyed)
            {
                throw new Exception("Cant touch after destroy.");
            }
            if (!string.IsNullOrEmpty(namedRunSystem) && !(system is IEcsRunSystem))
            {
                throw new Exception("Cant name non-IEcsRunSystem.");
            }
#endif
            _allSystems.Add(system);
            if (system is IEcsRunSystem)
            {
                if (namedRunSystem != null)
                {
                    _namedRunSystems[namedRunSystem.GetHashCode()] = _runSystems.Count;
                }
                _runSystems.Add(new EcsSystemsRunItem()
                {
                    Active = true, System = (IEcsRunSystem)system
                });
            }
            return(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds new system to processing.
        /// </summary>
        /// <param name="system">System instance.</param>
        /// <param name="namedRunSystem">Optional name of system.</param>
        public EcsSystems Add(IEcsSystem system, string namedRunSystem = null)
        {
#if DEBUG
            if (system == null)
            {
                throw new Exception("System is null.");
            }
            if (_initialized)
            {
                throw new Exception("Cant add system after initialization.");
            }
            if (_destroyed)
            {
                throw new Exception("Cant touch after destroy.");
            }
            if (!string.IsNullOrEmpty(namedRunSystem) && !(system is IEcsRunSystem))
            {
                throw new Exception("Cant name non-IEcsRunSystem.");
            }
#endif
            _allSystems.Add(system);
            if (system is IEcsRunSystem)
            {
                if (namedRunSystem == null && system is EcsSystems ecsSystems)
                {
                    namedRunSystem = ecsSystems.Name;
                }
                if (namedRunSystem != null)
                {
#if DEBUG
                    if (_namedRunSystems.ContainsKey(namedRunSystem.GetHashCode()))
                    {
                        throw new Exception($"Cant add named system - \"{namedRunSystem}\" name already exists.");
                    }
#endif
                    _namedRunSystems[namedRunSystem.GetHashCode()] = _runSystems.Count;
                }
                _runSystems.Add(new EcsSystemsRunItem {
                    Active = true, System = (IEcsRunSystem)system
                });
            }
            return(this);
        }