Skip to content

Collider2DExtensions

Namespace: SideXP.Core

public static class Collider2DExtensions

Extension functions for Collider2D components. See ColliderExtensions for 3D colliders.

Methods

GetColliderBounds(Collider2D)

public static Bounds GetColliderBounds(Collider2D collider)

Returns

Returns the collider bounds.

GetColliderBounds(Collider2D, Bounds)

public static bool GetColliderBounds(Collider2D collider, out Bounds bounds)

Gets the bounds of a collider.

Parameters

  • collider: The collider of which to query the bounds.
  • bounds: Outputs the collider bounds.

Returns

Returns true if the collider type is supported (box, sphere, capsule, or mesh with a shared mesh).

Remarks

While the game is running, the physics system provides accurate world bounds through bounds. At edit time (or for a prefab) that representation isn't baked, and reading it (even through the concrete collider type) returns a zeroed value. In that case the bounds are computed from the collider's geometry (center/size/radius/mesh) transformed into world space instead. Note: for a rotated non-box collider the computed AABB is slightly looser than the physics one.

GetColliderOffset(Collider2D)

public static Vector2 GetColliderOffset(Collider2D collider)

Gets the offset of a Collider2D.

Parameters

  • collider: The collider to check.

Returns

Returns the found collider offset.

GetColliderOffset(Collider2D, Vector2)

public static bool GetColliderOffset(Collider2D collider, out Vector2 offset)

Gets the offset of a Collider2D.

Parameters

  • collider: The collider to check.
  • offset: Outputs the found collider offset.

Returns

Returns true if the offset has been queried successfully.