mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
28 lines
576 B
C#
28 lines
576 B
C#
namespace TEngineCore
|
|
{
|
|
/// <summary>
|
|
/// 通用单例,无需释放和销毁
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
public class Singleton<T> where T : new()
|
|
{
|
|
private static T _instance;
|
|
|
|
public static T Instance
|
|
{
|
|
get
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = new T();
|
|
}
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
public static T Active()
|
|
{
|
|
return Instance;
|
|
}
|
|
}
|
|
} |