Repository navigation
Expand file tree
/
Copy pathModuleBase.cs
More file actions
198 lines (168 loc) · 6.96 KB
/
Copy pathModuleBase.cs
File metadata and controls
198 lines (168 loc) · 6.96 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using UnityEngine;
namespace CP_SDK
{
/// <summary>
/// Module type
/// </summary>
public enum EIModuleBaseType
{
Integrated,
External
}
/// <summary>
/// Activation type kind
/// </summary>
public enum EIModuleBaseActivationType
{
Never,
OnStart,
OnMenuSceneLoaded
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Module base interface
/// </summary>
public interface IModuleBase
{
EIModuleBaseType Type { get; }
string Name { get; }
string FancyName { get; }
string Description { get; }
string DocumentationURL { get; }
bool UseChatFeatures { get; }
bool IsEnabled { get; set; }
EIModuleBaseActivationType ActivationType { get; }
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Set enabled
/// </summary>
/// <param name="p_Enabled"></param>
void SetEnabled(bool p_Enabled);
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Check for module activation
/// </summary>
/// <param name="p_Kind"></param>
void CheckForActivation(EIModuleBaseActivationType p_Kind);
/// <summary>
/// On application exit
/// </summary>
void OnApplicationExit();
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Get Module settings UI
/// </summary>
(UI.IViewController, UI.IViewController, UI.IViewController) GetSettingsViewControllers();
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Module base interface
/// </summary>
public abstract class ModuleBase<t_Type> : IModuleBase
where t_Type : ModuleBase<t_Type>, new()
{
public abstract EIModuleBaseType Type { get; }
public abstract string Name { get; }
public virtual string FancyName => Name;
public abstract string Description { get; }
public virtual string DocumentationURL => string.Empty;
public abstract bool UseChatFeatures { get; }
public abstract bool IsEnabled { get; set; }
public abstract EIModuleBaseActivationType ActivationType { get; }
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Singleton
/// </summary>
public static t_Type Instance { get; private set; } = null;
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Is enabled
/// </summary>
private bool m_WasEnabled = false;
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Set enabled
/// </summary>
/// <param name="p_Enabled"></param>
public void SetEnabled(bool p_Enabled)
{
IsEnabled = p_Enabled;
if (IsEnabled && !m_WasEnabled) Enable();
if (!IsEnabled && m_WasEnabled) Disable();
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Check for module activation
/// </summary>
/// <param name="p_Kind"></param>
public void CheckForActivation(EIModuleBaseActivationType p_Kind)
{
if (!m_WasEnabled && IsEnabled && ActivationType == p_Kind)
Enable();
}
/// <summary>
/// On application exit
/// </summary>
public void OnApplicationExit()
{
if (m_WasEnabled && IsEnabled)
Disable();
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Enable the Module
/// </summary>
internal void Enable()
{
if (m_WasEnabled)
return;
m_WasEnabled = true;
Instance = this as t_Type;
OnEnable();
}
/// <summary>
/// Disable the Module
/// </summary>
internal void Disable()
{
if (!m_WasEnabled)
return;
OnDisable();
Instance = null;
m_WasEnabled = false;
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Enable the Module
/// </summary>
protected abstract void OnEnable();
/// <summary>
/// Disable the Module
/// </summary>
protected abstract void OnDisable();
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Get Module settings UI
/// </summary>
public (UI.IViewController, UI.IViewController, UI.IViewController) GetSettingsViewControllers() => GetSettingsViewControllersImplementation();
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Get Module settings UI
/// </summary>
protected virtual (UI.IViewController, UI.IViewController, UI.IViewController) GetSettingsViewControllersImplementation()
=> (null, null, null);
}
}