public void Execute(int index) { int cellHash = OverlappingCells[index]; if (InstigatorMap.TryGetFirstValue(cellHash, out FindAttackTargetDataTuple currentInstigatorTuple, out NativeMultiHashMapIterator <int> instigatorIterator) == false) { return; } do { if (TargetMap.TryGetFirstValue(cellHash, out FindAttackTargetDataTuple currentTargetTuple, out NativeMultiHashMapIterator <int> targetIterator) == false) { return; } do { if (CheckInRange(currentTargetTuple.Position, currentInstigatorTuple.Position, currentInstigatorTuple.RangeSqr)) { var attackTargetComponent = new AttackTargetComponent { Target = currentTargetTuple.Entity }; CommandBuffer.AddComponent(m_ThreadIndex, currentInstigatorTuple.Entity, attackTargetComponent); //CommandBuffer.AddComponent(chunkIndex, EntityToTestAgainst[j], new OccupiedAsTargetTag()); break; } } while (InstigatorMap.TryGetNextValue(out currentTargetTuple, ref targetIterator) == true); } while (InstigatorMap.TryGetNextValue(out currentInstigatorTuple, ref instigatorIterator) == true); }
private void CheckValidity(Entity e, ref AttackTargetComponent a) { if (EntityManager.Exists(a.Target) == false) { EntityManager.RemoveComponent <AttackTargetComponent>(e); if (EntityManager.HasComponent <EnemyTeamComponent>(e)) { EntityManager.AddComponent <FollowWaypointTag>(e); int currentTarget = EntityManager.GetComponentData <WaypointMovementComponent>(e).CurrentTargetIndex; var noise = new float3(m_Random.NextFloat(-m_NoiseValue, m_NoiseValue), 0, m_Random.NextFloat(-m_NoiseValue, m_NoiseValue)); var moveForward = new MoveForwardComponent { Target = AllWaypointTranslation[currentTarget].Value + noise }; EntityManager.AddComponentData(e, moveForward); } } }