Table of Contents

Class

Namespace
CoreFramework

Provides extension methods for working with Unity Transforms.

public static class TransformExtensions
Inheritance
object

Methods

Children(Transform)

Retrieves all the children of a given Transform.

public static IEnumerable<Transform> Children(this Transform parent)

Parameters

parent Transform

The Transform to retrieve children from.

Returns

IEnumerable<Transform>

An IEnumerable<Transform> containing all the child Transforms of the parent.

Remarks

This method can be used with LINQ to perform operations on all child Transforms. For example, you could use it to find all children with a specific tag, to disable all children, etc. Transform implements IEnumerable and the GetEnumerator method which returns an IEnumerator of all its children.

DestroyChildren(Transform)

Destroys all child game objects of the given transform.

public static void DestroyChildren(this Transform parent)

Parameters

parent Transform

The Transform whose child game objects are to be destroyed.

DestroyChildrenImmediate(Transform)

Immediately destroys all child game objects of the given transform.

public static void DestroyChildrenImmediate(this Transform parent)

Parameters

parent Transform

The Transform whose child game objects are to be immediately destroyed.

DisableChildren(Transform)

Disables all child game objects of the given transform.

public static void DisableChildren(this Transform parent)

Parameters

parent Transform

The Transform whose child game objects are to be disabled.

EnableChildren(Transform)

Enables all child game objects of the given transform.

public static void EnableChildren(this Transform parent)

Parameters

parent Transform

The Transform whose child game objects are to be enabled.

ForEveryChild(Transform, Action<Transform>)

Executes a specified action for each child of a given transform.

public static void ForEveryChild(this Transform parent, Action<Transform> action)

Parameters

parent Transform

The parent transform.

action Action<Transform>

The action to be performed on each child.

Remarks

This method iterates over all child transforms in reverse order and executes a given action on them. The action is a delegate that takes a Transform as a parameter.

InRangeOf(Transform, Transform, float, float)

Check if the transform is within a certain distance and optionally within a certain angle (FOV) from the target transform.

public static bool InRangeOf(this Transform source, Transform target, float maxDistance, float maxAngle = 360)

Parameters

source Transform

The transform to check.

target Transform

The target transform to compare the distance and optional angle with.

maxDistance float

The maximum distance allowed between the two transforms.

maxAngle float

The maximum allowed angle between the transform's forward vector and the direction to the target (default is 360).

Returns

bool

True if the transform is within range and angle (if provided) of the target, false otherwise.

Reset(Transform)

Resets transform's position, scale and rotation

public static void Reset(this Transform transform)

Parameters

transform Transform

Transform to use