TriLib  1.8.7f
TriLib Unity Package
TriLib.TransformExtensions Class Reference

Represents a series of UnityEngine.Transform extension methods. More...

Static Public Member Functions

static void LoadMatrix (this Transform transform, Matrix4x4 matrix, bool local=true)
 Assigns a UnityEngine.Matrix4x4 into UnityEngine.Transform components. More...
 
static Bounds EncapsulateBounds (this Transform transform)
 Encapsulates the UnityEngine.Transform childs bounds on new bounds. More...
 
static Transform FindDeepChild (this Transform transform, string name, bool endsWith=false)
 
static void DestroyChildren (this Transform transform, bool destroyImmediate=false)
 Destroys the children UnityEngine.GameObject of this UnityEngine.Transform. More...
 

Detailed Description

Represents a series of UnityEngine.Transform extension methods.

Member Function Documentation

◆ DestroyChildren()

static void TriLib.TransformExtensions.DestroyChildren ( this Transform  transform,
bool  destroyImmediate = false 
)
static

Destroys the children UnityEngine.GameObject of this UnityEngine.Transform.

Parameters
transformUnityEngine.Transform to destroy children from.
destroyImmediateWhen true destroy children immediately.

◆ EncapsulateBounds()

static Bounds TriLib.TransformExtensions.EncapsulateBounds ( this Transform  transform)
static

Encapsulates the UnityEngine.Transform childs bounds on new bounds.

Parameters
transformUnityEngine.Transform to encapsulate.
Returns
Encapsulated UnityEngine.Bounds.
//Gets the bounds that represents all children extents
var bounds = myTransform.EncapsulateBounds();
//Gets the bounds radius
var boundRadius = bounds.extents.magnitude;
//Calculates a distance from "myTransform" for camera framing
var distance = (boundRadius / (2.0f * Mathf.Tan(0.5f * camera.fieldOfView * Mathf.Deg2Rad))) * radius;
//Returns if the distance isnĀ“t numeric (caused by empty bounds)
if (System.Single.IsNaN(distance))
{
return;
}
//Sets the camera far clip plane to the double of the acquired distance
camera.farClipPlane = distance * 2f;
//Puts the camera at the acquired distance relative to the bounds
camera.transform.position = new Vector3(bounds.center.x, bounds.center.y, bounds.center.z + distance);
//Looks at the bounds center with the camera
camera.transform.LookAt(bounds.center);

◆ FindDeepChild()

static Transform TriLib.TransformExtensions.FindDeepChild ( this Transform  transform,
string  name,
bool  endsWith = false 
)
static

Parameters
transformUnityEngine.Transform to search in.
nameName of the object to search for.
endsWithWhen true, search for transforms that ends with 'name' value.
Returns
The UnityEngine.Transform if found, otherwise, null.

◆ LoadMatrix()

static void TriLib.TransformExtensions.LoadMatrix ( this Transform  transform,
Matrix4x4  matrix,
bool  local = true 
)
static

Assigns a UnityEngine.Matrix4x4 into UnityEngine.Transform components.

Parameters
transformUnityEngine.Transform to assign the UnityEngine.Matrix4x4.
matrixUnityEngine.Matrix4x4 to assign.
localIf true, copies the UnityEngine.Matrix4x4 components to UnityEngine.Transform local components. Otherwise, copies the UnityEngine.Matrix4x4 components to UnityEngine.Transform world components.
//Creates a matrix that moves 100 units forward at world space, then rotates 90 units on y-axis at local space
var myMatrix = Matrix4x4.TRS(new Vector3(0f, 0f, 100f), Quaternion.Euler(0f, 90f, 0f), Vector3.one);
//Assigns the position, rotation and local scale contained in the "myMatrix" into "myGameObject"
myGameObject.transform.LoadMatrix(myMatrix);

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