-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSingleton.cs
48 lines (39 loc) · 1013 Bytes
/
Singleton.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
namespace Cnoom.UnityTool.SingletonUtils
{
public class Singleton<T> : ISingleton where T : Singleton<T>
{
#region Properties
public static T Instance
{
get
{
if(instance == null)
{
lock (singletonLock)
{
if(instance == null)
{
instance = SingletonCreator.CreateSingleton<T>();
}
}
}
return instance;
}
}
#endregion
public void Dispose()
{
instance = default;
}
public virtual void OnSingletonInit()
{
}
#region Fields
private static T instance;
/// <summary>
/// 线程锁
/// </summary>
private static readonly object singletonLock = new object();
#endregion
}
}