Example #1
0
        /// <summary>
        /// Add system manually
        /// Pool will not be used, OnConstruct() call
        /// </summary>
        /// <param name="instance"></param>
        public bool AddSystem(ISystemBase instance)
        {
            if (this.world == null)
            {
                SystemGroupRegistryException.Throw();
            }

            WorldUtilities.SetWorld(this.world);

            instance.world = this.world;
            if (instance is ISystemValidation instanceValidate)
            {
                if (instanceValidate.CouldBeAdded() == false)
                {
                    instance.world = null;
                    return(false);
                }
            }

            this.runtimeSystem.Add(instance);
            instance.OnConstruct();

            if (instance is ISystemFilter systemFilter)
            {
                systemFilter.filter = systemFilter.CreateFilter();
            }

            this.world.UpdateGroup(this);

            return(true);
        }
Example #2
0
        /// <summary>
        /// Add system manually
        /// Pool will not be used, OnConstruct() call
        /// </summary>
        /// <param name="instance"></param>
        public bool AddSystem(ISystemBase instance)
        {
            if (this.world == null)
            {
                SystemGroupRegistryException.Throw();
            }

            WorldUtilities.SetWorld(this.world);

            instance.world = this.world;
            if (instance is ISystemValidation instanceValidate)
            {
                if (instanceValidate.CouldBeAdded() == false)
                {
                    instance.world = null;
                    return(false);
                }
            }

            var k = this.length;

            ArrayUtils.Resize(in k, ref this.systems, resizeWithOffset: false);
            ArrayUtils.Resize(in k, ref this.statesSystems, resizeWithOffset: false);
            ++this.length;

            this.systems.arr[k]       = instance;
            this.statesSystems.arr[k] = ModuleState.AllActive;
            instance.OnConstruct();

            if (instance is ISystemFilter systemFilter)
            {
                systemFilter.filter = systemFilter.CreateFilter();
            }

            this.world.UpdateGroup(this);

            return(true);
        }