YanCheng_Metrology/Assets/Scripts/ProjectBase/BaseManager/BaseManager.cs

34 lines
680 B
C#

using System;
using System.Reflection;
using UnityEngine;
public abstract class BaseManager<T> where T : class
{
private static T instance;
protected static readonly object lockObj = new object();
public static T Instance
{
get
{
if (instance == null)
{
lock (lockObj)
{
if (instance == null)
{
instance = (T)Activator.CreateInstance(typeof(T), true);
}
}
}
return instance;
}
}
public virtual void Destroy()
{
instance = null;
}
}