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 { return instance; }
}
protected virtual void Awake()
{
if (instance == null)
{
instance = (T)this;
}else if (instance != this)
{
Destroy(this.gameObject);
}
}
protected virtual void OnDestry()
{
if (instance == this) instance = null;
}
public bool IsInitialized
{
get { return instance != null; }
}
}
泛型单例模板
最新推荐文章于 2024-07-14 13:39:50 发布