@chiyou/minigame-framework 1.2.69 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/package.json +1 -1
  2. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.ts +28 -2
  3. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.ts +8 -1
  4. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.ts +28 -2
  5. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.ts +31 -5
  6. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.ts +34 -1
  7. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.ts +28 -2
  8. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.ts +17 -2
  9. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.ts +31 -5
  10. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.ts +32 -4
  11. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.ts +28 -2
  12. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.ts +31 -5
  13. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.ts +31 -5
  14. package/src/Framework/Definition/EventDefinition.ts +7 -0
  15. package/src/Framework/Definition/SystemDefinition.ts +12 -1
  16. package/src/Framework/Definition/TimerDefinition.ts +9 -0
  17. package/src/Framework/Definition/UIDefinition.ts +6 -0
  18. package/src/Framework/Manager/AudioMgr.ts +56 -7
  19. package/src/Framework/Manager/EventMgr.ts +31 -0
  20. package/src/Framework/Manager/InputMgr.ts +61 -0
  21. package/src/Framework/Manager/NodePoolMgr.ts +83 -4
  22. package/src/Framework/Manager/ResMgr.ts +41 -2
  23. package/src/Framework/Manager/TimerMgr.ts +53 -3
  24. package/src/Framework/Manager/UIMgr.ts +89 -9
  25. package/src/Framework/Utils/LogUtils.ts +27 -0
  26. package/src/Framework/Utils/ObjectUtils.ts +111 -0
  27. package/src/index.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chiyou/minigame-framework",
3
- "version": "1.2.69",
3
+ "version": "1.3.1",
4
4
  "description": "基于 Cocos Creator 3.x 的小游戏开发框架,支持多平台发布",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -265,12 +265,38 @@ export class PlatformAdapterBilibili extends AbsPlatformAdapter {
265
265
  }
266
266
 
267
267
  public getScreenInfo(): ScreenInfo {
268
- let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0);
268
+ let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0, {
269
+ left: 0, right: 0, top: 0,bottom: 0,
270
+ width: 0, height: 0
271
+ });
269
272
 
270
273
  if (window["bl"] && window["bl"].getSystemInfoSync) {
271
274
  let systemInfo: any = window["bl"].getSystemInfoSync();
272
275
  if (systemInfo !== null) {
273
- screenInfo = new ScreenInfo(screenInfo.windowWidth, screenInfo.windowHeight, systemInfo.screenWidth, systemInfo.screenHeight);
276
+ screenInfo.screenWidth = systemInfo.screenWidth;
277
+ screenInfo.screenHeight = systemInfo.screenHeight;
278
+ screenInfo.windowWidth = systemInfo.windowWidth;
279
+ screenInfo.windowHeight = systemInfo.windowHeight;
280
+
281
+ if (systemInfo.safeArea !== null) {
282
+ screenInfo.safeArea = {
283
+ left: systemInfo.safeArea.left,
284
+ right: systemInfo.safeArea.right,
285
+ top: systemInfo.safeArea.top,
286
+ bottom: systemInfo.safeArea.bottom,
287
+ width: systemInfo.safeArea.width,
288
+ height: systemInfo.safeArea.height,
289
+ }
290
+ } else {
291
+ screenInfo.safeArea = {
292
+ left: 0,
293
+ right: systemInfo.screenWidth,
294
+ top: 0,
295
+ bottom: systemInfo.screenHeight,
296
+ width: systemInfo.screenWidth,
297
+ height: systemInfo.screenHeight,
298
+ }
299
+ }
274
300
  }
275
301
  }
276
302
 
@@ -113,7 +113,14 @@ export class PlatformAdapterDesktopBrowser extends AbsPlatformAdapter {
113
113
  }
114
114
 
115
115
  public getScreenInfo(): ScreenInfo {
116
- let screenInfo: ScreenInfo = new ScreenInfo(screen.width, screen.height, screen.width, screen.height);
116
+ let screenWidth = screen.width;
117
+ let screenHeight = screen.height;
118
+
119
+ let screenInfo: ScreenInfo = new ScreenInfo(
120
+ screenWidth, screenHeight, screenWidth, screenHeight, {
121
+ left: 0, right: screenWidth, top: 0,bottom: screenHeight,
122
+ width: screenWidth, height: screenHeight
123
+ });
117
124
 
118
125
  LogUtils.Instance.info(PlatformAdapterDesktopBrowser.TAG, "获取屏幕信息", {
119
126
  operation: "getScreenInfo",
@@ -281,12 +281,38 @@ export class PlatformAdapterDouYin extends AbsPlatformAdapter {
281
281
  }
282
282
 
283
283
  public getScreenInfo(): ScreenInfo {
284
- let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0);
284
+ let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0, {
285
+ left: 0, right: 0, top: 0,bottom: 0,
286
+ width: 0, height: 0
287
+ });
285
288
 
286
289
  if (window["tt"] && window["tt"].getSystemInfoSync) {
287
290
  let systemInfo: any = window["tt"].getSystemInfoSync();
288
291
  if (systemInfo !== null) {
289
- screenInfo = new ScreenInfo(systemInfo.windowWidth, systemInfo.windowHeight, systemInfo.screenWidth, systemInfo.screenHeight);
292
+ screenInfo.screenWidth = systemInfo.screenWidth;
293
+ screenInfo.screenHeight = systemInfo.screenHeight;
294
+ screenInfo.windowWidth = systemInfo.windowWidth;
295
+ screenInfo.windowHeight = systemInfo.windowHeight;
296
+
297
+ if (systemInfo.safeArea !== null) {
298
+ screenInfo.safeArea = {
299
+ left: systemInfo.safeArea.left,
300
+ right: systemInfo.safeArea.right,
301
+ top: systemInfo.safeArea.top,
302
+ bottom: systemInfo.safeArea.bottom,
303
+ width: systemInfo.safeArea.width,
304
+ height: systemInfo.safeArea.height,
305
+ }
306
+ } else {
307
+ screenInfo.safeArea = {
308
+ left: 0,
309
+ right: systemInfo.screenWidth,
310
+ top: 0,
311
+ bottom: systemInfo.screenHeight,
312
+ width: systemInfo.screenWidth,
313
+ height: systemInfo.screenHeight,
314
+ }
315
+ }
290
316
  }
291
317
  }
292
318
 
@@ -187,12 +187,38 @@ export class PlatformAdapterHonor extends AbsPlatformAdapter {
187
187
  }
188
188
 
189
189
  public getScreenInfo(): ScreenInfo {
190
- let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0);
190
+ let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0, {
191
+ left: 0, right: 0, top: 0,bottom: 0,
192
+ width: 0, height: 0
193
+ });
191
194
 
192
- if (window["qg"] && window["qg"].getWindowInfo) {
193
- let windowInfo: any = window["qg"].getWindowInfo();
194
- if (windowInfo !== null) {
195
- screenInfo = new ScreenInfo(windowInfo.windowWidth, windowInfo.windowHeight, windowInfo.screenWidth, windowInfo.screenHeight);
195
+ if (window["qg"] && window["qg"].getSystemInfoSync) {
196
+ let systemInfo: any = window["qg"].getSystemInfoSync();
197
+ if (systemInfo !== null) {
198
+ screenInfo.screenWidth = systemInfo.screenWidth;
199
+ screenInfo.screenHeight = systemInfo.screenHeight;
200
+ screenInfo.windowWidth = systemInfo.windowWidth;
201
+ screenInfo.windowHeight = systemInfo.windowHeight;
202
+
203
+ if (systemInfo.safeArea !== null) {
204
+ screenInfo.safeArea = {
205
+ left: systemInfo.safeArea.left,
206
+ right: systemInfo.safeArea.right,
207
+ top: systemInfo.safeArea.top,
208
+ bottom: systemInfo.safeArea.bottom,
209
+ width: systemInfo.safeArea.width,
210
+ height: systemInfo.safeArea.height,
211
+ }
212
+ } else {
213
+ screenInfo.safeArea = {
214
+ left: 0,
215
+ right: systemInfo.screenWidth,
216
+ top: 0,
217
+ bottom: systemInfo.screenHeight,
218
+ width: systemInfo.screenWidth,
219
+ height: systemInfo.screenHeight,
220
+ }
221
+ }
196
222
  }
197
223
  }
198
224
 
@@ -184,7 +184,40 @@ export class PlatformAdapterHuaWei extends AbsPlatformAdapter {
184
184
  }
185
185
 
186
186
  public getScreenInfo(): ScreenInfo {
187
- let screenInfo: ScreenInfo = new ScreenInfo(screen.availWidth, screen.availHeight, screen.width, screen.height);
187
+ let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0, {
188
+ left: 0, right: 0, top: 0,bottom: 0,
189
+ width: 0, height: 0
190
+ });
191
+
192
+ if (window["qg"] && window["qg"].getSystemInfoSync) {
193
+ let systemInfo: any = window["qg"].getSystemInfoSync();
194
+ if (systemInfo !== null) {
195
+ screenInfo.screenWidth = systemInfo.screenWidth;
196
+ screenInfo.screenHeight = systemInfo.screenHeight;
197
+ screenInfo.windowWidth = systemInfo.windowWidth;
198
+ screenInfo.windowHeight = systemInfo.windowHeight;
199
+
200
+ if (systemInfo.safeArea !== null) {
201
+ screenInfo.safeArea = {
202
+ left: systemInfo.safeArea.left,
203
+ right: systemInfo.safeArea.right,
204
+ top: systemInfo.safeArea.top,
205
+ bottom: systemInfo.safeArea.bottom,
206
+ width: systemInfo.safeArea.width,
207
+ height: systemInfo.safeArea.height,
208
+ }
209
+ } else {
210
+ screenInfo.safeArea = {
211
+ left: 0,
212
+ right: systemInfo.screenWidth,
213
+ top: 0,
214
+ bottom: systemInfo.screenHeight,
215
+ width: systemInfo.screenWidth,
216
+ height: systemInfo.screenHeight,
217
+ }
218
+ }
219
+ }
220
+ }
188
221
 
189
222
  LogUtils.Instance.info(PlatformAdapterHuaWei.TAG, "获取屏幕信息", {
190
223
  operation: "getScreenInfo",
@@ -222,12 +222,38 @@ export class PlatformAdapterKuaiShou extends AbsPlatformAdapter {
222
222
  }
223
223
 
224
224
  public getScreenInfo(): ScreenInfo {
225
- let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0);
225
+ let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0, {
226
+ left: 0, right: 0, top: 0,bottom: 0,
227
+ width: 0, height: 0
228
+ });
226
229
 
227
230
  if (window["ks"] && window["ks"].getSystemInfoSync) {
228
231
  let systemInfo: any = window["ks"].getSystemInfoSync();
229
232
  if (systemInfo !== null) {
230
- screenInfo = new ScreenInfo(systemInfo.windowWidth, systemInfo.windowHeight, systemInfo.screenWidth, systemInfo.screenHeight);
233
+ screenInfo.screenWidth = systemInfo.screenWidth;
234
+ screenInfo.screenHeight = systemInfo.screenHeight;
235
+ screenInfo.windowWidth = systemInfo.windowWidth;
236
+ screenInfo.windowHeight = systemInfo.windowHeight;
237
+
238
+ if (systemInfo.safeArea !== null) {
239
+ screenInfo.safeArea = {
240
+ left: systemInfo.safeArea.left,
241
+ right: systemInfo.safeArea.right,
242
+ top: systemInfo.safeArea.top,
243
+ bottom: systemInfo.safeArea.bottom,
244
+ width: systemInfo.safeArea.width,
245
+ height: systemInfo.safeArea.height,
246
+ }
247
+ } else {
248
+ screenInfo.safeArea = {
249
+ left: 0,
250
+ right: systemInfo.screenWidth,
251
+ top: 0,
252
+ bottom: systemInfo.screenHeight,
253
+ width: systemInfo.screenWidth,
254
+ height: systemInfo.screenHeight,
255
+ }
256
+ }
231
257
  }
232
258
  }
233
259
 
@@ -187,12 +187,27 @@ export class PlatformAdapterOppo extends AbsPlatformAdapter {
187
187
  }
188
188
 
189
189
  public getScreenInfo(): ScreenInfo {
190
- let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0);
190
+ let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0, {
191
+ left: 0, right: 0, top: 0,bottom: 0,
192
+ width: 0, height: 0
193
+ });
191
194
 
192
195
  if (window["qg"] && window["qg"].getSystemInfoSync) {
193
196
  let systemInfo: any = window["qg"].getSystemInfoSync();
194
197
  if (systemInfo !== null) {
195
- screenInfo = new ScreenInfo(systemInfo.windowWidth, systemInfo.windowHeight, systemInfo.screenWidth, systemInfo.screenHeight);
198
+ screenInfo.screenWidth = systemInfo.screenWidth;
199
+ screenInfo.screenHeight = systemInfo.screenHeight;
200
+ screenInfo.windowWidth = systemInfo.windowWidth;
201
+ screenInfo.windowHeight = systemInfo.windowHeight;
202
+
203
+ screenInfo.safeArea = {
204
+ left: 0,
205
+ right: systemInfo.screenWidth,
206
+ top: 0,
207
+ bottom: systemInfo.screenHeight,
208
+ width: systemInfo.screenWidth,
209
+ height: systemInfo.screenHeight,
210
+ }
196
211
  }
197
212
  }
198
213
 
@@ -202,12 +202,38 @@ export class PlatformAdapterTapTap extends AbsPlatformAdapter {
202
202
  }
203
203
 
204
204
  public getScreenInfo(): ScreenInfo {
205
- let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0);
205
+ let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0, {
206
+ left: 0, right: 0, top: 0,bottom: 0,
207
+ width: 0, height: 0
208
+ });
206
209
 
207
- if (window["tap"] && window["tap"].getSystemInfoSync) {
208
- let systemInfo: any = window["tap"].getSystemInfoSync();
209
- if (systemInfo !== null) {
210
- screenInfo = new ScreenInfo(systemInfo.windowWidth, systemInfo.windowHeight, systemInfo.screenWidth, systemInfo.screenHeight);
210
+ if (window["tap"] && window["tap"].getWindowInfo) {
211
+ let windowInfo: any = window["tap"].getWindowInfo();
212
+ if (windowInfo !== null) {
213
+ screenInfo.screenWidth = windowInfo.screenWidth;
214
+ screenInfo.screenHeight = windowInfo.screenHeight;
215
+ screenInfo.windowWidth = windowInfo.windowWidth;
216
+ screenInfo.windowHeight = windowInfo.windowHeight;
217
+
218
+ if (windowInfo.safeArea !== null) {
219
+ screenInfo.safeArea = {
220
+ left: windowInfo.safeArea.left,
221
+ right: windowInfo.safeArea.right,
222
+ top: windowInfo.safeArea.top,
223
+ bottom: windowInfo.safeArea.bottom,
224
+ width: windowInfo.safeArea.width,
225
+ height: windowInfo.safeArea.height,
226
+ }
227
+ } else {
228
+ screenInfo.safeArea = {
229
+ left: 0,
230
+ right: windowInfo.screenWidth,
231
+ top: 0,
232
+ bottom: windowInfo.screenHeight,
233
+ width: windowInfo.screenWidth,
234
+ height: windowInfo.screenHeight,
235
+ }
236
+ }
211
237
  }
212
238
  }
213
239
 
@@ -175,12 +175,40 @@ export class PlatformAdapterVivo extends AbsPlatformAdapter {
175
175
  }
176
176
 
177
177
  public getScreenInfo(): ScreenInfo {
178
- let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0);
178
+ let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0, {
179
+ left: 0, right: 0, top: 0,bottom: 0,
180
+ width: 0, height: 0
181
+ });
179
182
 
180
- if (window["qg"] && window["qg"].getWindowInfo) {
183
+ if (window["qg"] && window["qg"].getWindowInfo && window["qg"].getSystemInfoSync) {
184
+ let systemInfo: any = window["qg"].getSystemInfoSync();
181
185
  let windowInfo: any = window["qg"].getWindowInfo();
182
- if (windowInfo !== null) {
183
- screenInfo = new ScreenInfo(windowInfo.windowWidth, windowInfo.windowHeight, windowInfo.windowWidth, windowInfo.windowHeight);
186
+
187
+ if (windowInfo !== null && systemInfo !== null) {
188
+ screenInfo.screenWidth = systemInfo.screenWidth;
189
+ screenInfo.screenHeight = systemInfo.screenHeight;
190
+ screenInfo.windowWidth = windowInfo.windowWidth;
191
+ screenInfo.windowHeight = windowInfo.windowHeight;
192
+
193
+ if (windowInfo.safeArea !== null) {
194
+ screenInfo.safeArea = {
195
+ left: windowInfo.safeArea.left,
196
+ right: windowInfo.safeArea.right,
197
+ top: windowInfo.safeArea.top,
198
+ bottom: windowInfo.safeArea.bottom,
199
+ width: windowInfo.safeArea.width,
200
+ height: windowInfo.safeArea.height,
201
+ }
202
+ } else {
203
+ screenInfo.safeArea = {
204
+ left: 0,
205
+ right: systemInfo.screenWidth,
206
+ top: 0,
207
+ bottom: systemInfo.screenHeight,
208
+ width: systemInfo.screenWidth,
209
+ height: systemInfo.screenHeight,
210
+ }
211
+ }
184
212
  }
185
213
  }
186
214
 
@@ -342,12 +342,38 @@ export class PlatformAdapterWeiXin extends AbsPlatformAdapter {
342
342
  }
343
343
 
344
344
  public getScreenInfo(): ScreenInfo {
345
- let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0);
345
+ let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0, {
346
+ left: 0, right: 0, top: 0,bottom: 0,
347
+ width: 0, height: 0
348
+ });
346
349
 
347
350
  if (window["wx"] && window["wx"].getWindowInfo) {
348
351
  let windowInfo: any = window["wx"].getWindowInfo();
349
352
  if (windowInfo !== null) {
350
- screenInfo = new ScreenInfo(windowInfo.windowWidth, windowInfo.windowHeight, windowInfo.screenWidth, windowInfo.screenHeight);
353
+ screenInfo.screenWidth = windowInfo.screenWidth;
354
+ screenInfo.screenHeight = windowInfo.screenHeight;
355
+ screenInfo.windowWidth = windowInfo.windowWidth;
356
+ screenInfo.windowHeight = windowInfo.windowHeight;
357
+
358
+ if (windowInfo.safeArea !== null) {
359
+ screenInfo.safeArea = {
360
+ left: windowInfo.safeArea.left,
361
+ right: windowInfo.safeArea.right,
362
+ top: windowInfo.safeArea.top,
363
+ bottom: windowInfo.safeArea.bottom,
364
+ width: windowInfo.safeArea.width,
365
+ height: windowInfo.safeArea.height,
366
+ }
367
+ } else {
368
+ screenInfo.safeArea = {
369
+ left: 0,
370
+ right: windowInfo.screenWidth,
371
+ top: 0,
372
+ bottom: windowInfo.screenHeight,
373
+ width: windowInfo.screenWidth,
374
+ height: windowInfo.screenHeight,
375
+ }
376
+ }
351
377
  }
352
378
  }
353
379
 
@@ -182,12 +182,38 @@ export class PlatformAdapterXiaoMi extends AbsPlatformAdapter {
182
182
  }
183
183
 
184
184
  public getScreenInfo(): ScreenInfo {
185
- let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0);
185
+ let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0, {
186
+ left: 0, right: 0, top: 0,bottom: 0,
187
+ width: 0, height: 0
188
+ });
186
189
 
187
- if (window["qg"] && window["qg"].getWindowInfo) {
188
- let windowInfo: any = window["qg"].getWindowInfo();
189
- if (windowInfo !== null) {
190
- screenInfo = new ScreenInfo(windowInfo.windowWidth, windowInfo.windowHeight, windowInfo.windowWidth, windowInfo.windowHeight);
190
+ if (window["qg"] && window["qg"].getSystemInfoSync) {
191
+ let systemInfo: any = window["qg"].getSystemInfoSync();
192
+ if (systemInfo !== null) {
193
+ screenInfo.screenWidth = systemInfo.screenWidth;
194
+ screenInfo.screenHeight = systemInfo.screenHeight;
195
+ screenInfo.windowWidth = systemInfo.windowWidth;
196
+ screenInfo.windowHeight = systemInfo.windowHeight;
197
+
198
+ if (systemInfo.safeArea !== null) {
199
+ screenInfo.safeArea = {
200
+ left: systemInfo.safeArea.left,
201
+ right: systemInfo.safeArea.right,
202
+ top: systemInfo.safeArea.top,
203
+ bottom: systemInfo.safeArea.bottom,
204
+ width: systemInfo.safeArea.width,
205
+ height: systemInfo.safeArea.height,
206
+ }
207
+ } else {
208
+ screenInfo.safeArea = {
209
+ left: 0,
210
+ right: systemInfo.screenWidth,
211
+ top: 0,
212
+ bottom: systemInfo.screenHeight,
213
+ width: systemInfo.screenWidth,
214
+ height: systemInfo.screenHeight,
215
+ }
216
+ }
191
217
  }
192
218
  }
193
219
 
@@ -179,12 +179,38 @@ export class PlatformAdapterZhiFuBao extends AbsPlatformAdapter {
179
179
  }
180
180
 
181
181
  public getScreenInfo(): ScreenInfo {
182
- let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0);
182
+ let screenInfo: ScreenInfo = new ScreenInfo(0, 0, 0, 0, {
183
+ left: 0, right: 0, top: 0,bottom: 0,
184
+ width: 0, height: 0
185
+ });
183
186
 
184
- if (window["my"] && window["my"].getSystemInfoSync) {
185
- let systemInfo: any = window["my"].getSystemInfoSync();
186
- if (systemInfo !== null) {
187
- screenInfo = new ScreenInfo(systemInfo.windowWidth, systemInfo.windowHeight, systemInfo.screenWidth, systemInfo.screenHeight);
187
+ if (window["my"] && window["my"].getWindowInfo) {
188
+ let windowInfo: any = window["my"].getWindowInfo();
189
+ if (windowInfo !== null) {
190
+ screenInfo.screenWidth = windowInfo.screenWidth;
191
+ screenInfo.screenHeight = windowInfo.screenHeight;
192
+ screenInfo.windowWidth = windowInfo.windowWidth;
193
+ screenInfo.windowHeight = windowInfo.windowHeight;
194
+
195
+ if (windowInfo.safeArea !== null) {
196
+ screenInfo.safeArea = {
197
+ left: windowInfo.safeArea.left,
198
+ right: windowInfo.safeArea.right,
199
+ top: windowInfo.safeArea.top,
200
+ bottom: windowInfo.safeArea.bottom,
201
+ width: windowInfo.safeArea.width,
202
+ height: windowInfo.safeArea.height,
203
+ }
204
+ } else {
205
+ screenInfo.safeArea = {
206
+ left: 0,
207
+ right: windowInfo.screenWidth,
208
+ top: 0,
209
+ bottom: windowInfo.screenHeight,
210
+ width: windowInfo.screenWidth,
211
+ height: windowInfo.screenHeight,
212
+ }
213
+ }
188
214
  }
189
215
  }
190
216
 
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 事件监听者信息(调试用)
3
+ */
4
+ export interface EventListenerInfo {
5
+ callback: Function;
6
+ target: any;
7
+ }
@@ -25,17 +25,28 @@ export type AppItem = {
25
25
  appIDMap: Map<PlatformID, string>;
26
26
  }
27
27
 
28
+ export interface ISafeArea {
29
+ left: number; // 安全区左边界 X
30
+ right: number; // 安全区右边界 X
31
+ top: number; // 安全区上边界 Y(刘海高度)
32
+ bottom: number; // 安全区下边界 Y
33
+ width: number; // 安全区宽度,单位逻辑像素
34
+ height: number; // 安全区高度,单位逻辑像素
35
+ }
36
+
28
37
  export class ScreenInfo {
29
38
  windowWidth: number;
30
39
  windowHeight: number;
31
40
  screenWidth: number;
32
41
  screenHeight: number;
42
+ safeArea: ISafeArea;
33
43
 
34
- constructor(windowWidth: number, windowHeight: number, screenWidth: number, screenHeight: number) {
44
+ constructor(windowWidth: number, windowHeight: number, screenWidth: number, screenHeight: number, safeArea: ISafeArea) {
35
45
  this.windowWidth = windowWidth;
36
46
  this.windowHeight = windowHeight;
37
47
  this.screenWidth = screenWidth;
38
48
  this.screenHeight = screenHeight;
49
+ this.safeArea = safeArea;
39
50
  }
40
51
  }
41
52
 
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 定时器重复次数枚举
3
+ */
4
+ export enum TimerRepeat {
5
+ /** 只执行一次 */
6
+ Once = 1,
7
+ /** 无限循环 */
8
+ Infinite = -1,
9
+ }
@@ -2,4 +2,10 @@
2
2
  export enum ToastDuration {
3
3
  Duration_Short = 1,
4
4
  Duration_Long = 2,
5
+ }
6
+
7
+ export enum ToastPosition {
8
+ Top = 0,
9
+ Center = 1,
10
+ Bottom = 2,
5
11
  }
@@ -1,4 +1,4 @@
1
- import { AudioClip, AudioSource } from "cc";
1
+ import { AudioClip, AudioSource, Node } from "cc";
2
2
  import { LogUtils } from "../Utils/LogUtils";
3
3
  import { PlatformID } from "../Definition/SystemDefinition";
4
4
  import { FrameworkBase } from "../Definition/FrameworkBase";
@@ -15,7 +15,9 @@ export class AudioMgr extends BaseMgr {
15
15
  static TAG: string = "AudioMgr";
16
16
 
17
17
  private effectSwitch: boolean = false;
18
- private effectAudioSource: AudioSource = null;
18
+ private effectPool: AudioSource[] = [];
19
+ /** 音效池最大同时播放数量 */
20
+ private static readonly EFFECT_POOL_SIZE: number = 8;
19
21
 
20
22
  private musicSwitch: boolean = false;
21
23
  private musicAudioSource: AudioSource = null;
@@ -39,11 +41,11 @@ export class AudioMgr extends BaseMgr {
39
41
  * 初始化音频管理器
40
42
  */
41
43
  public init(): void {
42
- this.effectAudioSource = this.node.addComponent(AudioSource);
43
44
  this.musicAudioSource = this.node.addComponent(AudioSource);
44
45
 
46
+ this._initEffectPool();
47
+
45
48
  this.effectSwitch = false;
46
- this.effectAudioSource.volume = 0;
47
49
 
48
50
  this.musicSwitch = false;
49
51
  this.musicAudioSource.volume = 0;
@@ -163,7 +165,9 @@ export class AudioMgr extends BaseMgr {
163
165
  LogUtils.Instance.info(AudioMgr.TAG, "开启音效");
164
166
 
165
167
  this.effectSwitch = true;
166
- this.effectAudioSource.volume = 1;
168
+ for (let i = 0; i < this.effectPool.length; i++) {
169
+ this.effectPool[i].volume = 1;
170
+ }
167
171
  }
168
172
 
169
173
  /** 关闭音效 */
@@ -175,7 +179,52 @@ export class AudioMgr extends BaseMgr {
175
179
  LogUtils.Instance.info(AudioMgr.TAG, "关闭音效");
176
180
 
177
181
  this.effectSwitch = false;
178
- this.effectAudioSource.volume = 0;
182
+ for (let i = 0; i < this.effectPool.length; i++) {
183
+ this.effectPool[i].volume = 0;
184
+ }
185
+ }
186
+
187
+ /**
188
+ * 初始化音效池(内部方法)
189
+ */
190
+ private _initEffectPool(): void {
191
+ for (let i = 0; i < AudioMgr.EFFECT_POOL_SIZE; i++) {
192
+ let node: Node = new Node("EffectAudio_" + i);
193
+ node.setParent(this.node);
194
+ let audioSource: AudioSource = node.addComponent(AudioSource);
195
+ audioSource.volume = 0;
196
+ // 监听 ended 事件,播完后清 clip 以便下次复用
197
+ audioSource.node.on(AudioSource.EventType.ENDED, () => {
198
+ audioSource.clip = null;
199
+ });
200
+ this.effectPool.push(audioSource);
201
+ }
202
+ }
203
+
204
+ /**
205
+ * 从池中找空闲 AudioSource 播放音效(内部方法)
206
+ */
207
+ private _playEffectWithPool(clip: AudioClip): void {
208
+ // 找一个当前未在播放的 AudioSource
209
+ let audioSource: AudioSource = null;
210
+ for (let i = 0; i < this.effectPool.length; i++) {
211
+ if (!this.effectPool[i].playing) {
212
+ audioSource = this.effectPool[i];
213
+ break;
214
+ }
215
+ }
216
+
217
+ // 池已满,跳过此次播放
218
+ if (audioSource === null) {
219
+ LogUtils.Instance.warn(AudioMgr.TAG, "音效池已满(8个全部占用),跳过此次播放", {
220
+ operation: "_playEffectWithPool",
221
+ poolSize: this.effectPool.length
222
+ });
223
+ return;
224
+ }
225
+
226
+ audioSource.clip = clip;
227
+ audioSource.play();
179
228
  }
180
229
 
181
230
  /**
@@ -201,7 +250,7 @@ export class AudioMgr extends BaseMgr {
201
250
  });
202
251
  return;
203
252
  }
204
- this.effectAudioSource.playOneShot(audioClip);
253
+ this._playEffectWithPool(audioClip);
205
254
  }
206
255
  }
207
256