You've already forked Darklings-FightingGame
mirror of
https://github.com/izzy2lost/Darklings-FightingGame.git
synced 2026-03-10 11:35:19 -07:00
41 lines
686 B
C#
41 lines
686 B
C#
using UnityEngine;
|
|
|
|
namespace Demonics.Manager
|
|
{
|
|
public class Singleton<T> : MonoBehaviour where T : MonoBehaviour
|
|
{
|
|
|
|
private static T _instance = null;
|
|
|
|
public static T Instance
|
|
{
|
|
get
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = FindObjectOfType<T>();
|
|
if (_instance == null)
|
|
{
|
|
var singletonObj = new GameObject();
|
|
singletonObj.name = typeof(T).ToString();
|
|
_instance = singletonObj.AddComponent<T>();
|
|
}
|
|
}
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
public virtual void Awake()
|
|
{
|
|
if (_instance != null)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
_instance = GetComponent<T>();
|
|
if (_instance == null)
|
|
return;
|
|
}
|
|
}
|
|
} |