using System.Collections; using System.Collections.Generic; using UnityEngine; public static class Extensions { #region Transform public static void SetTransform(this Transform current, SerializableTransform target) { current.localPosition = target.Position; current.localEulerAngles = target.Rotation; current.localScale = target.Scale; } public static void LerpTransform(this Transform current, SerializableTransform source, SerializableTransform target, float amount) { current.localPosition = Vector3.Lerp(source.Position, target.Position, amount); current.localEulerAngles = Quaternion.Lerp(Quaternion.Euler(source.Rotation), Quaternion.Euler(target.Rotation), amount).eulerAngles; current.localScale = Vector3.Lerp(source.Scale, target.Scale, amount); } public static void ResetTransform(this Transform trans) { trans.localPosition = Vector3.zero; trans.localEulerAngles = Vector3.zero; trans.localScale = Vector3.one; } #endregion #region GameObject public static GameObject CopyTransfrom(this GameObject go, GameObject other) { go.transform.position = other.transform.position; go.transform.rotation = other.transform.rotation; go.transform.localScale = other.transform.localScale; return go; } public static T Get(this GameObject go) { return go.GetComponent(); } public static T GetChild(this GameObject go) { return go.GetComponentInChildren(); } public static T[] GetChildren(this GameObject go) { return go.GetComponentsInChildren(); } #endregion }