26 lines
628 B
C#
26 lines
628 B
C#
![]() |
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.SceneManagement;
|
|||
|
|
|||
|
public class MonoSingleton<T> : MonoBehaviour where T : MonoBehaviour
|
|||
|
{
|
|||
|
private static T _instance;
|
|||
|
|
|||
|
public static T Instance
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_instance == null)
|
|||
|
{
|
|||
|
GameObject obj = new GameObject();
|
|||
|
obj.name = typeof(T).Name;
|
|||
|
GameObject.DontDestroyOnLoad(obj);
|
|||
|
T component = obj.AddComponent<T>();
|
|||
|
_instance = component;
|
|||
|
}
|
|||
|
return _instance;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|