This repository was archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathGameMode.cs
More file actions
176 lines (153 loc) · 5.77 KB
/
Copy pathGameMode.cs
File metadata and controls
176 lines (153 loc) · 5.77 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
//-----------------------------------------------------------------------
// <copyright>
// Copyright (c) 2018 wanderer. All rights reserved.
// </copyright>
// <describe> #游戏的管理类# </describe>
// <email> dutifulwanderer@gmail.com </email>
// <time> #2018年6月25日 12点06分# </time>
//-----------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using LitJson;
using UnityEngine;
namespace Wanderer.GameFramework
{
public partial class GameMode : MonoBehaviour
{
#region 属性
public static EventManager Event;
public static FSManager FSM;
public static DataTableManager DataTable;
public static NodeManager Node;
public static ResourceManager Resource;
public static UIManager UI;
public static WebRequestManager WebRequest;
public static AudioManager Audio;
public static LocalizationManager Localization;
public static SettingManager Setting;
public static SystemManager System;
public static NetworkManager Network;
public static PoolManager Pool;
public static DebuggerManager Debugger;
public static ConfigManager Config;
public static TimerManager Timer;
public static LiteDBManager LiteDB;
public static GameMode Self;
#region 资源
/// <summary>
/// 配置文件
/// </summary>
public TextAsset ConfigAsset;
private JsonData _configJsonData;
public JsonData ConfigJsonData
{
get
{
if (ConfigAsset == null || string.IsNullOrEmpty(ConfigAsset.text))
{
_configJsonData = null;
}
else
{
if (_configJsonData == null)
{
_configJsonData = JsonMapper.ToObject(ConfigAsset.text);
}
}
return _configJsonData;
}
set
{
_configJsonData = value;
}
}
#endregion
#region 回调
/// <summary>
/// 游戏进入后台时执行该方法 pause为true 切换回前台时pause为false
/// 强制暂停时,先 OnApplicationPause
/// </summary>
public static Action<bool> OnAppPause;
/// <summary>
/// 游戏失去焦点也就是进入后台时 focus为false 切换回前台时 focus为true
/// 重新“启动”手机时,OnApplicationFocus
/// </summary>
public static Action<bool> OnAppFocus;
#endregion
#endregion
IEnumerator Start()
{
GameMode.Self = this;
//默认不销毁
DontDestroyOnLoad(gameObject);
#region Module
//config 要特殊处理
Config = GameFrameworkMode.GetModule<ConfigManager>();
Config.SetData(ConfigAsset.text);
Setting = GameFrameworkMode.GetModule<SettingManager>();
Event = GameFrameworkMode.GetModule<EventManager>();
FSM = GameFrameworkMode.GetModule<FSManager>();
DataTable = GameFrameworkMode.GetModule<DataTableManager>();
Node = GameFrameworkMode.GetModule<NodeManager>();
Resource = GameFrameworkMode.GetModule<ResourceManager>();
UI = GameFrameworkMode.GetModule<UIManager>();
WebRequest = GameFrameworkMode.GetModule<WebRequestManager>();
Audio = GameFrameworkMode.GetModule<AudioManager>();
Localization = GameFrameworkMode.GetModule<LocalizationManager>();
System = GameFrameworkMode.GetModule<SystemManager>();
Network = GameFrameworkMode.GetModule<NetworkManager>();
Pool = GameFrameworkMode.GetModule<PoolManager>();
Debugger = GameFrameworkMode.GetModule<DebuggerManager>();
Timer = GameFrameworkMode.GetModule<TimerManager>();
LiteDB = GameFrameworkMode.GetModule<LiteDBManager>();
#endregion
#region resource
//添加对象池管理器
GameObject gameObjectPoolHelper = new GameObject("IGameObjectPoolHelper");
gameObjectPoolHelper.transform.SetParent(transform);
Resource.SetGameObjectPoolHelper(gameObjectPoolHelper.AddComponent<GameObjectPoolHelper>());
#endregion
#region state
//开启整个项目的流程
FSM.AddFSM<GameStateContext>();
// yield return new WaitForEndOfFrame();
GameFrameworkMode.Init();
FSM.GetFSM<GameStateContext>().OnBegin();
#endregion
yield return new WaitForEndOfFrame();
}
private void Update()
{
GameFrameworkMode.Update();
}
private void FixedUpdate()
{
GameFrameworkMode.FixedUpdate();
}
private void OnGUI()
{
GameFrameworkMode.ImGui();
}
private void OnDestroy()
{
GameFrameworkMode.ShutDown();
}
private void OnApplicationPause(bool pause)
{
OnAppPause?.Invoke(pause);
}
private void OnApplicationFocus(bool focus)
{
OnAppFocus?.Invoke(focus);
}
public static long GetCacheSize()
{
return GameFrameworkMode.GetCacheSize();
}
public static void ClearCache()
{
GameFrameworkMode.ClearCache();
}
}
}