Infohazard.Core 1.4.1
Infohazard Core Utility Library
Loading...
Searching...
No Matches
Infohazard.Core.GameObjectUtility Class Reference

Contains utility methods for dealing with GameObjects and Transforms. More...

Static Public Member Functions

static void GetCapsuleInfo (float radius, float height, Vector3 center, int direction, Transform transform, out Vector3 point1, out Vector3 point2, out float worldRadius, out float worldHeight)
 Converts capsule info in transform/height/radius form to two-point form for use with Physics.CapsuleCast. More...
 
static void GetCapsuleInfo (this CharacterController capsule, out Vector3 point1, out Vector3 point2, out float worldRadius, out float worldHeight)
 Converts capsule info in a CharacterController to two-point form for use with Physics.CapsuleCast. More...
 
static void GetCapsuleInfo (this CapsuleCollider capsule, out Vector3 point1, out Vector3 point2, out float worldRadius, out float worldHeight)
 Converts capsule info in a CapsuleCollider to two-point form for use with Physics.CapsuleCast. More...
 
static bool ColliderCast (this Collider collider, float padding, Vector3 direction, out RaycastHit hit, float maxDistance=float.PositiveInfinity, int layerMask=Physics.DefaultRaycastLayers, QueryTriggerInteraction triggerInteraction=QueryTriggerInteraction.UseGlobal)
 Perform a physics cast depending on the type of collider, using its parameters. Only BoxCollider, SphereCollider, and CapsuleCollider are supported. For simplicity, the scale of the transform is assumed to be uniform. More...
 
static void SetParentAndReset (this Transform transform, Transform parent)
 Set the parent of the given transform, and reset it's local position, rotation, and scale. More...
 
static void Initialize (this Transform transform, Transform parent, Vector3? position=null, Quaternion? rotation=null, Vector3? scale=null, bool inWorldSpace=false, in Scene? scene=null)
 Initialize the transform with the given parent, position, rotation, and scale. More...
 
static void Initialize (this Transform transform, in SpawnParams spawnParams=default)
 Initialize the transform with the given spawn params. More...
 
static void Initialize (this Transform transform, Vector3? position=null, Quaternion? rotation=null, Vector3? scale=null)
 Set's the transform's position, and rotation, and scale (if they are specified). More...
 
static void DestroyChildren (this Transform transform)
 Destroy all of the child GameObjects of a Transform at the end of this frame. More...
 
static void DestroyChildrenImmediate (this Transform transform)
 Destroy all of the child GameObjects of a Transform immediately. More...
 
static void DespawnChildren (this Transform transform)
 Despawn all of the child GameObjects of a Transform. More...
 
static bool TryGetComponentInParent< T > (this GameObject obj, out T result)
 Like GetComponentInParent, but more convenient if using in conditionals and also using the component value. More...
 
static bool TryGetComponentInChildren< T > (this GameObject obj, out T result, bool includeInactive=false)
 Like GetComponentInChildren, but more convenient if using in conditionals and also using the component value. More...
 
static bool TryGetComponentInParent< T > (this Component cmp, out T result)
 Like GetComponentInParent, but more convenient if using in if statements and also using the component value. More...
 
static bool TryGetComponentInChildren< T > (this Component cmp, out T result)
 Like GetComponentInChildren, but more convenient if using in if statements and also using the component value. More...
 
static string GetRelativeTransformPath (this Transform from, Transform to)
 Get the path from one transform to another (object names separated by slashes). Names are URL encoded in case they contain slashes. More...
 
static Transform GetTransformAtRelativePath (this Transform from, string path)
 Parses a slash-separated Transform path from a parent object to find a child. The names are expected to be URL encoded. More...
 
static bool IsPathUnique (this Transform from, Transform to)
 Check whether the path from one transform to another (the one returned by GetRelativeTransformPath) is unique. If the path is not unique, using GetTransformAtRelativePath will not necessarily return the correct transform. More...
 
static bool IsNameUniqueInSiblings (this Transform transform)
 Return whether the name of an object is unique within its siblings. More...
 
static void SetLayerRecursively (this GameObject obj, int layer)
 Sets the layer of a GameObject and all of its children. More...
 
static void SetLinearVelocity (this Rigidbody rb, Vector3 velocity)
 Utility method to accommodate Unity 6 velocity name change. More...
 
static Vector3 GetLinearVelocity (this Rigidbody rb)
 Utility method to accommodate Unity 6 velocity name change. More...
 
static void AddLinearVelocity (this Rigidbody rb, Vector3 velocity)
 Utility method to accommodate Unity 6 velocity name change. More...
 
static void MoveTowardsLinearVelocity (this Rigidbody rb, Vector3 targetVelocity, float maxDeltaV)
 Utility method to accommodate Unity 6 velocity name change. More...
 

Detailed Description

Contains utility methods for dealing with GameObjects and Transforms.

Member Function Documentation

◆ AddLinearVelocity()

static void Infohazard.Core.GameObjectUtility.AddLinearVelocity ( this Rigidbody  rb,
Vector3  velocity 
)
static

Utility method to accommodate Unity 6 velocity name change.

◆ ColliderCast()

static bool Infohazard.Core.GameObjectUtility.ColliderCast ( this Collider  collider,
float  padding,
Vector3  direction,
out RaycastHit  hit,
float  maxDistance = float.PositiveInfinity,
int  layerMask = Physics.DefaultRaycastLayers,
QueryTriggerInteraction  triggerInteraction = QueryTriggerInteraction.UseGlobal 
)
static

Perform a physics cast depending on the type of collider, using its parameters. Only BoxCollider, SphereCollider, and CapsuleCollider are supported. For simplicity, the scale of the transform is assumed to be uniform.

Parameters
colliderThe BoxCollider, SphereCollider, or CapsuleCollider to cast from.
paddingA padding to reduce the collider's extents. Given in world units.
directionDirection to cast in.
hitThe hit information.
maxDistanceThe maximum distance to cast. Default is infinity.
layerMaskThe layer mask to cast against. Default is default raycast layers.
triggerInteractionWhether to include triggers. Default is use global settings.
Returns
Whether the cast hit something.

◆ DespawnChildren()

static void Infohazard.Core.GameObjectUtility.DespawnChildren ( this Transform  transform)
static

Despawn all of the child GameObjects of a Transform.

Parameters
transformTransform to despawn children of.

◆ DestroyChildren()

static void Infohazard.Core.GameObjectUtility.DestroyChildren ( this Transform  transform)
static

Destroy all of the child GameObjects of a Transform at the end of this frame.

Parameters
transformTransform to destroy children of.

◆ DestroyChildrenImmediate()

static void Infohazard.Core.GameObjectUtility.DestroyChildrenImmediate ( this Transform  transform)
static

Destroy all of the child GameObjects of a Transform immediately.

Parameters
transformTransform to destroy children of.

◆ GetCapsuleInfo() [1/3]

static void Infohazard.Core.GameObjectUtility.GetCapsuleInfo ( float  radius,
float  height,
Vector3  center,
int  direction,
Transform  transform,
out Vector3  point1,
out Vector3  point2,
out float  worldRadius,
out float  worldHeight 
)
static

Converts capsule info in transform/height/radius form to two-point form for use with Physics.CapsuleCast.

Also tells you the radius and height of the capsule in world space.

Parameters
radiusRadius of the capsule in local space.
heightHeight of the capsule in local space.
centerCenter of the capsule in local space.
directionOn which axis the capsule extends (0 = x, 1 = y, 2 = z).
transformTransform that the capsule is parented to.
point1The first point of the capsule in world space.
point2The second point of the capsule in world space.
worldRadiusThe radius of the capsule in world space.
worldHeightThe height of the capsule in world space.

◆ GetCapsuleInfo() [2/3]

static void Infohazard.Core.GameObjectUtility.GetCapsuleInfo ( this CapsuleCollider  capsule,
out Vector3  point1,
out Vector3  point2,
out float  worldRadius,
out float  worldHeight 
)
static

Converts capsule info in a CapsuleCollider to two-point form for use with Physics.CapsuleCast.

Also tells you the radius and height of the capsule in world space.

Parameters
capsuleThe CapsuleCollider to read.
point1The first point of the capsule in world space.
point2The second point of the capsule in world space.
worldRadiusThe radius of the capsule in world space.
worldHeightThe height of the capsule in world space.

◆ GetCapsuleInfo() [3/3]

static void Infohazard.Core.GameObjectUtility.GetCapsuleInfo ( this CharacterController  capsule,
out Vector3  point1,
out Vector3  point2,
out float  worldRadius,
out float  worldHeight 
)
static

Converts capsule info in a CharacterController to two-point form for use with Physics.CapsuleCast.

Also tells you the radius and height of the capsule in world space.

Parameters
capsuleThe CharacterController to read.
point1The first point of the capsule in world space.
point2The second point of the capsule in world space.
worldRadiusThe radius of the capsule in world space.
worldHeightThe height of the capsule in world space.

◆ GetLinearVelocity()

static Vector3 Infohazard.Core.GameObjectUtility.GetLinearVelocity ( this Rigidbody  rb)
static

Utility method to accommodate Unity 6 velocity name change.

◆ GetRelativeTransformPath()

static string Infohazard.Core.GameObjectUtility.GetRelativeTransformPath ( this Transform  from,
Transform  to 
)
static

Get the path from one transform to another (object names separated by slashes). Names are URL encoded in case they contain slashes.

The parameter to must be a direct descendent of from, or an error is logged. The returned path contains the name of to but not from. This path can be turned back to an object reference using GetTransformAtRelativePath.

Parameters
fromThe parent Transform to get the path from.
toThe Transform to get the path to.
Returns
The path relative transform path separated by slashes.

◆ GetTransformAtRelativePath()

static Transform Infohazard.Core.GameObjectUtility.GetTransformAtRelativePath ( this Transform  from,
string  path 
)
static

Parses a slash-separated Transform path from a parent object to find a child. The names are expected to be URL encoded.

This can be used to turn a path created by GetRelativeTransformPath back to an object reference.

Parameters
fromThe parent Transform to search from.
pathThe slash-separated path to search for.
Returns
The found child Transform, or null if not found.

◆ Initialize() [1/3]

static void Infohazard.Core.GameObjectUtility.Initialize ( this Transform  transform,
in SpawnParams  spawnParams = default 
)
static

Initialize the transform with the given spawn params.

Parameters
transformThe transform to initialize.
spawnParamsThe spawn parameters.

◆ Initialize() [2/3]

static void Infohazard.Core.GameObjectUtility.Initialize ( this Transform  transform,
Transform  parent,
Vector3?  position = null,
Quaternion?  rotation = null,
Vector3?  scale = null,
bool  inWorldSpace = false,
in Scene?  scene = null 
)
static

Initialize the transform with the given parent, position, rotation, and scale.

Parameters
transformThe transform to initialize.
parentThe parent to attach to.
positionThe position (if null, do not set).
rotationThe rotation (if null, do not set).
scaleThe scale (if null, do not set).
inWorldSpaceWhether the given position, rotation, and scale should be considered global.
sceneAn optional scene to move the object to.

◆ Initialize() [3/3]

static void Infohazard.Core.GameObjectUtility.Initialize ( this Transform  transform,
Vector3?  position = null,
Quaternion?  rotation = null,
Vector3?  scale = null 
)
static

Set's the transform's position, and rotation, and scale (if they are specified).

Parameters
transformThe transform to initialize.
positionThe position (if null, do not set).
rotationThe rotation (if null, do not set).
scaleThe scale (if null, do not set).

◆ IsNameUniqueInSiblings()

static bool Infohazard.Core.GameObjectUtility.IsNameUniqueInSiblings ( this Transform  transform)
static

Return whether the name of an object is unique within its siblings.

Parameters
transformThe object to check.
Returns
Whether the name is unique.

◆ IsPathUnique()

static bool Infohazard.Core.GameObjectUtility.IsPathUnique ( this Transform  from,
Transform  to 
)
static

Check whether the path from one transform to another (the one returned by GetRelativeTransformPath) is unique. If the path is not unique, using GetTransformAtRelativePath will not necessarily return the correct transform.

The names of the objects do not need to be globally unique. Rather, they must be unique within all of their siblings according to IsNameUniqueInSiblings.

Parameters
fromThe transform to check the path from.
toThe transform to check the path to.
Returns
Whether the path is unique.

◆ MoveTowardsLinearVelocity()

static void Infohazard.Core.GameObjectUtility.MoveTowardsLinearVelocity ( this Rigidbody  rb,
Vector3  targetVelocity,
float  maxDeltaV 
)
static

Utility method to accommodate Unity 6 velocity name change.

◆ SetLayerRecursively()

static void Infohazard.Core.GameObjectUtility.SetLayerRecursively ( this GameObject  obj,
int  layer 
)
static

Sets the layer of a GameObject and all of its children.

Parameters
objThe GameObject to set the layer on.
layerThe layer index to set.

◆ SetLinearVelocity()

static void Infohazard.Core.GameObjectUtility.SetLinearVelocity ( this Rigidbody  rb,
Vector3  velocity 
)
static

Utility method to accommodate Unity 6 velocity name change.

◆ SetParentAndReset()

static void Infohazard.Core.GameObjectUtility.SetParentAndReset ( this Transform  transform,
Transform  parent 
)
static

Set the parent of the given transform, and reset it's local position, rotation, and scale.

Parameters
transformThe transform to reset.
parentThe transform to parent it to (can be null).

◆ TryGetComponentInChildren< T >() [1/2]

static bool Infohazard.Core.GameObjectUtility.TryGetComponentInChildren< T > ( this Component  cmp,
out T  result 
)
static

Like GetComponentInChildren, but more convenient if using in if statements and also using the component value.

◆ TryGetComponentInChildren< T >() [2/2]

static bool Infohazard.Core.GameObjectUtility.TryGetComponentInChildren< T > ( this GameObject  obj,
out T  result,
bool  includeInactive = false 
)
static

Like GetComponentInChildren, but more convenient if using in conditionals and also using the component value.

◆ TryGetComponentInParent< T >() [1/2]

static bool Infohazard.Core.GameObjectUtility.TryGetComponentInParent< T > ( this Component  cmp,
out T  result 
)
static

Like GetComponentInParent, but more convenient if using in if statements and also using the component value.

◆ TryGetComponentInParent< T >() [2/2]

static bool Infohazard.Core.GameObjectUtility.TryGetComponentInParent< T > ( this GameObject  obj,
out T  result 
)
static

Like GetComponentInParent, but more convenient if using in conditionals and also using the component value.

Parameters
objThe object to search from.
resultThe found component or null.
Template Parameters
TThe type of component to search for.
Returns
Whether a component of the given type was found.

The documentation for this class was generated from the following file: