UnityUtilities
UnityUtilities.UnityHelper Class Reference

Provides a lot of convenience methods for handling Unity data types, either in the form of extension methods or as static helper methods. More...

Static Public Member Functions

static void CopyPositionAndRotatationFrom (this Transform transform, Transform source)
 Copies the position and rotation from another transform to this transform. More...
 
static Transform SetPosition (this Transform transform, float? x=null, float? y=null, float? z=null)
 Sets the x/y/z transform.position using optional parameters, keeping all undefined values as they were before. Can be called with named parameters like transform.SetPosition(x: 5, z: 10), for example, only changing transform.position.x and z. More...
 
static Transform SetLocalPosition (this Transform transform, float? x=null, float? y=null, float? z=null)
 Sets the x/y/z transform.localPosition using optional parameters, keeping all undefined values as they were before. Can be called with named parameters like transform.SetLocalPosition(x: 5, z: 10), for example, only changing transform.localPosition.x and z. More...
 
static Transform SetLocalScale (this Transform transform, float? x=null, float? y=null, float? z=null)
 Sets the x/y/z transform.localScale using optional parameters, keeping all undefined values as they were before. Can be called with named parameters like transform.SetLocalScale(x: 5, z: 10), for example, only changing transform.localScale.x and z. More...
 
static Transform SetLossyScale (this Transform transform, float? x=null, float? y=null, float? z=null)
 Sets the x/y/z transform.lossyScale using optional parameters, keeping all undefined values as they were before. Can be called with named parameters like transform.SetLossyScale(x: 5, z: 10), for example, only changing transform.lossyScale.x and z. More...
 
static Transform SetEulerAngles (this Transform transform, float? x=null, float? y=null, float? z=null)
 Sets the x/y/z transform.eulerAngles using optional parameters, keeping all undefined values as they were before. Can be called with named parameters like transform.SetEulerAngles(x: 5, z: 10), for example, only changing transform.eulerAngles.x and z. More...
 
static Transform SetLocalEulerAngles (this Transform transform, float? x=null, float? y=null, float? z=null)
 Sets the x/y/z transform.localEulerAngles using optional parameters, keeping all undefined values as they were before. Can be called with named parameters like transform.SetLocalEulerAngles(x: 5, z: 10), for example, only changing transform.localEulerAngles.x and z. More...
 
static void AssignLayerToHierarchy (this GameObject gameObject, int layer)
 Assigns a layer to this GameObject and all its children recursively. More...
 
static void StripCloneFromName (this GameObject gameObject)
 When UnityEngine.Object.Instantiate(UnityEngine.Object) is called on a prefab named "Original", the resulting instance will be named "Original(Clone)". This method changes the name back to "Original" by stripping everything after and including the first "(Clone)" it finds. If no "(Clone)" is found, the name is left unchanged. More...
 
static string GetNameWithoutClone (this GameObject gameObject)
 When UnityEngine.Object.Instantiate(UnityEngine.Object) is called on a prefab named "Original", the resulting instance will be named "Original(Clone)". This method returns the name without "(Clone)" by stripping everything after and including the first "(Clone)" it finds. If no "(Clone)" is found, the name is returned unchanged. More...
 
static Vector2 Change2 (this Vector2 vector, float? x=null, float? y=null)
 Makes a copy of the Vector2 with changed x/y values, keeping all undefined values as they were before. Can be called with named parameters like vector.Change2(y: 5), for example, only changing the y component. More...
 
static Vector3 Change3 (this Vector3 vector, float? x=null, float? y=null, float? z=null)
 Makes a copy of the Vector3 with changed x/y/z values, keeping all undefined values as they were before. Can be called with named parameters like vector.Change3(x: 5, z: 10), for example, only changing the x and z components. More...
 
static Vector4 Change4 (this Vector4 vector, float? x=null, float? y=null, float? z=null, float? w=null)
 Makes a copy of the Vector4 with changed x/y/z/w values, keeping all undefined values as they were before. Can be called with named parameters like vector.Change4(x: 5, z: 10), for example, only changing the x and z components. More...
 
static Vector2 RotateRad (this Vector2 v, float angleRad)
 Rotates a Vector2. More...
 
static Vector2 RotateDeg (this Vector2 v, float angleDeg)
 Rotates a Vector2. More...
 
static Vector2 CreateVector2AngleRad (float angleRad)
 Creates a Vector2 with a length of 1 pointing towards a certain angle. More...
 
static Vector2 CreateVector2AngleDeg (float angleDeg)
 Creates a Vector2 with a length of 1 pointing towards a certain angle. More...
 
static float GetAngleRad (this Vector2 vector)
 Gets the rotation of a Vector2. More...
 
static float GetAngleDeg (this Vector2 vector)
 Gets the rotation of a Vector2. More...
 
static Vector2 EasedLerpVector2 (Vector2 current, Vector2 target, float percentPerSecond, float deltaTime=0f)
 Framerate-independent eased lerping to a target value, slowing down the closer it is. More...
 
static Vector3 EasedLerpVector3 (Vector3 current, Vector3 target, float percentPerSecond, float deltaTime=0f)
 Framerate-independent eased lerping to a target value, slowing down the closer it is. More...
 
static Vector4 EasedLerpVector4 (Vector4 current, Vector4 target, float percentPerSecond, float deltaTime=0f)
 Framerate-independent eased lerping to a target value, slowing down the closer it is. More...
 
static Color Change (this Color color, float? r=null, float? g=null, float? b=null, float? a=null)
 Makes a copy of the Color with changed r/g/b/a values, keeping all undefined values as they were before. Can be called with named parameters like color.Change(g: 0, a: 0.5), for example, only changing the g and a components. More...
 
static Color ChangeAlpha (this Color color, float a)
 Makes a copy of the vector with a changed alpha value. More...
 
static Color EasedLerpColor (Color current, Color target, float percentPerSecond, float deltaTime=0f)
 Framerate-independent eased lerping to a target value, slowing down the closer it is. More...
 
static Vector2 CalculateCentroid (this Vector2[] array)
 Calculates the average position of an array of Vector2. More...
 
static Vector3 CalculateCentroid (this Vector3[] array)
 Calculates the average position of an array of Vector3. More...
 
static Vector4 CalculateCentroid (this Vector4[] array)
 Calculates the average position of an array of Vector4. More...
 
static Vector2 CalculateCentroid (this List< Vector2 > list)
 Calculates the average position of a List of Vector2. More...
 
static Vector3 CalculateCentroid (this List< Vector3 > list)
 Calculates the average position of a List of Vector3. More...
 
static Vector4 CalculateCentroid (this List< Vector4 > list)
 Calculates the average position of a List of Vector4. More...
 
static Vector2 RandomPosition (this Rect rect, float extendDistance=0f)
 Extends/shrinks the rect by extendDistance to each side and gets a random position from the resulting rect. More...
 
static Rect RandomSubRect (this Rect rect, float width, float height)
 Gets a random subrect of the given width or height inside this rect. More...
 
static Vector2 Clamp2 (this Rect rect, Vector2 position, float extendDistance=0f)
 Extends/shrinks the rect by extendDistance to each side and then restricts the given vector to the resulting rect. More...
 
static Vector3 Clamp3 (this Rect rect, Vector3 position, float extendDistance=0f)
 Extends/shrinks the rect by extendDistance to each side and then restricts the given vector to the resulting rect. The z component is kept. More...
 
static Rect Extend (this Rect rect, float extendDistance)
 Extends/shrinks the rect by extendDistance to each side. More...
 
static bool Contains (this Rect rect, Vector2 position, float extendDistance)
 Extends/shrinks the rect by extendDistance to each side and then checks if a given point is inside the resulting rect. More...
 
static Vector2 [] GetCornerPoints (this Rect rect)
 Creates an array containing the four corner points of a Rect. More...
 
static bool PlayerPrefsGetBool (string key, bool defaultValue=false)
 Returns the value corresponding to the key in the preference file if it exists. If it doesn't exist, it will return defaultValue. (Internally, the value is stored as an int with either 0 or 1.) More...
 
static void PlayerPrefsSetBool (string key, bool value)
 Sets the value of the preference entry identified by the key. (Internally, the value is stored as an int with either 0 or 1.) More...
 
static bool ContainsLayer (this LayerMask mask, int layer)
 Is a specific layer actived in the given LayerMask? More...
 
static Bounds CombineColliderBounds (Collider[] colliders)
 Creates a Bounds encapsulating all given colliders bounds. More...
 
static void GetCapsuleCastData (CharacterController characterController, Vector3 origin, out Vector3 point1, out Vector3 point2, out float radius)
 Given a CharacterController and a point of origin (the lower point of the capsule), this returns the point1, point2 and radius needed to fill a CapsuleCast(). More...
 
static Vector2 CalculateViewportWorldSizeAtDistance (this Camera camera, float distance, float aspectRatio=0)
 Calculates the size of the viewport at a given distance from a perspective camera. More...
 

Properties

static Vector2 RandomOnUnitCircle [get]
 Gets a random Vector2 of length 1 pointing in a random direction. More...
 
static int RandomSign [get]
 Returns -1 or 1 with equal change. More...
 
static bool RandomBool [get]
 Returns true or false with equal chance. More...
 

Detailed Description

Provides a lot of convenience methods for handling Unity data types, either in the form of extension methods or as static helper methods.

Member Function Documentation

§ AssignLayerToHierarchy()

static void UnityUtilities.UnityHelper.AssignLayerToHierarchy ( this GameObject  gameObject,
int  layer 
)
static

Assigns a layer to this GameObject and all its children recursively.

Parameters
gameObjectThe GameObject to start at.
layerThe layer to set.

§ CalculateCentroid() [1/6]

static Vector2 UnityUtilities.UnityHelper.CalculateCentroid ( this Vector2 []  array)
static

Calculates the average position of an array of Vector2.

Parameters
arrayThe input array.
Returns
The average position.

§ CalculateCentroid() [2/6]

static Vector3 UnityUtilities.UnityHelper.CalculateCentroid ( this Vector3 []  array)
static

Calculates the average position of an array of Vector3.

Parameters
arrayThe input array.
Returns
The average position.

§ CalculateCentroid() [3/6]

static Vector4 UnityUtilities.UnityHelper.CalculateCentroid ( this Vector4 []  array)
static

Calculates the average position of an array of Vector4.

Parameters
arrayThe input array.
Returns
The average position.

§ CalculateCentroid() [4/6]

static Vector2 UnityUtilities.UnityHelper.CalculateCentroid ( this List< Vector2 >  list)
static

Calculates the average position of a List of Vector2.

Parameters
listThe input list.
Returns
The average position.

§ CalculateCentroid() [5/6]

static Vector3 UnityUtilities.UnityHelper.CalculateCentroid ( this List< Vector3 >  list)
static

Calculates the average position of a List of Vector3.

Parameters
listThe input list.
Returns
The average position.

§ CalculateCentroid() [6/6]

static Vector4 UnityUtilities.UnityHelper.CalculateCentroid ( this List< Vector4 >  list)
static

Calculates the average position of a List of Vector4.

Parameters
listThe input list.
Returns
The average position.

§ CalculateViewportWorldSizeAtDistance()

static Vector2 UnityUtilities.UnityHelper.CalculateViewportWorldSizeAtDistance ( this Camera  camera,
float  distance,
float  aspectRatio = 0 
)
static

Calculates the size of the viewport at a given distance from a perspective camera.

Parameters
cameraThe Camera.
distanceThe positive distance from the camera.
aspectRatioOptionally: An aspect ratio to use. If 0 is set, camera.aspect is used.
Returns
The size of the viewport at the given distance.

§ Change()

static Color UnityUtilities.UnityHelper.Change ( this Color  color,
float?  r = null,
float?  g = null,
float?  b = null,
float?  a = null 
)
static

Makes a copy of the Color with changed r/g/b/a values, keeping all undefined values as they were before. Can be called with named parameters like color.Change(g: 0, a: 0.5), for example, only changing the g and a components.

Parameters
colorThe Color to be copied with changed values.
rIf this is not null, the r component is set to this value.
gIf this is not null, the g component is set to this value.
bIf this is not null, the b component is set to this value.
aIf this is not null, the a component is set to this value.
Returns
A copy of the Color with changed values.

§ Change2()

static Vector2 UnityUtilities.UnityHelper.Change2 ( this Vector2  vector,
float?  x = null,
float?  y = null 
)
static

Makes a copy of the Vector2 with changed x/y values, keeping all undefined values as they were before. Can be called with named parameters like vector.Change2(y: 5), for example, only changing the y component.

Parameters
vectorThe Vector2 to be copied with changed values.
xIf this is not null, the x component is set to this value.
yIf this is not null, the y component is set to this value.
Returns
A copy of the Vector2 with changed values.

§ Change3()

static Vector3 UnityUtilities.UnityHelper.Change3 ( this Vector3  vector,
float?  x = null,
float?  y = null,
float?  z = null 
)
static

Makes a copy of the Vector3 with changed x/y/z values, keeping all undefined values as they were before. Can be called with named parameters like vector.Change3(x: 5, z: 10), for example, only changing the x and z components.

Parameters
vectorThe Vector3 to be copied with changed values.
xIf this is not null, the x component is set to this value.
yIf this is not null, the y component is set to this value.
zIf this is not null, the z component is set to this value.
Returns
A copy of the Vector3 with changed values.

§ Change4()

static Vector4 UnityUtilities.UnityHelper.Change4 ( this Vector4  vector,
float?  x = null,
float?  y = null,
float?  z = null,
float?  w = null 
)
static

Makes a copy of the Vector4 with changed x/y/z/w values, keeping all undefined values as they were before. Can be called with named parameters like vector.Change4(x: 5, z: 10), for example, only changing the x and z components.

Parameters
vectorThe Vector4 to be copied with changed values.
xIf this is not null, the x component is set to this value.
yIf this is not null, the y component is set to this value.
zIf this is not null, the z component is set to this value.
wIf this is not null, the w component is set to this value.
Returns
A copy of the Vector4 with changed values.

§ ChangeAlpha()

static Color UnityUtilities.UnityHelper.ChangeAlpha ( this Color  color,
float  a 
)
static

Makes a copy of the vector with a changed alpha value.

Parameters
colorThe Color to copy.
aThe new a component.
Returns
A copy of the Color with a changed alpha.

§ Clamp2()

static Vector2 UnityUtilities.UnityHelper.Clamp2 ( this Rect  rect,
Vector2  position,
float  extendDistance = 0f 
)
static

Extends/shrinks the rect by extendDistance to each side and then restricts the given vector to the resulting rect.

Parameters
rectThe Rect.
positionA position that should be restricted to the rect.
extendDistanceThe distance to extend/shrink the rect to each side.
Returns
The vector, clamped to the Rect.

§ Clamp3()

static Vector3 UnityUtilities.UnityHelper.Clamp3 ( this Rect  rect,
Vector3  position,
float  extendDistance = 0f 
)
static

Extends/shrinks the rect by extendDistance to each side and then restricts the given vector to the resulting rect. The z component is kept.

Parameters
rectThe Rect.
positionA position that should be restricted to the rect.
extendDistanceThe distance to extend/shrink the rect to each side.
Returns
The vector, clamped to the Rect.

§ CombineColliderBounds()

static Bounds UnityUtilities.UnityHelper.CombineColliderBounds ( Collider []  colliders)
static

Creates a Bounds encapsulating all given colliders bounds.

Parameters
collidersThe colliders.
Returns
A Bounds encapsulating all given colliders bounds.

§ Contains()

static bool UnityUtilities.UnityHelper.Contains ( this Rect  rect,
Vector2  position,
float  extendDistance 
)
static

Extends/shrinks the rect by extendDistance to each side and then checks if a given point is inside the resulting rect.

Parameters
rectThe Rect.
positionA position that should be restricted to the rect.
extendDistanceThe distance to extend/shrink the rect to each side.
Returns
True if the position is inside the extended rect.

§ ContainsLayer()

static bool UnityUtilities.UnityHelper.ContainsLayer ( this LayerMask  mask,
int  layer 
)
static

Is a specific layer actived in the given LayerMask?

Parameters
maskThe LayerMask.
layerThe layer to check for.
Returns
True if the layer is activated.

§ CopyPositionAndRotatationFrom()

static void UnityUtilities.UnityHelper.CopyPositionAndRotatationFrom ( this Transform  transform,
Transform  source 
)
static

Copies the position and rotation from another transform to this transform.

Parameters
transformThe transform to set the position/rotation at.
sourceThe transform to take the position/rotation from.

§ CreateVector2AngleDeg()

static Vector2 UnityUtilities.UnityHelper.CreateVector2AngleDeg ( float  angleDeg)
static

Creates a Vector2 with a length of 1 pointing towards a certain angle.

Parameters
angleDegThe angle in degrees.
Returns
The Vector2 pointing towards the angle.

§ CreateVector2AngleRad()

static Vector2 UnityUtilities.UnityHelper.CreateVector2AngleRad ( float  angleRad)
static

Creates a Vector2 with a length of 1 pointing towards a certain angle.

Parameters
angleRadThe angle in radians.
Returns
The Vector2 pointing towards the angle.

§ EasedLerpColor()

static Color UnityUtilities.UnityHelper.EasedLerpColor ( Color  current,
Color  target,
float  percentPerSecond,
float  deltaTime = 0f 
)
static

Framerate-independent eased lerping to a target value, slowing down the closer it is.

If you call

currentValue = UnityHelper.EasedLerpVector3(currentValue, Color.white, 0.75f);

each frame (e.g. in Update()), starting with a currentValue of Color.black, then after 1 second it will be approximately (0.75|0.75|0.75) - which is 75% of the way between Color.white and Color.black.

Adjusting the target or the percentPerSecond between calls is also possible.

Parameters
currentThe current value.
targetThe target value.
percentPerSecondHow much of the distance between current and target should be covered per second?
deltaTimeHow much time passed since the last call.
Returns
The interpolated value from current to target.

§ EasedLerpVector2()

static Vector2 UnityUtilities.UnityHelper.EasedLerpVector2 ( Vector2  current,
Vector2  target,
float  percentPerSecond,
float  deltaTime = 0f 
)
static

Framerate-independent eased lerping to a target value, slowing down the closer it is.

If you call

currentValue = UnityHelper.EasedLerpVector3(currentValue, Vector2.one, 0.75f);

each frame (e.g. in Update()), starting with a currentValue of Vector2.zero, then after 1 second it will be approximately (0.75|0.75) - which is 75% of the way between Vector2.zero and Vector2.one.

Adjusting the target or the percentPerSecond between calls is also possible.

Parameters
currentThe current value.
targetThe target value.
percentPerSecondHow much of the distance between current and target should be covered per second?
deltaTimeHow much time passed since the last call.
Returns
The interpolated value from current to target.

§ EasedLerpVector3()

static Vector3 UnityUtilities.UnityHelper.EasedLerpVector3 ( Vector3  current,
Vector3  target,
float  percentPerSecond,
float  deltaTime = 0f 
)
static

Framerate-independent eased lerping to a target value, slowing down the closer it is.

If you call

currentValue = UnityHelper.EasedLerpVector3(currentValue, Vector3.one, 0.75f);

each frame (e.g. in Update()), starting with a currentValue of Vector3.zero, then after 1 second it will be approximately (0.75|0.75|0.75) - which is 75% of the way between Vector3.zero and Vector3.one.

Adjusting the target or the percentPerSecond between calls is also possible.

Parameters
currentThe current value.
targetThe target value.
percentPerSecondHow much of the distance between current and target should be covered per second?
deltaTimeHow much time passed since the last call.
Returns
The interpolated value from current to target.

§ EasedLerpVector4()

static Vector4 UnityUtilities.UnityHelper.EasedLerpVector4 ( Vector4  current,
Vector4  target,
float  percentPerSecond,
float  deltaTime = 0f 
)
static

Framerate-independent eased lerping to a target value, slowing down the closer it is.

If you call

currentValue = UnityHelper.EasedLerpVector4(currentValue, Vector4.one, 0.75f);

each frame (e.g. in Update()), starting with a currentValue of Vector4.zero, then after 1 second it will be approximately (0.75|0.75|0.75) - which is 75% of the way between Vector4.zero and Vector4.one.

Adjusting the target or the percentPerSecond between calls is also possible.

Parameters
currentThe current value.
targetThe target value.
percentPerSecondHow much of the distance between current and target should be covered per second?
deltaTimeHow much time passed since the last call.
Returns
The interpolated value from current to target.

§ Extend()

static Rect UnityUtilities.UnityHelper.Extend ( this Rect  rect,
float  extendDistance 
)
static

Extends/shrinks the rect by extendDistance to each side.

Parameters
rectThe Rect.
extendDistanceThe distance to extend/shrink the rect to each side.
Returns
The rect, extended/shrunken by extendDistance to each side.

§ GetAngleDeg()

static float UnityUtilities.UnityHelper.GetAngleDeg ( this Vector2  vector)
static

Gets the rotation of a Vector2.

Parameters
vectorThe Vector2.
Returns
The rotation of the Vector2 in degrees.

§ GetAngleRad()

static float UnityUtilities.UnityHelper.GetAngleRad ( this Vector2  vector)
static

Gets the rotation of a Vector2.

Parameters
vectorThe Vector2.
Returns
The rotation of the Vector2 in radians.

§ GetCapsuleCastData()

static void UnityUtilities.UnityHelper.GetCapsuleCastData ( CharacterController  characterController,
Vector3  origin,
out Vector3  point1,
out Vector3  point2,
out float  radius 
)
static

Given a CharacterController and a point of origin (the lower point of the capsule), this returns the point1, point2 and radius needed to fill a CapsuleCast().

Parameters
characterControllerThe CharacterController to use as the capsule, providing scale, radius, height and center offset.
originThe capsule cast starting point at the lower end of the capsule.
point1Outputs the point1 parameter to be used in the CapsuleCast()
point2Outputs the point2 parameter to be used in the CapsuleCast()
radiusOutputs the radius parameter to be used in the CapsuleCast()

§ GetCornerPoints()

static Vector2 [] UnityUtilities.UnityHelper.GetCornerPoints ( this Rect  rect)
static

Creates an array containing the four corner points of a Rect.

Parameters
rectThe Rect.
Returns
An array containing the four corner points of the Rect.

§ GetNameWithoutClone()

static string UnityUtilities.UnityHelper.GetNameWithoutClone ( this GameObject  gameObject)
static

When UnityEngine.Object.Instantiate(UnityEngine.Object) is called on a prefab named "Original", the resulting instance will be named "Original(Clone)". This method returns the name without "(Clone)" by stripping everything after and including the first "(Clone)" it finds. If no "(Clone)" is found, the name is returned unchanged.

Parameters
gameObjectThe GameObject to return the original name of.

§ PlayerPrefsGetBool()

static bool UnityUtilities.UnityHelper.PlayerPrefsGetBool ( string  key,
bool  defaultValue = false 
)
static

Returns the value corresponding to the key in the preference file if it exists. If it doesn't exist, it will return defaultValue. (Internally, the value is stored as an int with either 0 or 1.)

Parameters
keyThe key.
defaultValueThe default value if none is given.
Returns
The value corresponding to key in the preference file if it exists, else the default value.

§ PlayerPrefsSetBool()

static void UnityUtilities.UnityHelper.PlayerPrefsSetBool ( string  key,
bool  value 
)
static

Sets the value of the preference entry identified by the key. (Internally, the value is stored as an int with either 0 or 1.)

Parameters
keyThe key.
valueThe value to set the preference entry to.

§ RandomPosition()

static Vector2 UnityUtilities.UnityHelper.RandomPosition ( this Rect  rect,
float  extendDistance = 0f 
)
static

Extends/shrinks the rect by extendDistance to each side and gets a random position from the resulting rect.

Parameters
rectThe Rect.
extendDistanceThe distance to extend/shrink the rect to each side.
Returns
A random position inside the extended rect.

§ RandomSubRect()

static Rect UnityUtilities.UnityHelper.RandomSubRect ( this Rect  rect,
float  width,
float  height 
)
static

Gets a random subrect of the given width or height inside this rect.

Parameters
rectThe Rect.
widthThe target width of the subrect. Clamped to the width of the given rect.
heightThe target height of the subrect. Clamped to the height of the given rect.
Returns
A random subrect with the given width and height.

§ RotateDeg()

static Vector2 UnityUtilities.UnityHelper.RotateDeg ( this Vector2  v,
float  angleDeg 
)
static

Rotates a Vector2.

Parameters
vThe Vector2 to rotate.
angleDegHow far to rotate the Vector2 in degrees.
Returns
The rotated Vector2.

§ RotateRad()

static Vector2 UnityUtilities.UnityHelper.RotateRad ( this Vector2  v,
float  angleRad 
)
static

Rotates a Vector2.

Parameters
vThe Vector2 to rotate.
angleRadHow far to rotate the Vector2 in radians.
Returns
The rotated Vector2.

§ SetEulerAngles()

static Transform UnityUtilities.UnityHelper.SetEulerAngles ( this Transform  transform,
float?  x = null,
float?  y = null,
float?  z = null 
)
static

Sets the x/y/z transform.eulerAngles using optional parameters, keeping all undefined values as they were before. Can be called with named parameters like transform.SetEulerAngles(x: 5, z: 10), for example, only changing transform.eulerAngles.x and z.

Parameters
transformThe transform to set the transform.eulerAngles at.
xIf this is not null, transform.eulerAngles.x is set to this value.
yIf this is not null, transform.eulerAngles.y is set to this value.
zIf this is not null, transform.eulerAngles.z is set to this value.
Returns
The transform itself.

§ SetLocalEulerAngles()

static Transform UnityUtilities.UnityHelper.SetLocalEulerAngles ( this Transform  transform,
float?  x = null,
float?  y = null,
float?  z = null 
)
static

Sets the x/y/z transform.localEulerAngles using optional parameters, keeping all undefined values as they were before. Can be called with named parameters like transform.SetLocalEulerAngles(x: 5, z: 10), for example, only changing transform.localEulerAngles.x and z.

Parameters
transformThe transform to set the transform.localEulerAngles at.
xIf this is not null, transform.localEulerAngles.x is set to this value.
yIf this is not null, transform.localEulerAngles.y is set to this value.
zIf this is not null, transform.localEulerAngles.z is set to this value.
Returns
The transform itself.

§ SetLocalPosition()

static Transform UnityUtilities.UnityHelper.SetLocalPosition ( this Transform  transform,
float?  x = null,
float?  y = null,
float?  z = null 
)
static

Sets the x/y/z transform.localPosition using optional parameters, keeping all undefined values as they were before. Can be called with named parameters like transform.SetLocalPosition(x: 5, z: 10), for example, only changing transform.localPosition.x and z.

Parameters
transformThe transform to set the transform.localPosition at.
xIf this is not null, transform.localPosition.x is set to this value.
yIf this is not null, transform.localPosition.y is set to this value.
zIf this is not null, transform.localPosition.z is set to this value.
Returns
The transform itself.

§ SetLocalScale()

static Transform UnityUtilities.UnityHelper.SetLocalScale ( this Transform  transform,
float?  x = null,
float?  y = null,
float?  z = null 
)
static

Sets the x/y/z transform.localScale using optional parameters, keeping all undefined values as they were before. Can be called with named parameters like transform.SetLocalScale(x: 5, z: 10), for example, only changing transform.localScale.x and z.

Parameters
transformThe transform to set the transform.localScale at.
xIf this is not null, transform.localScale.x is set to this value.
yIf this is not null, transform.localScale.y is set to this value.
zIf this is not null, transform.localScale.z is set to this value.
Returns
The transform itself.

§ SetLossyScale()

static Transform UnityUtilities.UnityHelper.SetLossyScale ( this Transform  transform,
float?  x = null,
float?  y = null,
float?  z = null 
)
static

Sets the x/y/z transform.lossyScale using optional parameters, keeping all undefined values as they were before. Can be called with named parameters like transform.SetLossyScale(x: 5, z: 10), for example, only changing transform.lossyScale.x and z.

Parameters
transformThe transform to set the transform.lossyScale at.
xIf this is not null, transform.lossyScale.x is set to this value.
yIf this is not null, transform.lossyScale.y is set to this value.
zIf this is not null, transform.lossyScale.z is set to this value.
Returns
The transform itself.

§ SetPosition()

static Transform UnityUtilities.UnityHelper.SetPosition ( this Transform  transform,
float?  x = null,
float?  y = null,
float?  z = null 
)
static

Sets the x/y/z transform.position using optional parameters, keeping all undefined values as they were before. Can be called with named parameters like transform.SetPosition(x: 5, z: 10), for example, only changing transform.position.x and z.

Parameters
transformThe transform to set the transform.position at.
xIf this is not null, transform.position.x is set to this value.
yIf this is not null, transform.position.y is set to this value.
zIf this is not null, transform.position.z is set to this value.
Returns
The transform itself.

§ StripCloneFromName()

static void UnityUtilities.UnityHelper.StripCloneFromName ( this GameObject  gameObject)
static

When UnityEngine.Object.Instantiate(UnityEngine.Object) is called on a prefab named "Original", the resulting instance will be named "Original(Clone)". This method changes the name back to "Original" by stripping everything after and including the first "(Clone)" it finds. If no "(Clone)" is found, the name is left unchanged.

Parameters
gameObjectThe GameObject to change the name of.

Property Documentation

§ RandomBool

bool UnityUtilities.UnityHelper.RandomBool
staticget

Returns true or false with equal chance.

§ RandomOnUnitCircle

Vector2 UnityUtilities.UnityHelper.RandomOnUnitCircle
staticget

Gets a random Vector2 of length 1 pointing in a random direction.

§ RandomSign

int UnityUtilities.UnityHelper.RandomSign
staticget

Returns -1 or 1 with equal change.


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