using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Singleton<T> : MonoBehaviour where T : Singleton<T>
{
private static T instance;
public static T Instance { get => instance; }
protected virtual void Awake()
{
if (instance != null)
Destroy(gameObject);
else
instance = (T)this;
}
public static bool IsInitialized
{
get { return instance != null; }
}
protected virtual void OnDestroy()
{
if(instance == this)
{
instance = null;
}
}
}
标签:System,instance,Unity,static,单例,泛型,using,null,public
From: https://www.cnblogs.com/AlexNJW/p/16785579.html