/// <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); }
/// <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>()); }
/// <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>()); }
/// <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); }
/// <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); } }