Esempio n. 1
0
    public static int GetEntitiesInRadius <ENTITY_TYPE>(ref ENTITY_TYPE[] result, Vector3 position, float radius = INTEREST_RADIUS) where ENTITY_TYPE : ServerWorldEntity
    {
        ray.origin    = position;
        ray.direction = Vector3.up;
        bool gotHits;

        lock (octree)
        {
            gotHits = octree.GetNearbyNonAlloc(ray, radius, listResult);
        }
        if (!gotHits)
        {
            return(0);
        }
        // Clear out all entities that don't match the requested class
        listResult.RemoveAll((entity) => { return(!(entity is ENTITY_TYPE)); });
        int hits = listResult.Count;

        if (result.Length < hits)
        {
            result = new ENTITY_TYPE[(int)Mathf.Round(hits * 1.1f)];
        }
        listResult.CopyTo(result);
        return(hits);
    }