namespace TPSBR { using System.Collections.Generic; using UnityEngine; public static partial class GameObjectExtensions { // PUBLIC METHODS public static T GetComponentNoAlloc(this GameObject gameObject) where T : class { return GameObjectExtensions.GetComponentNoAlloc(gameObject); } public static void SetActiveSafe(this GameObject gameObject, bool value) { if (gameObject == null) return; if (gameObject.activeSelf == value) return; gameObject.SetActive(value); } } public static partial class GameObjectExtensions where T : class { // PRIVATE MEMBERS private static List _components = new List(); // PUBLIC METHODS public static T GetComponentNoAlloc(GameObject gameObject) { _components.Clear(); gameObject.GetComponents(_components); if (_components.Count > 0) { T component = _components[0]; _components.Clear(); return component; } return null; } } }