blob: 7286d44ce6dc9e274c9e93dfefccf15f7d1364c7 (
plain)
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
49
50
51
52
53
54
55
56
57
58
59
|
using UnityEngine;
using System.Collections;
public class Single<T> where T : new()
{
private static T s_instance;
public static T Instance
{
get { return GetInstance(); }
}
protected Single()
{
}
public static void CreateInstance()
{
if (s_instance == null)
{
s_instance = new T();
(s_instance as Single<T>).Init();
}
}
public static void DestroyInstance()
{
if (s_instance != null)
{
(s_instance as Single<T>).UnInit();
s_instance = default(T);
}
}
public static T GetInstance()
{
if (s_instance == null)
{
CreateInstance();
}
return s_instance;
}
public static bool HasInstance()
{
return (s_instance != null);
}
public virtual void Init()
{
}
public virtual void UnInit()
{
}
}
|