Wizard_Of_Wak/Assets/1_Script/System/SingletonMonoBehaviour.cs

39 lines
754 B
C#

using UnityEngine;
public class SingletonMonoBehaviour<T> : MonoBehaviour where T : SingletonMonoBehaviour<T>
{
static public T Instance { get; private set; }
void Awake()
{
if (Instance == null)
{
Instance = (T)this;
OnAwake();
}
else
{
//Debug.Log("1개이상의 싱글턴이 존재합니다" + gameObject.name);
//Debug.Log("같은 함수가 들어간 싱글턴을 제거해 주세요");
Destroy(gameObject);
}
}
void Start()
{
if (Instance == (T)this)
{
OnStart();
}
}
virtual protected void OnAwake()
{
}
virtual protected void OnStart()
{
}
}