Unity Game Session MVP
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BrewMonster
|
||||
{
|
||||
public class MonoSingleton<T> : MonoBehaviour where T : MonoBehaviour
|
||||
{
|
||||
private static T _instance;
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = FindFirstObjectByType<T>();
|
||||
|
||||
if (_instance == null)
|
||||
{
|
||||
GameObject obj = new GameObject(typeof(T).Name);
|
||||
_instance = obj.AddComponent<T>();
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
_instance = this as T;
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/// <summary>Override this method to initialize the singleton</summary>
|
||||
protected virtual void Initialize()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user