Class BoundsExtensions
Extension methods for Unity's Bounds struct
Inheritance
BoundsExtensions
Assembly: cs.temp.dll.dll
public static class BoundsExtensions
Fields
Declaration
Field Value
Declaration
Field Value
Declaration
Field Value
Declaration
Field Value
Declaration
public const int LB_LT = 7
Field Value
Declaration
Field Value
Declaration
Field Value
Declaration
public const int LBF_LBB = 18
Field Value
Declaration
public const int LBF_RBF = 9
Field Value
Declaration
Field Value
Declaration
Field Value
Declaration
public const int LT_RT = 4
Field Value
Declaration
Field Value
Declaration
public const int LTB_LBB = 14
Field Value
Declaration
Field Value
Declaration
public const int LTF_LBF = 12
Field Value
Declaration
public const int LTF_LTB = 19
Field Value
Declaration
public const int LTF_RTF = 8
Field Value
Declaration
Field Value
Declaration
public const int RB_LB = 6
Field Value
Declaration
Field Value
Declaration
public const int RBB_LBB = 11
Field Value
Declaration
Field Value
Declaration
public const int RBF_RBB = 16
Field Value
Declaration
Field Value
Declaration
Field Value
Declaration
public const int RT_RB = 5
Field Value
Declaration
Field Value
Declaration
public const int RTB_LTB = 10
Field Value
Declaration
public const int RTB_RBB = 13
Field Value
Declaration
Field Value
Declaration
public const int RTF_RBF = 15
Field Value
Declaration
public const int RTF_RTB = 17
Field Value
Declaration
Field Value
Methods
Checks to see whether point is closer to bounds or otherBounds
Declaration
public static bool CloserToPoint(this Bounds bounds, Vector3 point, Bounds otherBounds)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
|
Vector3 |
point |
|
Bounds |
otherBounds |
|
Returns
Checks to see if bounds contains the other bounds completely.
Declaration
public static bool ContainsBounds(this Bounds bounds, Bounds otherBounds)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
|
Bounds |
otherBounds |
|
Returns
Declaration
public static void DebugDraw(this Bounds bounds, Color color, float duration = 0F, bool depthTest = true)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
The Bounds to draw.
|
Color |
color |
Color of the line.
|
Single |
duration |
How long the line should be visible for in seconds.
|
Boolean |
depthTest |
Should the line be obscured by objects closer to the camera?
|
Returns bounds that contain both this bounds and the bounds passed in.
Declaration
public static Bounds ExpandToContain(this Bounds originalBounds, Bounds otherBounds)
Parameters
Type |
Name |
Description |
Bounds |
originalBounds |
|
Bounds |
otherBounds |
|
Returns
Method to get bounds using collider method.
Declaration
public static bool GetColliderBounds(GameObject target, out Bounds bounds, LayerMask ignoreLayers)
Parameters
Type |
Name |
Description |
GameObject |
target |
GameObject to generate the bounds around.
|
Bounds |
bounds |
An AABB in world space around all the colliders in a gameObject hierarchy.
|
LayerMask |
ignoreLayers |
A LayerMask to restrict the colliders selected.
|
Returns
Type |
Description |
Boolean |
True if bounds were calculated, if zero colliders are present bounds will not be calculated.
|
Method to get bounds from a single Collider
Declaration
public static void GetColliderBoundsPoints(Collider collider, List<Vector3> boundsPoints, LayerMask ignoreLayers)
Parameters
Type |
Name |
Description |
Collider |
collider |
Target collider
|
List<Vector3> |
boundsPoints |
array reference that gets filled with points
|
LayerMask |
ignoreLayers |
layerMask to simplify search
|
Method to get bounding box points using Collider method.
Declaration
public static void GetColliderBoundsPoints(GameObject target, List<Vector3> boundsPoints, LayerMask ignoreLayers)
Parameters
Type |
Name |
Description |
GameObject |
target |
gameObject that boundingBox bounds.
|
List<Vector3> |
boundsPoints |
array reference that gets filled with points
|
LayerMask |
ignoreLayers |
layerMask to simplify search
|
Gets all the corner points and mid points from Renderer's Bounds
Declaration
public static void GetCornerAndMidPointPositions(this Bounds bounds, Transform transform, ref Vector3[] positions)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
|
Transform |
transform |
|
Vector3[] |
positions |
|
Gets all the corner points and mid points from Renderer's Bounds, ignoring the z axis
Declaration
public static void GetCornerAndMidPointPositions2D(this Bounds bounds, Transform transform, ref Vector3[] positions, BoundsExtensions.Axis flattenAxis)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
|
Transform |
transform |
|
Vector3[] |
positions |
|
BoundsExtensions.Axis |
flattenAxis |
|
Gets all the corner points of the bounds in world space by transforming input bounds using the given transform
Declaration
public static void GetCornerPositions(this Bounds bounds, Transform transform, ref Vector3[] positions)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
Input bounds, in local space
|
Transform |
transform |
Local to world transform
|
Vector3[] |
positions |
Output corner positions
|
Gets all the corner points of the bounds
Declaration
public static void GetCornerPositions(this Bounds bounds, ref Vector3[] positions)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
|
Vector3[] |
positions |
|
Gets all the corner points from Renderer's Bounds
Declaration
public static void GetCornerPositionsFromRendererBounds(this Bounds bounds, ref Vector3[] positions)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
|
Vector3[] |
positions |
|
Declaration
public static void GetFacePositions(this Bounds bounds, Transform transform, ref Vector3[] positions)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
|
Transform |
transform |
|
Vector3[] |
positions |
|
Returns an instance of the 'Bounds' class which is invalid. An invalid 'Bounds' instance
is one which has its size vector set to 'float.MaxValue' for all 3 components. The center
of an invalid bounds instance is the zero vector.
Declaration
public static Bounds GetInvalidBoundsInstance()
Returns
Method to get bounds using mesh filters method.
Declaration
public static bool GetMeshFilterBounds(GameObject target, out Bounds bounds, LayerMask ignoreLayers)
Parameters
Type |
Name |
Description |
GameObject |
target |
GameObject to generate the bounds around.
|
Bounds |
bounds |
An AABB in world space around all the mesh filters in a GameObject hierarchy.
|
LayerMask |
ignoreLayers |
A LayerMask to restrict the colliders selected.
|
Returns
Type |
Description |
Boolean |
True if bounds were calculated, if zero mesh filters are present bounds will not be calculated.
|
GetMeshFilterBoundsPoints - gets bounding box points using MeshFilter method.
Declaration
public static void GetMeshFilterBoundsPoints(GameObject target, List<Vector3> boundsPoints, LayerMask ignoreLayers)
Parameters
Type |
Name |
Description |
GameObject |
target |
gameObject that boundingbox bounds
|
List<Vector3> |
boundsPoints |
array reference that gets filled with points
|
LayerMask |
ignoreLayers |
layerMask to simplify search
|
Method to get bounds from a collection of points.
Declaration
public static bool GetPointsBounds(List<Vector3> points, out Bounds bounds)
Parameters
Type |
Name |
Description |
List<Vector3> |
points |
The points to construct a bounds around.
|
Bounds |
bounds |
An AABB in world space around all the points.
|
Returns
Type |
Description |
Boolean |
True if bounds were calculated, if zero points are present bounds will not be calculated.
|
Method to get bounds using renderer method.
Declaration
public static bool GetRenderBounds(GameObject target, out Bounds bounds, LayerMask ignoreLayers)
Parameters
Type |
Name |
Description |
GameObject |
target |
GameObject to generate the bounds around.
|
Bounds |
bounds |
An AABB in world space around all the renderers in a gameObject hierarchy.
|
LayerMask |
ignoreLayers |
A LayerMask to restrict the colliders selected.
|
Returns
Type |
Description |
Boolean |
True if bounds were calculated, if zero renderers are present bounds will not be calculated.
|
GetRenderBoundsPoints gets bounding box points using Render method.
Declaration
public static void GetRenderBoundsPoints(GameObject target, List<Vector3> boundsPoints, LayerMask ignoreLayers)
Parameters
Type |
Name |
Description |
GameObject |
target |
gameObject that boundingbox bounds
|
List<Vector3> |
boundsPoints |
array reference that gets filled with points
|
LayerMask |
ignoreLayers |
layerMask to simplify search
|
Calculates how much scale is required for this Bounds to fit inside another bounds without stretching.
Declaration
public static float GetScaleToFitInside(this Bounds bounds, Bounds containerBounds)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
|
Bounds |
containerBounds |
The bounds of the container we're trying to fit this object.
|
Returns
Type |
Description |
Single |
A single scale factor that can be applied to this object to fit inside the container.
|
Calculates how much scale is required for this Bounds to match another Bounds.
Declaration
public static Vector3 GetScaleToMatchBounds(this Bounds bounds, Bounds otherBounds, Vector3 padding = null)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
|
Bounds |
otherBounds |
Object representation to be scaled to
|
Vector3 |
padding |
padding multiplied into another bounds
|
Returns
Type |
Description |
Vector3 |
Scale represented as a Vector3
|
Returns the rectangle which encloses the specifies 'Bounds' instance in screen space.
Declaration
public static Rect GetScreenRectangle(this Bounds bounds, Camera camera)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
|
Camera |
camera |
|
Returns
Returns the screen space corner points of the specified 'Bounds' instance.
Declaration
public static Vector2[] GetScreenSpaceCornerPoints(this Bounds bounds, Camera camera)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
|
Camera |
camera |
The camera used for rendering to the screen. This is needed to perform the
transformation to screen space.
|
Returns
Type |
Description |
Vector2[] |
|
Checks if the specified bounds instance is valid. A valid 'Bounds' instance is
one whose size vector does not have all 3 components set to 'float.MaxValue'.
Declaration
public static bool IsValid(this Bounds bounds)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
|
Returns
Transforms 'bounds' using the specified transform matrix.
Declaration
public static Bounds Transform(this Bounds bounds, Matrix4x4 transformMatrix)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
The 'Bounds' instance which must be transformed.
|
Matrix4x4 |
transformMatrix |
The specified 'Bounds' instance will be transformed using this transform matrix. The function
assumes that the matrix doesn't contain any projection or skew transformation.
|
Returns
Type |
Description |
Bounds |
The transformed 'Bounds' instance.
|
Returns the volume of the bounds.
Declaration
public static float Volume(this Bounds bounds)
Parameters
Type |
Name |
Description |
Bounds |
bounds |
|
Returns