TapCommon-Unity/Runtime/Internal/UI/Base/Singleton.cs

29 lines
666 B
C#
Raw Normal View History

2023-09-20 15:29:14 +08:00
using System;
namespace TapTap.UI
{
public class Singleton<T> where T : class
{
private static T _instance;
private static readonly object _lock = new object();
public static T Instance
{
get
{
if (_instance == null)
{
lock (_lock)
{
if (_instance == null)
{
_instance = (T)Activator.CreateInstance(typeof(T), true);
}
}
}
return _instance;
}
}
}
}