public void Execute(Entity entity, int index, [ReadOnly] ref Translation translation, [ReadOnly] ref SectorEntity SectorEntity, ref DeathComponent _death) { float3 unitPosition = translation.Value; Entity closestTargetEntity = Entity.Null; float closestTargetDistance = float.MaxValue; bool isTargetDead = _death.isDead; int hashMapKey = SectorSystem.GetPositionHashMapKey(translation.Value); FindTarget(hashMapKey, unitPosition, SectorEntity, ref closestTargetEntity, ref closestTargetDistance, ref isTargetDead); FindTarget(hashMapKey + 1, unitPosition, SectorEntity, ref closestTargetEntity, ref closestTargetDistance, ref isTargetDead); FindTarget(hashMapKey - 1, unitPosition, SectorEntity, ref closestTargetEntity, ref closestTargetDistance, ref isTargetDead); FindTarget(hashMapKey + SectorSystem.SectorYMultiplier, unitPosition, SectorEntity, ref closestTargetEntity, ref closestTargetDistance, ref isTargetDead); FindTarget(hashMapKey - SectorSystem.SectorYMultiplier, unitPosition, SectorEntity, ref closestTargetEntity, ref closestTargetDistance, ref isTargetDead); FindTarget(hashMapKey + 1 + SectorSystem.SectorYMultiplier, unitPosition, SectorEntity, ref closestTargetEntity, ref closestTargetDistance, ref isTargetDead); FindTarget(hashMapKey - 1 + SectorSystem.SectorYMultiplier, unitPosition, SectorEntity, ref closestTargetEntity, ref closestTargetDistance, ref isTargetDead); FindTarget(hashMapKey + 1 - SectorSystem.SectorYMultiplier, unitPosition, SectorEntity, ref closestTargetEntity, ref closestTargetDistance, ref isTargetDead); FindTarget(hashMapKey - 1 - SectorSystem.SectorYMultiplier, unitPosition, SectorEntity, ref closestTargetEntity, ref closestTargetDistance, ref isTargetDead); if (closestTargetEntityArray.Length != 0) { if (!isTargetDead) { closestTargetEntityArray[index] = closestTargetEntity; } } }
public void Execute(Entity entity, int index, [ReadOnly] ref Translation translation, [ReadOnly] ref SectorEntity SectorEntity) { float3 unitPosition = translation.Value; Entity closestAttackerEntity = Entity.Null; float closestAttackerDistance = float.MaxValue; int hashMapKey = SectorSystem.GetPositionHashMapKey(translation.Value); FindAttacker(hashMapKey, unitPosition, SectorEntity, ref closestAttackerEntity, ref closestAttackerDistance); FindAttacker(hashMapKey + 1, unitPosition, SectorEntity, ref closestAttackerEntity, ref closestAttackerDistance); FindAttacker(hashMapKey - 1, unitPosition, SectorEntity, ref closestAttackerEntity, ref closestAttackerDistance); FindAttacker(hashMapKey + SectorSystem.SectorYMultiplier, unitPosition, SectorEntity, ref closestAttackerEntity, ref closestAttackerDistance); FindAttacker(hashMapKey - SectorSystem.SectorYMultiplier, unitPosition, SectorEntity, ref closestAttackerEntity, ref closestAttackerDistance); FindAttacker(hashMapKey + 1 + SectorSystem.SectorYMultiplier, unitPosition, SectorEntity, ref closestAttackerEntity, ref closestAttackerDistance); FindAttacker(hashMapKey - 1 + SectorSystem.SectorYMultiplier, unitPosition, SectorEntity, ref closestAttackerEntity, ref closestAttackerDistance); FindAttacker(hashMapKey + 1 - SectorSystem.SectorYMultiplier, unitPosition, SectorEntity, ref closestAttackerEntity, ref closestAttackerDistance); FindAttacker(hashMapKey - 1 - SectorSystem.SectorYMultiplier, unitPosition, SectorEntity, ref closestAttackerEntity, ref closestAttackerDistance); if (closestAttackerEntityArray.Length != 0) { EntityWithTarget attacker = new EntityWithTarget { entity = closestAttackerEntity, position = unitPosition }; closestAttackerEntityArray[index] = attacker; } }