using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
namespace MoreMountains.Tools
{
///
/// Game object extensions
///
public static class GameObjectExtensions
{
static List m_ComponentCache = new List();
///
/// Grabs a component without allocating memory uselessly
///
///
///
///
public static Component MMGetComponentNoAlloc(this GameObject @this, System.Type componentType)
{
@this.GetComponents(componentType, m_ComponentCache);
Component component = m_ComponentCache.Count > 0 ? m_ComponentCache[0] : null;
m_ComponentCache.Clear();
return component;
}
///
/// Grabs a component without allocating memory uselessly
///
///
///
///
public static T MMGetComponentNoAlloc(this GameObject @this) where T : Component
{
@this.GetComponents(typeof(T), m_ComponentCache);
Component component = m_ComponentCache.Count > 0 ? m_ComponentCache[0] : null;
m_ComponentCache.Clear();
return component as T;
}
}
}