1 using System.Collections.Generic;
16 self.SetProperties(Vector3.zero, Quaternion.identity, Vector3.one);
23 public static void SetProperties(
this Transform
self, Transform properties)
25 self.SetProperties(properties.position, properties.rotation, properties.localScale);
33 public static void SetProperties(
this Transform
self, Vector3 position, Quaternion rotation, Vector3 scale)
35 self.position = position;
36 self.rotation = rotation;
37 self.localScale = scale;
44 public static void SetProperties(
this Transform
self, Quaternion rotation, Vector3 scale)
46 self.rotation = rotation;
47 self.localScale = scale;
54 public static void SetProperties(
this Transform
self, Vector3 position, Vector3 scale)
56 self.position = position;
57 self.localScale = scale;
64 public static void SetProperties(
this Transform
self, Vector3 position, Quaternion rotation)
66 self.position = position;
67 self.rotation = rotation;
77 return Quaternion.LookRotation(target -
self.position);
93 public static void LookAway(
this Transform
self, Vector3 target)
101 public static void LookAway(
this Transform
self, Transform target)
113 return Quaternion.LookRotation(
self.position - target);
130 public static void SetLerp(
this Transform
self, Transform a, Transform b,
float t)
132 self.SetProperties(Vector3.Lerp(a.position, b.position, t), Quaternion.Lerp(a.rotation, b.rotation, t), Vector3.Lerp(a.localScale, b.localScale, t));
142 Transform[] exceptionsArray = exceptions !=
null ? exceptions.ToArray() :
new Transform[0];
144 while ((exceptions ==
null &&
self.childCount > 0) || (exceptions !=
null &&
self.childCount > exceptionsArray.Length))
145 foreach (Transform child
in self)
146 if (exceptions ==
null || !exceptionsArray.Contains(child))
147 Object.DestroyImmediate(child.gameObject);
156 Transform[] exceptionsArray = exceptions !=
null ? exceptions.ToArray() :
new Transform[0];
159 foreach (Transform child
in self)
160 if (exceptions ==
null || !exceptionsArray.Contains(child))
161 Object.Destroy(child.gameObject);
Extensions for the Transform component
static void SetProperties(this Transform self, Vector3 position, Vector3 scale)
Sets the transform position and scale to the given values.
static Quaternion GetLookAtRotation(this Transform self, Transform target)
Find the rotation to look at a target.
static void DestroyAllChildren(this Transform self, IEnumerable< Transform > exceptions=null)
Destroys the children of a transform.
static Quaternion GetLookAwayRotation(this Transform self, Vector3 target)
Find the rotation to look in the opposite direction of the target.
static void SetLerp(this Transform self, Transform a, Transform b, float t)
Linearly interpolates between two transforms.
static void SetProperties(this Transform self, Vector3 position, Quaternion rotation)
Sets the transform position and rotation to the given values.
static void LookAway(this Transform self, Vector3 target)
Instantly look in the opposite direction of the target.
static void LookAway(this Transform self, Transform target)
Instantly look in the opposite direction of the target.
static Quaternion GetLookAwayRotation(this Transform self, Transform target)
Find the rotation to look away from a target transform.
static void SetProperties(this Transform self, Vector3 position, Quaternion rotation, Vector3 scale)
Sets the transform position, rotation and scale to the given values.
static void ResetTransform(this Transform self)
Sets the transform position, rotation and scale to the default values. Position = (0,...
static Quaternion GetLookAtRotation(this Transform self, Vector3 target)
Find the rotation to look at a target.
static void SetProperties(this Transform self, Transform properties)
Sets the transform position, rotation and scale to the same values in the given transform.
static void SetProperties(this Transform self, Quaternion rotation, Vector3 scale)
Sets the transform rotation and scale to the given values.
static void DestroyImmediateAllChildren(this Transform self, IEnumerable< Transform > exceptions=null)
Destroys immediately the children of a transform.