Nez.Portable/Physics/SpatialHash.cs
/// <summary>
/// gets all the colliders that fall within the specified rect
/// </summary>
/// <returns>the number of Colliders returned</returns>
/// <param name="rect">Rect.</param>
/// <param name="results">Results.</param>
/// <param name="layerMask">Layer mask.</param>
gets all the colliders that fall within the specified rect
gets all the colliders that fall within the specified rect
public int overlapRectangle(ref RectangleF rect, Collider[] results, int layerMask)
        {
            _overlapTestBox.updateBox(rect.width, rect.height);
            _overlapTestBox.position = rect.location;
            var resultCounter = 0;
            var potentials = aabbBroadphase(ref rect, null, layerMask);
            foreach (var collider in potentials)
            {
                if (collider is BoxCollider)
                {
                    results[resultCounter] = collider;
                    resultCounter++;
                }
                else if (collider is CircleCollider)
                {
                    if (Collisions.rectToCircle(ref rect, collider.bounds.center, collider.bounds.width * 0.5f))
                    {
                        results[resultCounter] = collider;
                        resultCounter++;
                    }
                }
                else if (collider is PolygonCollider)
                {
                    if (collider.shape.overlaps(_overlapTestBox))
                    {
                        results[resultCounter] = collider;
                        resultCounter++;
                    }
                }
                else
                {
                    throw new NotImplementedException(
                        "overlapRectangle against this collider type is not implemented!");
                }
                if (resultCounter == results.Length)
                    return resultCounter;
            }
            return resultCounter;
        }
public int overlapRectangle ( ref RectangleF rect , Collider [ ] results , int layerMask ) { _overlapTestBox . updateBox ( rect . width , rect . height ) ; _overlapTestBox . position = rect . location ; var resultCounter = 0 ; var potentials = aabbBroadphase ( ref rect , null , layerMask ) ; foreach ( var collider in potentials ) { if ( collider is BoxCollider ) { results [ resultCounter ] = collider ; resultCounter ++ ; } else if ( collider is CircleCollider ) { if ( Collisions . rectToCircle ( ref rect , collider . bounds . center , collider . bounds . width * 0.5f ) ) { results [ resultCounter ] = collider ; resultCounter ++ ; } } else if ( collider is PolygonCollider ) { if ( collider . shape . overlaps ( _overlapTestBox ) ) { results [ resultCounter ] = collider ; resultCounter ++ ; } } else { throw new NotImplementedException ( " " ) ; } if ( resultCounter == results . Length ) return resultCounter ; } return resultCounter ; }
gets all the colliders that fall within the specified rect
gets all the colliders that fall within the specified rect
// if our results array is full return
the number of Colliders returned
the number of Colliders returned
RectangleF
ref
results
Collider[]
None
layerMask
int
None
rect
None