Example #1
0
    public HitAbleInfo[] GetHitAbleInCircles(Vector3 globalPosition, HitAbleType mask, float radius, bool useColliderBounds, bool sorted = false)
    {
        if (SpawnedHitAbles.Count == 0)
        {
            return(new HitAbleInfo[0]);
        }

        List <HitAbleInfo> enemies = new List <HitAbleInfo>();

        for (int i = 0; i < SpawnedHitAbles.Count; i++)
        {
            if (!SpawnedHitAbles[i].Transform)
            {
                continue;
            }
            if (!HitAble.CheckForBitInMask(SpawnedHitAbles[i].HitAbleType, mask))
            {
                continue;
            }

            float distance = DistanceBetween(globalPosition, SpawnedHitAbles[i].hitAble, useColliderBounds);
            if (distance < radius)
            {
                SpawnedHitAbles[i].distance = distance;
                enemies.Add(SpawnedHitAbles[i]);
            }
        }

        if (sorted)
        {
            enemies.Sort();
        }
        return(enemies.ToArray());
    }
Example #2
0
    public HitAbleInfo GetNearestHitAbles(Vector3 globalPosition, HitAbleType mask, bool useColliderBounds, float maxDistance = -1)
    {
        if (SpawnedHitAbles.Count == 0)
        {
            return(null);
        }

        HitAbleInfo nearest = new HitAbleInfo()
        {
            hitAble = null
        };

        float nearestDistance = -1;

        for (int i = 0; i < SpawnedHitAbles.Count; i++)
        {
            if (!SpawnedHitAbles[i].Transform)
            {
                continue;
            }
            if (!HitAble.CheckForBitInMask(SpawnedHitAbles[i].hitAble.hitAbleType, mask))
            {
                continue;
            }

            float distance = DistanceBetween(globalPosition, SpawnedHitAbles[i].hitAble, useColliderBounds);
            if ((maxDistance > 0 && distance < maxDistance) && (nearestDistance == -1 || distance < nearestDistance))
            {
                nearest          = SpawnedHitAbles[i];
                nearest.distance = distance;
                nearestDistance  = distance;
            }
        }
        return(nearest);
    }