The HelperFunctions class provides a collection of utility methods for various common tasks in Unity, including UI interaction, timing, and children management. The class also includes helper methods for color conversion and working with Quaternions.
public static bool IsOverUI()Checks if the mouse is currently over a UI element.
public static WaitForSeconds GetWait(float time)Returns a cached WaitForSeconds object for the given time if available; otherwise, creates and returns a new one.
- time: The duration of the wait.
public static WaitForSecondsRealtime GetWaitRealTime(float time)Returns a cached WaitForSecondsRealtime object for the given time if available; otherwise, creates and returns a new one.
- time: The duration of the wait.
public static Transform GetRandomObject(List<Transform> list, Transform avoidedObject = null)Returns a random object from a list of Transforms, avoiding a specified object if provided.
- list: List of Transform objects to choose from.
- avoidedObject: (Optional) A Transform object to avoid.
public static void DestroyChildren(Transform parent)Destroys all children of the specified parent Transform.
public static void DestroyChildren(Transform parent, string tag, bool destroyWithoutTag = false)Destroys children under a given Transform parent based on a tag. If destroyWithoutTag is true, all children without the specified tag are destroyed.
- parent: The parent Transform.
- tag: The tag to filter children by.
- destroyWithoutTag: Whether to destroy children without the specified tag.
public static Transform GetFirstChildWithTag(Transform parent, string tag)Returns the first child of the parent Transform with the specified tag.
- parent: The parent Transform.
- tag: The tag to search for.
public static T GetFirstChildWithComponent<T>(Transform parent) where T : ComponentReturns the first child with the specified component, searched recursively.
- parent: The parent Transform.
- T: The type of component to search for.
public static List<Transform> GetChildren(Transform parent)Returns a list of all children of the parent Transform.
- parent: The parent Transform.
public static List<Transform> GetTransformsWithTag(List<Transform> list, string tag)Returns a list of Transforms from the input list that have the specified tag.
- list: List of Transform objects to filter.
- tag: The tag to filter by.
public static List<Transform> GetChildrenWithTag(Transform parent, string tag)Returns a list of children of the parent Transform that have the specified tag.
- parent: The parent Transform.
- tag: The tag to filter by.
public static List<Transform> GetTransformsWithComponent<T>(List<Transform> list) where T : ComponentReturns a list of Transforms from the input list that have the specified component attached.
- list: List of Transform objects to filter.
- T: The type of component to filter by.
public static List<Transform> GetChildrenWithComponent<T>(Transform parent) where T : ComponentReturns a list of children of the parent Transform that have the specified component attached.
- parent: The parent Transform.
- T: The type of component to filter by.
public static string ConvertToOrdinal(int number)Converts an integer to its ordinal representation (e.g., 1 -> 1st, 2 -> 2nd).
- number: The integer to convert.
public static string GetUUID()Generates a unique identifier (UUID).
public static long GetUnixTime(float hoursOffset = 0f)Returns the Unix timestamp, optionally offset by a specified number of hours.
- hoursOffset: The number of hours to offset the timestamp by.
public static Quaternion ReverseQuaternion(Quaternion quaternion)Returns the inverse of the given Quaternion.
- quaternion: The Quaternion to reverse.
public static Color HexToColor(string hex)Converts a hexadecimal color string to a Color object.
- hex: The hexadecimal color string (e.g., "#FFFFFF").
public class Singleton<T> : MonoBehaviour where T : MonoBehaviourA generic Singleton class for MonoBehaviour-based objects. Ensures that only one instance of a type exists.
- Instance: The Singleton instance.
protected virtual void Awake()Initializes the Singleton instance. If an instance already exists, destroys the new one.