using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; public static class TransformUtility { /// /// Set Active state of the GameObject /// public static void SetActive(this Transform Target, bool Toggle) => Target.gameObject.SetActive(Toggle); /// Global Position Methods /// /// Reset Global position to (0,0,0) /// public static void ResetGlobalPos(this Transform Target) => Target.position = Vector3.zero; /// /// Sets Global Position on X and Z axis without changing Y. /// public static void SetGlobalPosXZ(this Transform target, Transform targetPos) => target.position = new Vector3(targetPos.position.x, target.position.y, targetPos.position.z); /// /// Set Global Position on X axis and the rest stay the same. /// public static void SetGlobalPosX(this Transform Target, float PosX) => Target.position = new Vector3(PosX, Target.position.y, Target.position.z); /// /// Set Global Position on Y axis and the rest stay the same. /// public static void SetGlobalPosY(this Transform Target, float PosY) => Target.position = new Vector3(Target.position.x, PosY, Target.position.z); /// /// Set Global Position on Z axis and the rest stay the same. /// public static void SetGlobalPosZ(this Transform Target, float PosZ) => Target.position = new Vector3(Target.position.x, Target.position.y, PosZ); /// Local Position Methods /// /// Reset Local position to (0,0,0) /// public static void ResetLocalPos(this Transform Target) => Target.localPosition = Vector3.zero; /// /// Set Local Position on X axis and the rest stay the same. /// public static void SetLocalPosX(this Transform Target, float PosX) => Target.localPosition = new Vector3(PosX, Target.localPosition.y, Target.localPosition.z); /// /// Set Local Position on Y axis and the rest stay the same. /// public static void SetLocalPosY(this Transform Target, float PosY) => Target.localPosition = new Vector3(Target.localPosition.x, PosY, Target.localPosition.z); /// /// Set Local Position on Z axis and the rest stay the same. /// public static void SetLocalPosZ(this Transform Target, float PosZ) => Target.localPosition = new Vector3(Target.localPosition.x, Target.localPosition.y, PosZ); /// /// Set Local Position on X axis and set the rest to zero. /// public static void SetOnlyLocalPosX(this Transform Target, float PosX) => Target.localPosition = Vector3.right * PosX; /// /// Set Local Position on Y axis and set the rest to zero. /// public static void SetOnlyLocalPosY(this Transform Target, float PosY) => Target.localPosition = Vector3.up * PosY; /// /// Set Local Position on Z axis and set the rest to zero. /// public static void SetOnlyLocalPosZ(this Transform Target, float PosZ) => Target.localPosition = Vector3.forward * PosZ; /// Global Rotation Methods /// /// Set Global Euler Angles on X axis and set the rest stay same. /// public static void SetGlobalEulerX(this Transform Target, float RotX) => Target.eulerAngles = new Vector3(RotX, Target.eulerAngles.y, Target.eulerAngles.z); /// /// Set Global Euler Angles on Y axis and set the rest stay same. /// public static void SetGlobalEulerY(this Transform Target, float RotY) => Target.eulerAngles = new Vector3(Target.eulerAngles.x, RotY, Target.eulerAngles.z); /// /// Set Global Euler Angles on Z axis and set the rest stay same. /// public static void SetGlobalEulerZ(this Transform Target, float RotZ) => Target.eulerAngles = new Vector3(Target.eulerAngles.x, Target.eulerAngles.y, RotZ); /// /// Set Global Euler Angles on X axis and set the rest to zero. /// public static void SetOnlyGlobalEulerX(this Transform Target, float RotX) => Target.eulerAngles = new Vector3(RotX, 0f, 0f); /// /// Set Global Euler Angles on Y axis and set the rest to zero. /// public static void SetOnlyGlobalEulerY(this Transform Target, float RotY) => Target.eulerAngles = new Vector3(0f, RotY, 0f); /// /// Set Global Euler Angles on Z axis and set the rest to zero. /// public static void SetOnlyGlobalEulerZ(this Transform Target, float RotZ) => Target.eulerAngles = new Vector3(0f, 0f, RotZ); /// Reset Local Rotation to (0,0,0) /// public static void ResetLocalRot(this Transform Target) => Target.localEulerAngles = Vector3.zero; /// Local Rotation Methods /// /// Set Local Euler Angles on X axis and set the rest stay same. /// public static void SetLocalEulerX(this Transform Target, float RotX) => Target.localEulerAngles = new Vector3(RotX, Target.localEulerAngles.y, Target.localEulerAngles.z); /// /// Set Local Euler Angles on Y axis and set the rest stay same. /// public static void SetLocalEulerY(this Transform Target, float RotY) => Target.localEulerAngles = new Vector3(Target.localEulerAngles.x, RotY, Target.localEulerAngles.z); /// /// Set Local Euler Angles on Z axis and set the rest stay same. /// public static void SetLocalEulerZ(this Transform Target, float RotZ) => Target.localEulerAngles = new Vector3(Target.localEulerAngles.x, Target.localEulerAngles.y, RotZ); /// /// Set Local Euler Angles on X axis and set the rest to zero. /// public static void SetOnlyLocalEulerX(this Transform Target, float RotX) => Target.localEulerAngles = new Vector3(RotX, 0f, 0f); /// /// Set Local Euler Angles on Y axis and set the rest to zero. /// public static void SetOnlyLocalEulerY(this Transform Target, float RotY) => Target.localEulerAngles = new Vector3(0f, RotY, 0f); /// /// Set Local Euler Angles on Z axis and set the rest to zero. /// public static void SetOnlyLocalEulerZ(this Transform Target, float RotZ) => Target.localEulerAngles = new Vector3(0f, 0f, RotZ); /// Scale Methods /// /// Reset Local Scale of Transform to (1,1,1) /// public static void ResetScale(this Transform Target) => Target.localScale = Vector3.one; /// Scale Methods /// /// Set Local Scale of Transform /// public static void SetScale(this Transform Target, float X = 1f, float Y = 1f, float Z = 1f) => Target.localScale = new Vector3(X, Y, Z); /// /// Set Local Scale on X Axis and rest stay the same /// public static void SetLocalScaleX(this Transform Target, float ScaleX) => Target.localScale = new Vector3(ScaleX, Target.localScale.y, Target.localScale.z); /// /// Set Local Scale on Y Axis and rest stay the same /// public static void SetLocalScaleY(this Transform Target, float ScaleY) => Target.localScale = new Vector3(Target.localScale.x, ScaleY, Target.localScale.z); /// /// Set Local Scale on Z Axis and rest stay the same /// public static void SetLocalScaleZ(this Transform Target, float ScaleZ) => Target.localScale = new Vector3(Target.localScale.x, Target.localScale.y, ScaleZ); }//class end public static class UI_Utility { public static void SetActive(this SpriteRenderer spriteRenderer, bool value) => spriteRenderer.gameObject.SetActive(value); public static void SetActive(this Image image, bool value) => image.gameObject.SetActive(value); public static void SetAlpha(this Image image, float value) => image.color = new Color(image.color.r, image.color.b, image.color.b, value); public static void SetActive(this Button button, bool value) => button.gameObject.SetActive(value); public static void SetActive(this TMP_Text text, bool value) => text.gameObject.SetActive(value); }//class end public static class ListUtility { /// /// Method returns the First element of the List. /// public static T First(this List list) { if (list.Count > 0) return list[0]; return default(T); }//Last() end /// /// Method returns the Last element of the List. /// public static T Last(this List list) { if (list.Count > 0) return list[list.Count - 1]; return default(T); }//Last() end }//class end