public Entity ReplaceCellClicked(Entitas.Entity newCell) { var componentPool = GetComponentPool(OrdersComponentIds.CellClicked); var component = (CellClickedComponent)(componentPool.Count > 0 ? componentPool.Pop() : new CellClickedComponent()); component.Cell = newCell; ReplaceComponent(OrdersComponentIds.CellClicked, component); return this; }
public Entity ReplaceChild(Entitas.Entity newParent) { var component = CreateComponent<ChildComponent>(ComponentIds.Child); component.parent = newParent; ReplaceComponent(ComponentIds.Child, component); return this; }
protected virtual IEnumerator SphereCheck() { int range = 0; while (targetEntity == null) { if (Physics.OverlapSphereNonAlloc(transform.localPosition, visibilityRange, enemyCollider, player.enemyMask) > 0) { targetEntity = enemyCollider[0].GetComponent <Entitas>(); targetEntity.deathEvent += OnEnemyDeath; } else { if (range < visibilityRange) { range += 2; //print("enemy not found 0.1s"); yield return(new WaitForSeconds(0.1f)); continue; } else { //print("enemy not found 0.5s"); yield return(new WaitForSeconds(sphereCheckDelay)); } } } //print("Enemy found."); }
public Entity AddGameBoardCache(Entitas.Entity[,] newGrid) { var componentPool = GetComponentPool(ComponentIds.GameBoardCache); var component = (GameBoardCacheComponent)(componentPool.Count > 0 ? componentPool.Pop() : new GameBoardCacheComponent()); component.grid = newGrid; return AddComponent(ComponentIds.GameBoardCache, component); }
// selection type void SingleLeftClick() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, playerMask)) { Entitas entity = hit.collider.GetComponent <Entitas>(); entity.OnSelected(); selectedEntities.Add(entity.instanceID, entity); if (entity is Building) { Building b = (Building)entity; if (b.currentState != BuildingState.Complete) { UIController.instance.commandController.Create("Incomplete Building"); } else { UIController.instance.commandController.Create(b.entityName); } } else { UIController.instance.commandController.Create(entity.entityName); } } }
public Entity AddUnit(Entitas.Entity newSquad, string newUnitType) { var componentPool = GetComponentPool(UnitsComponentIds.Unit); var component = (UnitComponent)(componentPool.Count > 0 ? componentPool.Pop() : new UnitComponent()); component.Squad = newSquad; component.UnitType = newUnitType; return AddComponent(UnitsComponentIds.Unit, component); }
public Entity ReplaceSquadSelected(Entitas.Entity newSquad) { var componentPool = GetComponentPool(OrdersComponentIds.SquadSelected); var component = (SquadSelectedComponent)(componentPool.Count > 0 ? componentPool.Pop() : new SquadSelectedComponent()); component.Squad = newSquad; ReplaceComponent(OrdersComponentIds.SquadSelected, component); return this; }
public Entity AddSquad(Entitas.Entity newCell, System.Collections.Generic.List<Entitas.Entity> newUnits) { var componentPool = GetComponentPool(UnitsComponentIds.Squad); var component = (SquadComponent)(componentPool.Count > 0 ? componentPool.Pop() : new SquadComponent()); component.Cell = newCell; component.Units = newUnits; return AddComponent(UnitsComponentIds.Squad, component); }
public Entity AddSpot(Entitas.Entity newCell, int newFloor) { var componentPool = GetComponentPool(CellsComponentIds.Spot); var component = (SpotComponent)(componentPool.Count > 0 ? componentPool.Pop() : new SpotComponent()); component.Cell = newCell; component.Floor = newFloor; return AddComponent(CellsComponentIds.Spot, component); }
public Entity ReplaceUnitClicked(Entitas.Entity newUnit) { var componentPool = GetComponentPool(OrdersComponentIds.UnitClicked); var component = (UnitClickedComponent)(componentPool.Count > 0 ? componentPool.Pop() : new UnitClickedComponent()); component.Unit = newUnit; ReplaceComponent(OrdersComponentIds.UnitClicked, component); return this; }
IEnumerator SphereCheck() { int range = 1; while (enemy == null) { if (Physics.OverlapSphereNonAlloc(transform.position, range, enemyCollider, player.enemyMask) > 0) { enemy = enemyCollider[0].GetComponent <Entitas>(); break; } else { if (range < visibilityRange) { range += 2; print("enemy not found 0.1s"); yield return(new WaitForSeconds(0.1f)); continue; } else { print("enemy not found 0.5s"); yield return(new WaitForSeconds(0.5f)); } } } print("enemy found"); }
public Entity ReplaceFollowTarget(Entitas.Entity newTarget) { var component = CreateComponent<FollowTargetComponent>(ComponentIds.FollowTarget); component.target = newTarget; ReplaceComponent(ComponentIds.FollowTarget, component); return this; }
void SendAttack(Entitas target) { if (attackEvent != null) { attackEvent(target); } }
public Entity AddRequest(Entitas.Entity newStart, Entitas.Entity newTarget) { var componentPool = GetComponentPool(ComponentIds.Request); var component = (RequestComponent)(componentPool.Count > 0 ? componentPool.Pop() : new RequestComponent()); component.start = newStart; component.target = newTarget; return AddComponent(ComponentIds.Request, component); }
public Entity AddAI(Entitas.Entity newTargetEntity, float newDeadZoneY, float newVelocityY) { var component = CreateComponent<RMC.EntitasPong.Entitas.Components.AIComponent>(ComponentIds.AI); component.targetEntity = newTargetEntity; component.deadZoneY = newDeadZoneY; component.velocityY = newVelocityY; return AddComponent(ComponentIds.AI, component); }
public Entity AddEntitas(Entitas.Systems newPausableUpdateSystems, Entitas.Systems newUnpausableUpdateSystems, Entitas.Systems newPausableFixedUpdateSystems) { var component = CreateComponent<RMC.Common.Entitas.Components.Entitas.EntitasComponent>(ComponentIds.Entitas); component.pausableUpdateSystems = newPausableUpdateSystems; component.unpausableUpdateSystems = newUnpausableUpdateSystems; component.pausableFixedUpdateSystems = newPausableFixedUpdateSystems; return AddComponent(ComponentIds.Entitas, component); }
public Entity AddMoveOrder(Entitas.Entity newSquad, Entitas.Entity newCell, bool newInstant) { var componentPool = GetComponentPool(OrdersComponentIds.MoveOrder); var component = (MoveOrderComponent)(componentPool.Count > 0 ? componentPool.Pop() : new MoveOrderComponent()); component.Squad = newSquad; component.Cell = newCell; component.Instant = newInstant; return AddComponent(OrdersComponentIds.MoveOrder, component); }
public Entity AddLaser(float newHeight, UnityEngine.Vector2 newDirection, Entitas.Entity newSource) { var component = CreateComponent<LaserComponent>(ComponentIds.Laser); component.height = newHeight; component.direction = newDirection; component.source = newSource; return AddComponent(ComponentIds.Laser, component); }
public Entity AddLaser(float newHeight, UnityEngine.Vector2 newDirection, Entitas.Entity newSource) { var component = _laserComponentPool.Count > 0 ? _laserComponentPool.Pop() : new LaserComponent(); component.height = newHeight; component.direction = newDirection; component.source = newSource; return AddComponent(ComponentIds.Laser, component); }
public Entity SetGameBoardCache(Entitas.Entity[,] newGrid) { if (hasGameBoardCache) { throw new EntitasException("Could not set gameBoardCache!\n" + this + " already has an entity with GameBoardCacheComponent!", "You should check if the pool already has a gameBoardCacheEntity before setting it or use pool.ReplaceGameBoardCache()."); } var entity = CreateEntity(); entity.AddGameBoardCache(newGrid); return entity; }
public Entity AddNode(Entitas.Entity newParent, float newFcost, float newGcost, float newHcost) { var componentPool = GetComponentPool(ComponentIds.Node); var component = (NodeComponent)(componentPool.Count > 0 ? componentPool.Pop() : new NodeComponent()); component.parent = newParent; component.fcost = newFcost; component.gcost = newGcost; component.hcost = newHcost; return AddComponent(ComponentIds.Node, component); }
public Entity ReplaceGameBoardCache(Entitas.Entity[,] newGrid) { var previousComponent = hasGameBoardCache ? gameBoardCache : null; var component = _gameBoardCacheComponentPool.Count > 0 ? _gameBoardCacheComponentPool.Pop() : new GameBoardCacheComponent(); component.grid = newGrid; ReplaceComponent(ComponentIds.GameBoardCache, component); if (previousComponent != null) { _gameBoardCacheComponentPool.Push(previousComponent); } return this; }
public Entity ReplaceShield(Entitas.Entity newOwner) { var previousComponent = hasShield ? shield : null; var component = _shieldComponentPool.Count > 0 ? _shieldComponentPool.Pop() : new ShieldComponent(); component.owner = newOwner; ReplaceComponent(ComponentIds.Shield, component); if (previousComponent != null) { _shieldComponentPool.Push(previousComponent); } return this; }
public Entity ReplaceGameBoardCache(Entitas.Entity[,] newGrid) { var entity = gameBoardCacheEntity; if (entity == null) { entity = SetGameBoardCache(newGrid); } else { entity.ReplaceGameBoardCache(newGrid); } return entity; }
public Entity ReplaceFollowTarget(Entitas.Entity newTarget) { var previousComponent = hasFollowTarget ? followTarget : null; var component = _followTargetComponentPool.Count > 0 ? _followTargetComponentPool.Pop() : new FollowTargetComponent(); component.target = newTarget; ReplaceComponent(ComponentIds.FollowTarget, component); if (previousComponent != null) { _followTargetComponentPool.Push(previousComponent); } return this; }
public Entity AddLaserSpawner(float newVelocity, float newHeight, float newAngle, UnityEngine.Vector2 newDirection, int newCollisionType, Entitas.Entity newLaser) { var component = _laserSpawnerComponentPool.Count > 0 ? _laserSpawnerComponentPool.Pop() : new LaserSpawnerComponent(); component.velocity = newVelocity; component.height = newHeight; component.angle = newAngle; component.direction = newDirection; component.collisionType = newCollisionType; component.laser = newLaser; return AddComponent(ComponentIds.LaserSpawner, component); }
public Entity ReplaceChild(Entitas.Entity newParent) { var previousComponent = hasChild ? child : null; var component = _childComponentPool.Count > 0 ? _childComponentPool.Pop() : new ChildComponent(); component.parent = newParent; ReplaceComponent(ComponentIds.Child, component); if (previousComponent != null) { _childComponentPool.Push(previousComponent); } return this; }
void Sonar() { if (Time.time > lastSonarCheck) { lastSonarCheck = Time.time + sonarCheckTime; if (Physics.OverlapSphereNonAlloc(transform.localPosition, visibilityRange, enemyCollider, enemyMask) > 0) { targetEntity = enemyCollider[0].GetComponent <Entitas>(); targetEntity.deathEvent += OnEnemyDeath; } } }
public Entity ReplaceGameBoardCache(Entitas.Entity[,] newGrid) { GameBoardCacheComponent component; if (hasGameBoardCache) { WillRemoveComponent(ComponentIds.GameBoardCache); component = gameBoardCache; } else { component = new GameBoardCacheComponent(); } component.grid = newGrid; return ReplaceComponent(ComponentIds.GameBoardCache, component); }
void when_created() { it["has values"] = () => { var componentNames = new [] { "Health", "Position", "View" }; const string poolName = "My Pool"; var data = new PoolMetaData(poolName, componentNames); data.poolName.should_be(poolName); data.componentNames.should_be_same(componentNames); }; }
public Entity ReplaceLaser(float newHeight, UnityEngine.Vector2 newDirection, Entitas.Entity newSource) { var previousComponent = hasLaser ? laser : null; var component = _laserComponentPool.Count > 0 ? _laserComponentPool.Pop() : new LaserComponent(); component.height = newHeight; component.direction = newDirection; component.source = newSource; ReplaceComponent(ComponentIds.Laser, component); if (previousComponent != null) { _laserComponentPool.Push(previousComponent); } return this; }
void when_created() { it["has values"] = () => { var componentNames = new [] { "Health", "Position", "View" }; var componentTypes = new [] { typeof(ComponentA), typeof(ComponentB), typeof(ComponentC) }; const string contextName = "My Context"; var data = new ContextInfo(contextName, componentNames, componentTypes); data.name.should_be(contextName); data.componentNames.should_be_same(componentNames); data.componentTypes.should_be_same(componentTypes); }; }
public Entity ReplaceLaserSpawner(float newVelocity, float newHeight, float newAngle, UnityEngine.Vector2 newDirection, int newCollisionType, Entitas.Entity newLaser) { var previousComponent = hasLaserSpawner ? laserSpawner : null; var component = _laserSpawnerComponentPool.Count > 0 ? _laserSpawnerComponentPool.Pop() : new LaserSpawnerComponent(); component.velocity = newVelocity; component.height = newHeight; component.angle = newAngle; component.direction = newDirection; component.collisionType = newCollisionType; component.laser = newLaser; ReplaceComponent(ComponentIds.LaserSpawner, component); if (previousComponent != null) { _laserSpawnerComponentPool.Push(previousComponent); } return this; }
void Start() { Entitas entity = Selection.instance.selectedEntities.Values.First(); if (entity is Building) { Tname.text = entity.entityName; b = (Building)entity; b.OnBuildComplete += OnBuildComplete; b.deathEvent += OnBuildingDestroyed; } else { print("Not syncronize. Destroy " + name); Destroy(gameObject); } }
void Start() { for (int i = 0; i < buildingArray.Length; i++) { Entitas e = buildingArray[i].GetComponent <Entitas>(); buildingList.Add(e.entityName, buildingArray[i]); } for (int i = 0; i < ghostBuildingArray.Length; i++) { GhostBuilding gb = ghostBuildingArray[i].GetComponent <GhostBuilding>(); ghostBuildingList.Add(gb.Bname, ghostBuildingArray[i]); } buildingArray = null; ghostBuildingArray = null; }
void SingleRightClick() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { if (hit.collider.gameObject.layer == 8) { SendMove(hit.point); } else if (1 << hit.collider.gameObject.layer == player.playerMask) { Entitas entity = hit.collider.gameObject.GetComponent <Entitas>(); if (entity.entityType == EntitasType.Building) { print("go to building"); Building building = (Building)entity; if (building.currentState != BuildingState.Complete && building.builder == null) { if (onRightSelectFriendlyBuilding != null) { onRightSelectFriendlyBuilding(building); } } } else if (entity.entityType == EntitasType.Unit) { print("go to that unit"); } } else if (1 << hit.collider.gameObject.layer == player.enemyMask) { Entitas e = hit.collider.gameObject.GetComponent <Entitas>(); SendAttack(e); } } }
void Start() { Entitas entity = Selection.instance.selectedEntities.Values.First(); if (entity is ResourceField) { //print("is resources field"); Thealth.text = entity.healthPoint.ToString() + '/' + entity.maxHealth.ToString(); Building b = (Building)entity; Tlevel.text = "Lv " + b.level.ToString(); ResourceField rf = (ResourceField)entity; Tproduction.text = '+' + rf.production.ToString(); } else if (entity is Villager) { //print("is villager"); Thealth.text = entity.healthPoint.ToString() + '/' + entity.maxHealth.ToString(); } else if (entity is Unit) { //print("is villager"); Thealth.text = entity.healthPoint.ToString() + '/' + entity.maxHealth.ToString(); } }
public void OnEnemyDeath() { targetEntity.deathEvent -= OnEnemyDeath; targetEntity = null; }
public void AssignBuilder(Entitas entity) { builder = entity; isBuilderExist = true; }
public Entity SetGameBoardCache(Entitas.Entity[,] newGrid) { if (hasGameBoardCache) { throw new SingleEntityException(Matcher.GameBoardCache); } var entity = CreateEntity(); entity.AddGameBoardCache(newGrid); return entity; }
public void Attack(Entitas target) { isAggresive = false; this.targetEntity = target; AttackTransition(); }
void when_created() { Pool pool = null; ReactiveSystem reactiveSystem = null; ReactiveSubSystemSpy subSystem = null; MultiReactiveSubSystemSpy multiSubSystem = null; before = () => { pool = new Pool(CID.NumComponents); }; context["OnEntityAdded"] = () => { before = () => { subSystem = getSubSystemSypWithOnEntityAdded(); reactiveSystem = new ReactiveSystem(pool, subSystem); }; it["does not execute its subsystem when no entities were collected"] = () => { reactiveSystem.Execute(); subSystem.didExecute.should_be(0); }; it["executes when trigger matches"] = () => { var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); reactiveSystem.Execute(); subSystem.didExecute.should_be(1); subSystem.entities.Length.should_be(1); subSystem.entities.should_contain(e); }; it["executes only once when trigger matches"] = () => { var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); reactiveSystem.Execute(); reactiveSystem.Execute(); subSystem.didExecute.should_be(1); subSystem.entities.Length.should_be(1); subSystem.entities.should_contain(e); }; it["collects changed entities in execute"] = () => { subSystem.replaceComponentAOnExecute = true; var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); reactiveSystem.Execute(); reactiveSystem.Execute(); subSystem.didExecute.should_be(2); }; it["doesn't execute when trigger doesn't match"] = () => { var e = pool.CreateEntity(); e.AddComponentA(); reactiveSystem.Execute(); subSystem.didExecute.should_be(0); subSystem.entities.should_be_null(); }; it["deactivates and will not be triggered"] = () => { reactiveSystem.Deactivate(); var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); reactiveSystem.Execute(); subSystem.didExecute.should_be(0); subSystem.entities.should_be_null(); }; it["activates and will be triggered again"] = () => { reactiveSystem.Deactivate(); reactiveSystem.Activate(); var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); reactiveSystem.Execute(); subSystem.didExecute.should_be(1); subSystem.entities.Length.should_be(1); subSystem.entities.should_contain(e); }; it["clears"] = () => { var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); reactiveSystem.Clear(); reactiveSystem.Execute(); subSystem.didExecute.should_be(0); }; it["can ToString"] = () => { reactiveSystem.ToString().should_be("ReactiveSystem(ReactiveSubSystemSpy)"); }; }; context["OnEntityRemoved"] = () => { before = () => { subSystem = getSubSystemSypWithOnEntityRemoved(); reactiveSystem = new ReactiveSystem(pool, subSystem); }; it["executes when trigger matches"] = () => { var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); e.RemoveComponentA(); reactiveSystem.Execute(); subSystem.didExecute.should_be(1); subSystem.entities.Length.should_be(1); subSystem.entities.should_contain(e); }; it["executes only once when trigger matches"] = () => { var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); e.RemoveComponentA(); reactiveSystem.Execute(); reactiveSystem.Execute(); subSystem.didExecute.should_be(1); subSystem.entities.Length.should_be(1); subSystem.entities.should_contain(e); }; it["doesn't execute when trigger doesn't match"] = () => { var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); e.AddComponentC(); e.RemoveComponentC(); reactiveSystem.Execute(); subSystem.didExecute.should_be(0); subSystem.entities.should_be_null(); }; it["retains entities until execute completed"] = () => { var didExecute = 0; Entity providedEntity = null; subSystem.executeAction = entities => { didExecute += 1; providedEntity = entities[0]; providedEntity.retainCount.should_be(1); }; var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); pool.DestroyEntity(e); reactiveSystem.Execute(); didExecute.should_be(1); providedEntity.retainCount.should_be(0); }; }; context["OnEntityAddedOrRemoved"] = () => { it["executes when added"] = () => { subSystem = getSubSystemSypWithOnEntityAddedOrRemoved(); reactiveSystem = new ReactiveSystem(pool, subSystem); var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); reactiveSystem.Execute(); subSystem.didExecute.should_be(1); subSystem.entities.Length.should_be(1); subSystem.entities.should_contain(e); }; it["executes when removed"] = () => { var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); subSystem = getSubSystemSypWithOnEntityAddedOrRemoved(); reactiveSystem = new ReactiveSystem(pool, subSystem); e.RemoveComponentA(); reactiveSystem.Execute(); subSystem.didExecute.should_be(1); subSystem.entities.Length.should_be(1); subSystem.entities.should_contain(e); }; it["collects matching entities created or modified in the subsystem"] = () => { var sys = new EntityEmittingSubSystem(pool); reactiveSystem = new ReactiveSystem(pool, sys); var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); reactiveSystem.Execute(); sys.entities.Length.should_be(1); sys.didExecute.should_be(1); reactiveSystem.Execute(); sys.entities.Length.should_be(1); sys.didExecute.should_be(2); }; }; context["MultiReactiveSystem"] = () => { before = () => { var triggers = new [] { Matcher.AllOf(new [] { CID.ComponentA }).OnEntityAdded(), Matcher.AllOf(new [] { CID.ComponentB }).OnEntityRemoved() }; multiSubSystem = new MultiReactiveSubSystemSpy(triggers); reactiveSystem = new ReactiveSystem(pool, multiSubSystem); }; it["executes when a triggering matcher matches"] = () => { var eA = pool.CreateEntity(); eA.AddComponentA(); var eB = pool.CreateEntity(); eB.AddComponentB(); reactiveSystem.Execute(); multiSubSystem.didExecute.should_be(1); multiSubSystem.entities.Length.should_be(1); multiSubSystem.entities.should_contain(eA); eB.RemoveComponentB(); reactiveSystem.Execute(); multiSubSystem.didExecute.should_be(2); multiSubSystem.entities.Length.should_be(1); multiSubSystem.entities.should_contain(eB); }; }; context["ensure components matcher"] = () => { context["single reactive system"] = () => { ReactiveEnsureSubSystemSpy ensureSubSystem = null; Entity eAB = null; Entity eABC = null; before = () => { ensureSubSystem = new ReactiveEnsureSubSystemSpy(_matcherAB, GroupEventType.OnEntityAdded, Matcher.AllOf(new[] { CID.ComponentA, CID.ComponentB, CID.ComponentC })); reactiveSystem = new ReactiveSystem(pool, ensureSubSystem); eAB = pool.CreateEntity(); eAB.AddComponentA(); eAB.AddComponentB(); eABC = pool.CreateEntity(); eABC.AddComponentA(); eABC.AddComponentB(); eABC.AddComponentC(); }; it["only passes in entities matching required matcher"] = () => { reactiveSystem.Execute(); ensureSubSystem.didExecute.should_be(1); ensureSubSystem.entities.Length.should_be(1); ensureSubSystem.entities.should_contain(eABC); }; it["retains included entities until execute completed"] = () => { eABC.retainCount.should_be(3); // retained by pool, group and group observer var didExecute = 0; ensureSubSystem.executeAction = entities => { didExecute += 1; eABC.retainCount.should_be(3); }; reactiveSystem.Execute(); didExecute.should_be(1); eABC.retainCount.should_be(2); // retained by pool and group }; it["doesn't retain not included entities until execute completed"] = () => { eAB.retainCount.should_be(3); // retained by pool, group and group observer var didExecute = 0; ensureSubSystem.executeAction = entity => { didExecute += 1; eAB.retainCount.should_be(2); }; reactiveSystem.Execute(); didExecute.should_be(1); eABC.retainCount.should_be(2); // retained by pool and group eAB.retainCount.should_be(2); // retained by pool and group }; }; it["only passes in entities matching required matcher (multi reactive)"] = () => { var triggers = new [] { Matcher.AllOf(new [] { CID.ComponentA }).OnEntityAdded(), Matcher.AllOf(new [] { CID.ComponentB }).OnEntityRemoved() }; var ensure = Matcher.AllOf(new [] { CID.ComponentA, CID.ComponentB, CID.ComponentC }); var ensureSubSystem = new MultiReactiveEnsureSubSystemSpy(triggers, ensure); reactiveSystem = new ReactiveSystem(pool, ensureSubSystem); var eAB = pool.CreateEntity(); eAB.AddComponentA(); eAB.AddComponentB(); var eABC = pool.CreateEntity(); eABC.AddComponentA(); eABC.AddComponentB(); eABC.AddComponentC(); reactiveSystem.Execute(); ensureSubSystem.didExecute.should_be(1); ensureSubSystem.entities.Length.should_be(1); ensureSubSystem.entities.should_contain(eABC); }; it["doesn't call execute when no entities left after filtering"] = () => { var ensureSubSystem = new ReactiveEnsureSubSystemSpy( _matcherAB, GroupEventType.OnEntityAdded, Matcher.AllOf(new [] { CID.ComponentA, CID.ComponentB, CID.ComponentC, CID.ComponentD }) ); reactiveSystem = new ReactiveSystem(pool, ensureSubSystem); var eAB = pool.CreateEntity(); eAB.AddComponentA(); eAB.AddComponentB(); var eABC = pool.CreateEntity(); eABC.AddComponentA(); eABC.AddComponentB(); eABC.AddComponentC(); reactiveSystem.Execute(); ensureSubSystem.didExecute.should_be(0); }; }; context["exlude components"] = () => { context["single reactive system"] = () => { ReactiveExcludeSubSystemSpy excludeSubSystem = null; Entity eAB = null; Entity eABC = null; before = () => { excludeSubSystem = new ReactiveExcludeSubSystemSpy(_matcherAB, GroupEventType.OnEntityAdded, Matcher.AllOf(new[] { CID.ComponentC }) ); reactiveSystem = new ReactiveSystem(pool, excludeSubSystem); eAB = pool.CreateEntity(); eAB.AddComponentA(); eAB.AddComponentB(); eABC = pool.CreateEntity(); eABC.AddComponentA(); eABC.AddComponentB(); eABC.AddComponentC(); }; it["only passes in entities not matching matcher"] = () => { reactiveSystem.Execute(); excludeSubSystem.didExecute.should_be(1); excludeSubSystem.entities.Length.should_be(1); excludeSubSystem.entities.should_contain(eAB); }; it["retains included entities until execute completed"] = () => { var didExecute = 0; excludeSubSystem.executeAction = entities => { didExecute += 1; eAB.retainCount.should_be(3); }; reactiveSystem.Execute(); didExecute.should_be(1); }; it["doesn't retain not included entities until execute completed"] = () => { var didExecute = 0; excludeSubSystem.executeAction = entities => { didExecute += 1; eABC.retainCount.should_be(2); }; reactiveSystem.Execute(); didExecute.should_be(1); }; }; it["only passes in entities not matching required matcher (multi reactive)"] = () => { var triggers = new [] { Matcher.AllOf(new [] { CID.ComponentA }).OnEntityAdded(), Matcher.AllOf(new [] { CID.ComponentB }).OnEntityRemoved() }; var exclude = Matcher.AllOf(new [] { CID.ComponentC }); var excludeSubSystem = new MultiReactiveExcludeSubSystemSpy(triggers, exclude); reactiveSystem = new ReactiveSystem(pool, excludeSubSystem); var eAB = pool.CreateEntity(); eAB.AddComponentA(); eAB.AddComponentB(); var eABC = pool.CreateEntity(); eABC.AddComponentA(); eABC.AddComponentB(); eABC.AddComponentC(); reactiveSystem.Execute(); excludeSubSystem.didExecute.should_be(1); excludeSubSystem.entities.Length.should_be(1); excludeSubSystem.entities.should_contain(eAB); }; }; context["ensure / exlude components mix"] = () => { ReactiveEnsureExcludeSubSystemSpy ensureExcludeSystem = null; Entity eAB = null; Entity eAC = null; Entity eABC = null; before = () => { ensureExcludeSystem = new ReactiveEnsureExcludeSubSystemSpy(_matcherAB, GroupEventType.OnEntityAdded, Matcher.AllOf(new[] { CID.ComponentA, CID.ComponentB }), Matcher.AllOf(new[] { CID.ComponentC })); reactiveSystem = new ReactiveSystem(pool, ensureExcludeSystem); eAB = pool.CreateEntity(); eAB.AddComponentA(); eAB.AddComponentB(); eAC = pool.CreateEntity(); eAC.AddComponentA(); eAC.AddComponentC(); eABC = pool.CreateEntity(); eABC.AddComponentA(); eABC.AddComponentB(); eABC.AddComponentC(); }; it["only passes in entities"] = () => { reactiveSystem.Execute(); ensureExcludeSystem.didExecute.should_be(1); ensureExcludeSystem.entities.Length.should_be(1); ensureExcludeSystem.entities.should_contain(eAB); }; it["retains included entities until execute completed"] = () => { var didExecute = 0; ensureExcludeSystem.executeAction = entities => { didExecute += 1; eAB.retainCount.should_be(3); }; reactiveSystem.Execute(); didExecute.should_be(1); }; it["doesn't retain not included entities until execute completed"] = () => { var didExecute = 0; ensureExcludeSystem.executeAction = entities => { didExecute += 1; eAC.retainCount.should_be(1); eABC.retainCount.should_be(2); }; reactiveSystem.Execute(); didExecute.should_be(1); }; }; context["IClearReactiveSystem"] = () => { ClearReactiveSubSystemSpy clearSubSystem = null; before = () => { clearSubSystem = getClearSubSystemSypWithOnEntityAdded(); reactiveSystem = new ReactiveSystem(pool, clearSubSystem); }; it["clears reactive system after execute when implementing IClearReactiveSystem"] = () => { clearSubSystem.replaceComponentAOnExecute = true; var e = pool.CreateEntity(); e.AddComponentA(); e.AddComponentB(); reactiveSystem.Execute(); reactiveSystem.Execute(); clearSubSystem.didExecute.should_be(1); }; }; }
public void Attack(Entitas target) { designatedDestination = Vector3.zero; this.targetEntity = target; AttackTransition(); }
// unit selection void AddWithinBounds() { bound = GetViewportBounds(Camera.main, positionPressed, positionReleased); // foreach(ISelectable entity in visibleEntities.Values) // { // if(IsWithinBounds(Camera.main, bound, entity.ISelectTransform.localPosition)) // { // if(!selectableEntities.Contains(entity)) // { // selectableEntities.Add(entity); // entity.OnSelected(); // } // } // } // first phase - select all foreach (KeyValuePair <int, Entitas> entitas in OnScreenEntities) { if (IsWithinBounds(Camera.main, bound, entitas.Value.transform.localPosition)) { if (!selectedEntities.ContainsKey(entitas.Key)) { selectedEntities.Add(entitas.Key, entitas.Value); //entitas.Value.OnSelected(); } } } // second phase - filtering if (selectedEntities.Count == 0) { return; } else if (selectedEntities.Count == 1) { Entitas entity = selectedEntities.Values.First(); entity.OnSelected(); if (entity is Building) { Building b = (Building)entity; if (b.currentState != BuildingState.Complete) { UIController.instance.commandController.Create("Incomplete Building"); } else { UIController.instance.commandController.Create(b.entityName); } } else { UIController.instance.commandController.Create(entity.entityName); } } else { // check if any building mixed with units List <int> toRemove = selectedEntities.Where(pair => pair.Value.entityType == EntitasType.Building).Select(pair => pair.Key).ToList(); foreach (int i in toRemove) { selectedEntities.Remove(i); } foreach (KeyValuePair <int, Entitas> pair in selectedEntities) { pair.Value.OnSelected(); } if (selectedEntities.Count == 1) { UIController.instance.commandController.Create(selectedEntities.Values.First().entityName); } else { UIController.instance.commandController.Create("Generic"); } } }
void ClearTarget() { targetEntity.deathEvent -= OnEnemyDeath; targetEntity = null; }
public void Attack(Entitas target) { this.targetEntity = target; AttackTransition(); }
public void DeassignBuilder() { builder = null; isBuilderExist = false; }