using UnityEngine;
namespace MoreMountains.Tools
{
///
/// Singleton pattern.
///
public class MMSingleton : MonoBehaviour where T : Component
{
protected static T _instance;
///
/// Singleton design pattern
///
/// The instance.
public static T Instance
{
get
{
if (_instance == null)
{
_instance = FindObjectOfType ();
if (_instance == null)
{
GameObject obj = new GameObject ();
_instance = obj.AddComponent ();
}
}
return _instance;
}
}
///
/// On awake, we initialize our instance. Make sure to call base.Awake() in override if you need awake.
///
protected virtual void Awake ()
{
if (!Application.isPlaying)
{
return;
}
_instance = this as T;
}
}
}