C# Класс RedBlueGames.Tools.RBPhysics2D

RBPhysics2D wraps 2D physics calls with Debug calls for drawing the casts in the Editor
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
DebugDrawColliders void
DrawBoxAndOverlaps void
DrawCircleAndOverlaps void
DrawCircleCastAndHits void
DrawHitsForCirclecast void
DrawHitsForRaycasts void
DrawLineAndHits void
DrawRayAndHits void
DrawRaycastHit2D void
RBPhysics2D System.Collections
RaycastHitsContainHit bool

Открытые методы

Метод Описание
CircleCast ( Vector2 origin, float radius, Vector2 direction, float distance = Mathf.Infinity, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : RaycastHit2D

Casts a circle against colliders in the scene, with debug drawing information. Returns the first hit information.

CircleCastAll ( Vector2 origin, float radius, Vector2 direction, float distance = Mathf.Infinity, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : UnityEngine.RaycastHit2D[]

Casts a circle against colliders in the scene, with debug drawing information. Returns all the hits along the cast.

CircleCastNonAlloc ( Vector2 origin, float radius, Vector2 direction, RaycastHit2D results, float distance = Mathf.Infinity, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : void

Casts a circle against colliders in the scene, with debug drawing information. Passes results into a supplied array to minimize allocations.

LineCast ( Vector2 start, Vector2 end, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : RaycastHit2D

Perform a LineCast, with debug drawing. Gets the first hit.

LineCastAll ( Vector2 start, Vector2 end, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : UnityEngine.RaycastHit2D[]

Perform a LineCast, with debug drawing. Gets all hits along the line

LineCastNonAlloc ( Vector2 start, Vector2 end, RaycastHit2D results, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : void

Perform a LineCast, wait debug drawing. Uses a supplied array to prevent allocation.

OverlapArea ( Vector2 cornerA, Vector2 cornerB, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity ) : Collider2D

Checks if any collider lies inside a rectangle. Returns the collider with the lowest z value (I think...)

OverlapAreaAll ( Vector2 cornerA, Vector2 cornerB, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity ) : UnityEngine.Collider2D[]

Checks if any collider lies inside a rectangle. Returns all colliders found

OverlapCircle ( Vector2 center, float radius, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity ) : Collider2D

Checks if any collider lies inside a circle. Returns the collider with the lowest z value (I think...)

OverlapCircleAll ( Vector2 center, float radius, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity ) : UnityEngine.Collider2D[]

Checks if any collider lies inside a circle. Returns all overlapping colliders

RayCast ( Vector2 origin, Vector2 direction, float distance = Mathf.Infinity, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : RaycastHit2D

Casts a ray against scene colliders, with debug drawing information. Returns the first hit.

RayCastAll ( Vector2 origin, Vector2 direction, float distance = Mathf.Infinity, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : UnityEngine.RaycastHit2D[]

Casts a ray against scene colliders, with debug drawing information. Returns all hit along the cast.

RayCastNonAlloc ( Vector2 origin, Vector2 direction, RaycastHit2D results, float distance = Mathf.Infinity, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : void

Casts a ray against scene colliders, with debug drawing information. Passes results into a supplied array in order to minimize allocations

Приватные методы

Метод Описание
DebugDrawColliders ( Collider2D colliders, Color color ) : void
DrawBoxAndOverlaps ( Collider2D overlappingColliders, Vector2 cornerA, Vector2 cornerB ) : void
DrawCircleAndOverlaps ( Collider2D overlappingColliders, Vector2 center, float radius ) : void
DrawCircleCastAndHits ( RaycastHit2D hits, Vector2 origin, float radius, Vector2 direction, float distance = Mathf.Infinity ) : void
DrawHitsForCirclecast ( RaycastHit2D hits, float radius ) : void
DrawHitsForRaycasts ( RaycastHit2D hits ) : void
DrawLineAndHits ( RaycastHit2D hits, Vector2 origin, Vector2 endpoint ) : void
DrawRayAndHits ( RaycastHit2D hits, Vector2 origin, Vector2 direction, float distance = Mathf.Infinity ) : void
DrawRaycastHit2D ( RaycastHit2D hit, float size = 1.0f ) : void
RBPhysics2D ( ) : System.Collections
RaycastHitsContainHit ( RaycastHit2D hits ) : bool

Описание методов

CircleCast() публичный статический Метод

Casts a circle against colliders in the scene, with debug drawing information. Returns the first hit information.
public static CircleCast ( Vector2 origin, float radius, Vector2 direction, float distance = Mathf.Infinity, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : RaycastHit2D
origin UnityEngine.Vector2 Origin point in 2D.
radius float Radius of the circle.
direction UnityEngine.Vector2 Direction to "drag" the circle.
distance float Distance for the cast.
layerMask int Layer mask to hit.
minDepth float Minimum depth - hit items with at least this z.
maxDepth float Max depth - hit items with at most this z.
Результат UnityEngine.RaycastHit2D

CircleCastAll() публичный статический Метод

Casts a circle against colliders in the scene, with debug drawing information. Returns all the hits along the cast.
public static CircleCastAll ( Vector2 origin, float radius, Vector2 direction, float distance = Mathf.Infinity, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : UnityEngine.RaycastHit2D[]
origin UnityEngine.Vector2 Origin point in 2D.
radius float Radius of the circle.
direction UnityEngine.Vector2 Direction to "drag" the circle.
distance float Distance for the cast.
layerMask int Layer mask to hit.
minDepth float Minimum depth - hit items with at least this z.
maxDepth float Max depth - hit items with at most this z.
Результат UnityEngine.RaycastHit2D[]

CircleCastNonAlloc() публичный статический Метод

Casts a circle against colliders in the scene, with debug drawing information. Passes results into a supplied array to minimize allocations.
public static CircleCastNonAlloc ( Vector2 origin, float radius, Vector2 direction, RaycastHit2D results, float distance = Mathf.Infinity, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : void
origin UnityEngine.Vector2 Origin point in 2D.
radius float Radius of the circle.
direction UnityEngine.Vector2 Direction to "drag" the circle.
results UnityEngine.RaycastHit2D Array to store the resulting hits in.
distance float Distance for the cast.
layerMask int Layer mask to hit.
minDepth float Minimum depth - hit items with at least this z.
maxDepth float Max depth - hit items with at most this z.
Результат void

LineCast() публичный статический Метод

Perform a LineCast, with debug drawing. Gets the first hit.
public static LineCast ( Vector2 start, Vector2 end, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : RaycastHit2D
start UnityEngine.Vector2 Start point, in 2D world space.
end UnityEngine.Vector2 End point, in 2D world space.
layerMask int Layer mask to hit.
minDepth float Minimum depth - hit items with at least this z.
maxDepth float Max depth - hit items with at most this z.
Результат UnityEngine.RaycastHit2D

LineCastAll() публичный статический Метод

Perform a LineCast, with debug drawing. Gets all hits along the line
public static LineCastAll ( Vector2 start, Vector2 end, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : UnityEngine.RaycastHit2D[]
start UnityEngine.Vector2 Start point, in 2D world space.
end UnityEngine.Vector2 End point, in 2D world space.
layerMask int Layer mask to hit.
minDepth float Minimum depth - hit items with at least this z.
maxDepth float Max depth - hit items with at most this z.
Результат UnityEngine.RaycastHit2D[]

LineCastNonAlloc() публичный статический Метод

Perform a LineCast, wait debug drawing. Uses a supplied array to prevent allocation.
public static LineCastNonAlloc ( Vector2 start, Vector2 end, RaycastHit2D results, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : void
start UnityEngine.Vector2 Start point in 2D world space.
end UnityEngine.Vector2 End point in 2D world space.
results UnityEngine.RaycastHit2D Array to store the results in.
layerMask int Layer mask to hit.
minDepth float Minimum depth - hit items with at least this z.
maxDepth float Max depth - hit items with at most this z.
Результат void

OverlapArea() публичный статический Метод

Checks if any collider lies inside a rectangle. Returns the collider with the lowest z value (I think...)
public static OverlapArea ( Vector2 cornerA, Vector2 cornerB, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity ) : Collider2D
cornerA UnityEngine.Vector2 One corner for the Area
cornerB UnityEngine.Vector2 Opposite corner for the Area
layerMask int Layer mask for colliders to check.
minDepth float Minimum depth - hit items with at least this z.
maxDepth float Max depth - hit items with at most this z.
Результат UnityEngine.Collider2D

OverlapAreaAll() публичный статический Метод

Checks if any collider lies inside a rectangle. Returns all colliders found
public static OverlapAreaAll ( Vector2 cornerA, Vector2 cornerB, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity ) : UnityEngine.Collider2D[]
cornerA UnityEngine.Vector2 One corner for the Area
cornerB UnityEngine.Vector2 Opposite corner for the Area
layerMask int Layer mask for colliders to check.
minDepth float Minimum depth - hit items with at least this z.
maxDepth float Max depth - hit items with at most this z.
Результат UnityEngine.Collider2D[]

OverlapCircle() публичный статический Метод

Checks if any collider lies inside a circle. Returns the collider with the lowest z value (I think...)
public static OverlapCircle ( Vector2 center, float radius, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity ) : Collider2D
center UnityEngine.Vector2 Center for the circle in 2D world space.
radius float Radius for the circle.
layerMask int Layer mask for colliders to check.
minDepth float Minimum depth - hit items with at least this z.
maxDepth float Max depth - hit items with at most this z.
Результат UnityEngine.Collider2D

OverlapCircleAll() публичный статический Метод

Checks if any collider lies inside a circle. Returns all overlapping colliders
public static OverlapCircleAll ( Vector2 center, float radius, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity ) : UnityEngine.Collider2D[]
center UnityEngine.Vector2 Center for the circle in 2D world space.
radius float Radius for the circle.
layerMask int Layer mask for colliders to check.
minDepth float Minimum depth - hit items with at least this z.
maxDepth float Max depth - hit items with at most this z.
Результат UnityEngine.Collider2D[]

RayCast() публичный статический Метод

Casts a ray against scene colliders, with debug drawing information. Returns the first hit.
public static RayCast ( Vector2 origin, Vector2 direction, float distance = Mathf.Infinity, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : RaycastHit2D
origin UnityEngine.Vector2 Origin for the ray in 2D world space.
direction UnityEngine.Vector2 Direction as a 2D vector.
distance float Distance for the raycast.
layerMask int Layer mask to hit.
minDepth float Minimum depth - hit items with at least this z.
maxDepth float Max depth - hit items with at most this z.
Результат UnityEngine.RaycastHit2D

RayCastAll() публичный статический Метод

Casts a ray against scene colliders, with debug drawing information. Returns all hit along the cast.
public static RayCastAll ( Vector2 origin, Vector2 direction, float distance = Mathf.Infinity, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : UnityEngine.RaycastHit2D[]
origin UnityEngine.Vector2 Origin for the ray in 2D world space.
direction UnityEngine.Vector2 Direction as a 2D vector.
distance float Distance for the raycast.
layerMask int Layer mask to hit.
minDepth float Minimum depth - hit items with at least this z.
maxDepth float Max depth - hit items with at most this z.
Результат UnityEngine.RaycastHit2D[]

RayCastNonAlloc() публичный статический Метод

Casts a ray against scene colliders, with debug drawing information. Passes results into a supplied array in order to minimize allocations
public static RayCastNonAlloc ( Vector2 origin, Vector2 direction, RaycastHit2D results, float distance = Mathf.Infinity, int layerMask = Physics2D.DefaultRaycastLayers, float minDepth = Mathf.NegativeInfinity, float maxDepth = Mathf.Infinity ) : void
origin UnityEngine.Vector2 Origin for the ray in 2D world space.
direction UnityEngine.Vector2 Direction as a 2D vector.
results UnityEngine.RaycastHit2D Array to store resulting hits in.
distance float Distance for the raycast.
layerMask int Layer mask to hit.
minDepth float Minimum depth - hit items with at least this z.
maxDepth float Max depth - hit items with at most this z.
Результат void