示例#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);
        }
示例#2
0
        /// <summary>
        /// Get first system by type
        /// </summary>
        /// <typeparam name="TSystem"></typeparam>
        /// <returns></returns>
        public TSystem GetSystem <TSystem>() where TSystem : class, ISystemBase
        {
            if (this.world == null)
            {
                SystemGroupRegistryException.Throw();
            }

            return(this.runtimeSystem.Get <TSystem>());
        }
示例#3
0
        /// <summary>
        /// Returns true if system with TSystem type exists
        /// </summary>
        /// <typeparam name="TSystem"></typeparam>
        /// <returns></returns>
        public bool HasSystem <TSystem>() where TSystem : class, ISystemBase, new()
        {
            if (this.world == null)
            {
                SystemGroupRegistryException.Throw();
            }

            return(this.runtimeSystem.Has <TSystem>());
        }
示例#4
0
        /// <summary>
        /// Add system by type
        /// Retrieve system from pool, OnConstruct() call
        /// </summary>
        /// <typeparam name="TSystem"></typeparam>
        public bool AddSystem <TSystem>() where TSystem : class, ISystemBase, new()
        {
            if (this.world == null)
            {
                SystemGroupRegistryException.Throw();
            }

            var instance = PoolSystems.Spawn <TSystem>();

            if (this.AddSystem(instance) == false)
            {
                instance.world = null;
                PoolSystems.Recycle(ref instance);
                return(false);
            }

            return(true);
        }
示例#5
0
        /// <summary>
        /// Remove system manually
        /// Pool will not be used, OnDeconstruct() call
        /// </summary>
        /// <param name="instance"></param>
        public void RemoveSystem(ISystemBase instance)
        {
            if (this.world == null)
            {
                SystemGroupRegistryException.Throw();
            }

            if (this.runtimeSystem.Remove(instance) == true)
            {
                if (instance is ISystemFilter systemFilter)
                {
                    systemFilter.filter = Filter.Empty;
                }
                instance.world = null;
                instance.OnDeconstruct();

                this.world.UpdateGroup(this);
            }
        }