Repository navigation
Expand file tree
/
Copy pathCSingletonBase.cs
More file actions
58 lines (47 loc) · 1.48 KB
/
Copy pathCSingletonBase.cs
File metadata and controls
58 lines (47 loc) · 1.48 KB
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
using UnityEngine;
using System.Collections;
public class CSingletonBase<CLASS_SingletoneTarget> : CObjectBase
where CLASS_SingletoneTarget : CSingletonBase<CLASS_SingletoneTarget>
{
static public CLASS_SingletoneTarget instance
{
get
{
if (_instance == null)
{
_instance = FindObjectOfType<CLASS_SingletoneTarget>();
if (_instance != null && _instance._bIsExcuteAwake == false)
_instance.OnAwake();
}
return _instance;
}
}
static private CLASS_SingletoneTarget _instance;
static private bool _bIsQuitApplication = false;
// ========================== [ Division ] ========================== //
protected override void OnAwake()
{
if (_bIsExcuteAwake == false)
{
if (_instance == null)
_instance = FindObjectOfType<CLASS_SingletoneTarget>();
}
base.OnAwake();
}
void OnDestroy()
{
_bIsExcuteAwake = false;
}
private void OnApplicationQuit()
{
_bIsQuitApplication = true;
}
// ========================== [ Division ] ========================== //
static public CLASS_SingletoneTarget EventMakeSingleton()
{
if (_bIsQuitApplication) return null;
if (_instance != null) return instance;
GameObject pObjectNewManager = new GameObject(typeof(CLASS_SingletoneTarget).ToString());
return pObjectNewManager.AddComponent<CLASS_SingletoneTarget>();
}
}