namespace UnityEngine.Rendering
{
// Use this class to get a static instance of a component
// Mainly used to have a default instance
///
/// Singleton of a Component class.
///
/// Component type.
public static class ComponentSingleton
where TType : Component
{
static TType s_Instance = null;
///
/// Instance of the required component type.
///
public static TType instance
{
get
{
if (s_Instance == null)
{
GameObject go = new GameObject("Default " + typeof(TType)) { hideFlags = HideFlags.HideAndDontSave };
go.SetActive(false);
s_Instance = go.AddComponent();
}
return s_Instance;
}
}
}
}