@chiyou/minigame-framework 1.2.61 → 1.2.62
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.
- package/package.json +1 -1
- package/src/Framework/Manager/AdMgr.ts +16 -5
- package/src/Framework/Manager/AudioMgr.ts +30 -21
- package/src/Framework/Manager/InputMgr.ts +3 -0
- package/src/Framework/Manager/LifeCycleMgr.ts +3 -0
- package/src/Framework/Manager/NodePoolMgr.ts +14 -3
- package/src/Framework/Manager/PrivacyMgr.ts +30 -7
- package/src/Framework/Manager/ResMgr.ts +3 -0
- package/src/Framework/Manager/SocialMgr.ts +3 -0
- package/src/Framework/Manager/SystemMgr.ts +3 -0
- package/src/Framework/Manager/TimerMgr.ts +3 -0
- package/src/Framework/Manager/UIMgr.ts +10 -2
- package/src/Framework/Manager/UserMgr.ts +20 -7
- package/src/Framework/Utils/ServiceLocator.ts +18 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { math, randomRangeInt, view } from 'cc';
|
|
2
2
|
import { LogUtils } from '../Utils/LogUtils';
|
|
3
3
|
import { FwkErrorCode } from '../Definition/FwkErrorDefinition';
|
|
4
|
-
import { AudioMgr } from './AudioMgr';
|
|
5
4
|
import { AdCallback, Ad_Record, InterstitialAd_Callback_Status, InterstitialAd_Record, RewardedVideoAd_Callback_Status, RewardedVideoAd_Record, AdSwitchType, AdType, BannerAd_Info, CustomAd_Info, BannerAd_PlatformInfo, CustomAd_PlatformInfo, InterstitialAd_Scene, RewardedVideoAd_Scene, AdPlatformSettingInfo, AdPlatformUnitInfo, AdDefinition } from '../Definition/AdDefinition';
|
|
6
5
|
import { PlatformID } from '../Definition/SystemDefinition';
|
|
7
|
-
import { UserMgr } from './UserMgr';
|
|
8
6
|
import { BaseMgr } from './BaseMgr';
|
|
9
7
|
import { AbsAdAdapter } from '../Adapter/AdAdapter/AbsAdAdapter';
|
|
10
8
|
import { AdAdapterWeiXin } from '../Adapter/AdAdapter/AdAdapterWeiXin';
|
|
@@ -18,6 +16,9 @@ import { AdAdapterTapTap } from '../Adapter/AdAdapter/AdAdapterTapTap';
|
|
|
18
16
|
import { AdAdapterVivo } from '../Adapter/AdAdapter/AdAdapterVivo';
|
|
19
17
|
import { AdAdapterXiaoMi } from '../Adapter/AdAdapter/AdAdapterXiaoMi';
|
|
20
18
|
import { AdAdapterZhiFuBao } from '../Adapter/AdAdapter/AdAdapterZhiFuBao';
|
|
19
|
+
import { ServiceLocator } from '../Utils/ServiceLocator';
|
|
20
|
+
import type { UserMgr } from './UserMgr';
|
|
21
|
+
import type { AudioMgr } from './AudioMgr';
|
|
21
22
|
|
|
22
23
|
/** 广告管理器 */
|
|
23
24
|
export class AdMgr extends BaseMgr {
|
|
@@ -77,6 +78,8 @@ export class AdMgr extends BaseMgr {
|
|
|
77
78
|
this.destroy();
|
|
78
79
|
return;
|
|
79
80
|
}
|
|
81
|
+
|
|
82
|
+
ServiceLocator.Instance.register("AdMgr", this);
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
/**
|
|
@@ -275,12 +278,18 @@ export class AdMgr extends BaseMgr {
|
|
|
275
278
|
}
|
|
276
279
|
|
|
277
280
|
if (res === RewardedVideoAd_Callback_Status.Status_Watching) {
|
|
278
|
-
|
|
281
|
+
let audioMgr = ServiceLocator.Instance.get<AudioMgr>("AudioMgr");
|
|
282
|
+
if (audioMgr) {
|
|
283
|
+
audioMgr.pauseMusic();
|
|
284
|
+
}
|
|
279
285
|
AdMgr.Instance.hideAllPermanentAd();
|
|
280
286
|
} else if (res === RewardedVideoAd_Callback_Status.Status_Complete ||
|
|
281
287
|
res === RewardedVideoAd_Callback_Status.Status_Giveup ||
|
|
282
288
|
res === RewardedVideoAd_Callback_Status.Status_Error) {
|
|
283
|
-
|
|
289
|
+
let audioMgr = ServiceLocator.Instance.get<AudioMgr>("AudioMgr");
|
|
290
|
+
if (audioMgr) {
|
|
291
|
+
audioMgr.resumeMusic();
|
|
292
|
+
}
|
|
284
293
|
AdMgr.Instance.showAllPermanentAd();
|
|
285
294
|
}
|
|
286
295
|
|
|
@@ -523,7 +532,9 @@ export class AdMgr extends BaseMgr {
|
|
|
523
532
|
launchNoAdInterval = adPlatformSettingInfo.launchNoAdInterval_interstitialAd;
|
|
524
533
|
|
|
525
534
|
interstitialAdIntervalBase = adPlatformSettingInfo.registerUser_interstitialAd_IntervalBase;
|
|
526
|
-
|
|
535
|
+
|
|
536
|
+
const userMgr = ServiceLocator.Instance.get<UserMgr>("UserMgr");
|
|
537
|
+
if (userMgr && userMgr.isNewUser()) {
|
|
527
538
|
interstitialAdIntervalBase = adPlatformSettingInfo.registerUser_interstitialAd_IntervalBase;
|
|
528
539
|
}
|
|
529
540
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { AudioClip, AudioSource } from "cc";
|
|
2
2
|
import { LogUtils } from "../Utils/LogUtils";
|
|
3
|
-
import { ResMgr } from "./ResMgr";
|
|
4
3
|
import { PlatformID } from "../Definition/SystemDefinition";
|
|
5
4
|
import { FrameworkBase } from "../Definition/FrameworkBase";
|
|
6
5
|
import { BaseMgr } from "./BaseMgr";
|
|
7
6
|
import { FwkErrorCode } from "../Definition/FwkErrorDefinition";
|
|
7
|
+
import { ServiceLocator } from "../Utils/ServiceLocator";
|
|
8
|
+
import type { ResMgr } from "./ResMgr";
|
|
8
9
|
|
|
9
10
|
/** 音频管理器 */
|
|
10
11
|
export class AudioMgr extends BaseMgr {
|
|
@@ -28,6 +29,8 @@ export class AudioMgr extends BaseMgr {
|
|
|
28
29
|
this.destroy();
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
32
|
+
|
|
33
|
+
ServiceLocator.Instance.register("AudioMgr", this);
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
/**
|
|
@@ -182,16 +185,19 @@ export class AudioMgr extends BaseMgr {
|
|
|
182
185
|
return;
|
|
183
186
|
}
|
|
184
187
|
|
|
185
|
-
let
|
|
186
|
-
if (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
188
|
+
let resMgr = ServiceLocator.Instance.get<ResMgr>("ResMgr");
|
|
189
|
+
if (resMgr) {
|
|
190
|
+
let audioClip: AudioClip = resMgr.getAsset("Sounds", url);
|
|
191
|
+
if (audioClip == null) {
|
|
192
|
+
LogUtils.Instance.error(AudioMgr.TAG, FwkErrorCode.Audio.LoadFailed, {
|
|
193
|
+
operation: "playEffect",
|
|
194
|
+
url: url,
|
|
195
|
+
reason: "资源未加载"
|
|
196
|
+
});
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
this.effectAudioSource.playOneShot(audioClip);
|
|
193
200
|
}
|
|
194
|
-
this.effectAudioSource.playOneShot(audioClip);
|
|
195
201
|
}
|
|
196
202
|
|
|
197
203
|
/**
|
|
@@ -275,18 +281,21 @@ export class AudioMgr extends BaseMgr {
|
|
|
275
281
|
return;
|
|
276
282
|
}
|
|
277
283
|
|
|
278
|
-
let
|
|
279
|
-
if (
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
284
|
+
let resMgr = ServiceLocator.Instance.get<ResMgr>("ResMgr");
|
|
285
|
+
if (resMgr) {
|
|
286
|
+
let audioClip: AudioClip = resMgr.getAsset("Sounds", url);
|
|
287
|
+
if (audioClip == null) {
|
|
288
|
+
LogUtils.Instance.error(AudioMgr.TAG, FwkErrorCode.Audio.LoadFailed, {
|
|
289
|
+
operation: "playMusic",
|
|
290
|
+
url: url,
|
|
291
|
+
reason: "资源未加载"
|
|
292
|
+
});
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
this.musicAudioSource.clip = audioClip;
|
|
288
296
|
|
|
289
|
-
|
|
297
|
+
this._playMusic();
|
|
298
|
+
}
|
|
290
299
|
}
|
|
291
300
|
|
|
292
301
|
/** 播放音乐(内部方法) */
|
|
@@ -3,6 +3,7 @@ import { BaseMgr } from './BaseMgr';
|
|
|
3
3
|
import { LogUtils } from '../Utils/LogUtils';
|
|
4
4
|
import { FwkErrorCode } from '../Definition/FwkErrorDefinition';
|
|
5
5
|
import { TimeUtils } from '../Utils/TimeUtils';
|
|
6
|
+
import { ServiceLocator } from '../Utils/ServiceLocator';
|
|
6
7
|
|
|
7
8
|
/** 键盘事件项 */
|
|
8
9
|
interface KeyboardEventItem {
|
|
@@ -201,6 +202,8 @@ export class InputMgr extends BaseMgr {
|
|
|
201
202
|
this.destroy();
|
|
202
203
|
return;
|
|
203
204
|
}
|
|
205
|
+
|
|
206
|
+
ServiceLocator.Instance.register("InputMgr", this);
|
|
204
207
|
}
|
|
205
208
|
|
|
206
209
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FrameworkBase } from "../Definition/FrameworkBase";
|
|
2
2
|
import { LogUtils } from "../Utils/LogUtils";
|
|
3
|
+
import { ServiceLocator } from "../Utils/ServiceLocator";
|
|
3
4
|
import { BaseMgr } from "./BaseMgr";
|
|
4
5
|
import { EventMgr } from "./EventMgr";
|
|
5
6
|
|
|
@@ -19,6 +20,8 @@ export class LifeCycleMgr extends BaseMgr {
|
|
|
19
20
|
this.destroy();
|
|
20
21
|
return;
|
|
21
22
|
}
|
|
23
|
+
|
|
24
|
+
ServiceLocator.Instance.register("LifeCycleMgr", this);
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
/**
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CCObject, Node, NodePool, Vec3 } from 'cc';
|
|
2
2
|
import { BaseMgr } from './BaseMgr';
|
|
3
3
|
import { LogUtils } from '../Utils/LogUtils';
|
|
4
|
-
import { UIMgr } from './UIMgr';
|
|
5
4
|
import { FwkErrorCode } from '../Definition/FwkErrorDefinition';
|
|
5
|
+
import { ServiceLocator } from '../Utils/ServiceLocator';
|
|
6
|
+
import type { UIMgr } from './UIMgr';
|
|
6
7
|
|
|
7
8
|
/** 节点池配置接口 */
|
|
8
9
|
export interface IPoolConfig {
|
|
@@ -77,6 +78,8 @@ export class NodePoolMgr extends BaseMgr {
|
|
|
77
78
|
this.destroy();
|
|
78
79
|
return;
|
|
79
80
|
}
|
|
81
|
+
|
|
82
|
+
ServiceLocator.Instance.register("NodePoolMgr", this);
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
/**
|
|
@@ -421,7 +424,12 @@ export class NodePoolMgr extends BaseMgr {
|
|
|
421
424
|
return null;
|
|
422
425
|
}
|
|
423
426
|
|
|
424
|
-
let
|
|
427
|
+
let uiMgr = ServiceLocator.Instance.get<UIMgr>("UIMgr");
|
|
428
|
+
if (!uiMgr) {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
let node: Node = uiMgr.create_ui(poolInfo.poolConfig.prefabUiName);
|
|
425
433
|
if (!node) {
|
|
426
434
|
LogUtils.Instance.error(NodePoolMgr.TAG, FwkErrorCode.NodePool.CreateFailed, {
|
|
427
435
|
operation: "_createNode",
|
|
@@ -454,7 +462,10 @@ export class NodePoolMgr extends BaseMgr {
|
|
|
454
462
|
|
|
455
463
|
let poolInfo: PoolInfo = this._poolInfoMap.get(poolName);
|
|
456
464
|
|
|
457
|
-
|
|
465
|
+
let uiMgr = ServiceLocator.Instance.get<UIMgr>("UIMgr");
|
|
466
|
+
if (uiMgr) {
|
|
467
|
+
uiMgr.destroy_ui(poolName, node);
|
|
468
|
+
}
|
|
458
469
|
|
|
459
470
|
if (poolInfo.poolConfig && poolInfo.poolConfig.enableDebug) {
|
|
460
471
|
this._printPoolState(poolName);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { LogUtils } from '../Utils/LogUtils';
|
|
2
2
|
import { AuthorizeResult, GetSettingResult, KindReminder, KindReminderType, PrivacyDefinition, PrivacyInfo, PrivacyPlatformInfo, PrivacyType, QueryPrivacyResult } from '../Definition/PrivacyDefinition';
|
|
3
3
|
import { FwkErrorCode } from '../Definition/FwkErrorDefinition';
|
|
4
|
-
import { UIMgr } from './UIMgr';
|
|
5
4
|
import { ToastDuration } from '../Definition/UIDefinition';
|
|
6
5
|
import { PlatformID } from '../Definition/SystemDefinition';
|
|
7
6
|
import { BaseMgr } from './BaseMgr';
|
|
8
7
|
import { FrameworkBase } from '../Definition/FrameworkBase';
|
|
8
|
+
import { ServiceLocator } from '../Utils/ServiceLocator';
|
|
9
|
+
import type { UIMgr } from './UIMgr';
|
|
9
10
|
|
|
10
11
|
/** 隐私协议管理器 */
|
|
11
12
|
export class PrivacyMgr extends BaseMgr {
|
|
@@ -28,6 +29,8 @@ export class PrivacyMgr extends BaseMgr {
|
|
|
28
29
|
this.destroy();
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
32
|
+
|
|
33
|
+
ServiceLocator.Instance.register("PrivacyMgr", this);
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
/**
|
|
@@ -172,9 +175,14 @@ export class PrivacyMgr extends BaseMgr {
|
|
|
172
175
|
return;
|
|
173
176
|
}
|
|
174
177
|
|
|
178
|
+
let uiMgr = ServiceLocator.Instance.get<UIMgr>("UIMgr");
|
|
179
|
+
|
|
175
180
|
this.getPlatformAdapter().requirePrivacyAuthorize((result) => {
|
|
176
181
|
if (!result) {
|
|
177
|
-
|
|
182
|
+
if (uiMgr) {
|
|
183
|
+
uiMgr.showToast("未同意隐私协议,无法使用" + featureName);
|
|
184
|
+
}
|
|
185
|
+
|
|
178
186
|
LogUtils.Instance.info(PrivacyMgr.TAG, "用户拒绝隐私授权", {
|
|
179
187
|
featureName: featureName,
|
|
180
188
|
privacyType: PrivacyType[privacyType],
|
|
@@ -187,7 +195,10 @@ export class PrivacyMgr extends BaseMgr {
|
|
|
187
195
|
let privacyPlatformInfo: PrivacyPlatformInfo = privacyInfo.privacyPlatformMap.get(this.getCurrentPlatformID());
|
|
188
196
|
let scopeDescription: string = privacyPlatformInfo?.scopeDescription || "未知";
|
|
189
197
|
if (privacyPlatformInfo === null || privacyPlatformInfo.scopeDisable) {
|
|
190
|
-
|
|
198
|
+
if (uiMgr) {
|
|
199
|
+
uiMgr.showToast("不支持[" + scopeDescription + "],无法使用" + featureName);
|
|
200
|
+
}
|
|
201
|
+
|
|
191
202
|
LogUtils.Instance.info(PrivacyMgr.TAG, "隐私功能不支持", {
|
|
192
203
|
featureName: featureName,
|
|
193
204
|
privacyType: PrivacyType[privacyType],
|
|
@@ -210,7 +221,10 @@ export class PrivacyMgr extends BaseMgr {
|
|
|
210
221
|
let scopeName: string = privacyPlatformInfo.scopeName;
|
|
211
222
|
this.getPlatformAdapter().getSetting(scopeName, (result: GetSettingResult) => {
|
|
212
223
|
if (result === GetSettingResult.Result_SettingNotAvailable) {
|
|
213
|
-
|
|
224
|
+
if (uiMgr) {
|
|
225
|
+
uiMgr.showToast("App版本过低,无法使用" + featureName, ToastDuration.Duration_Long);
|
|
226
|
+
}
|
|
227
|
+
|
|
214
228
|
LogUtils.Instance.info(PrivacyMgr.TAG, "隐私授权失败(版本不支持)", {
|
|
215
229
|
featureName: featureName,
|
|
216
230
|
privacyType: PrivacyType[privacyType],
|
|
@@ -219,7 +233,10 @@ export class PrivacyMgr extends BaseMgr {
|
|
|
219
233
|
callback(QueryPrivacyResult.Result_Invalid);
|
|
220
234
|
return;
|
|
221
235
|
} else if (result === GetSettingResult.Result_Rejected) {
|
|
222
|
-
|
|
236
|
+
if (uiMgr) {
|
|
237
|
+
uiMgr.showToast("右上角...设置,开启[" + scopeDescription + "]权限,即可使用" + featureName, ToastDuration.Duration_Long);
|
|
238
|
+
}
|
|
239
|
+
|
|
223
240
|
LogUtils.Instance.info(PrivacyMgr.TAG, "用户拒绝权限授权", {
|
|
224
241
|
featureName: featureName,
|
|
225
242
|
privacyType: PrivacyType[privacyType],
|
|
@@ -231,7 +248,10 @@ export class PrivacyMgr extends BaseMgr {
|
|
|
231
248
|
} else if (result === GetSettingResult.Result_NotExist_AuthorizeAvailable) {
|
|
232
249
|
this.getPlatformAdapter().authorize(scopeName, (result3) => {
|
|
233
250
|
if (result3 === AuthorizeResult.Result_AuthorizeNotAvailable) {
|
|
234
|
-
|
|
251
|
+
if (uiMgr) {
|
|
252
|
+
uiMgr.showToast("App版本过低,无法使用" + featureName, ToastDuration.Duration_Long);
|
|
253
|
+
}
|
|
254
|
+
|
|
235
255
|
LogUtils.Instance.info(PrivacyMgr.TAG, "授权失败(功能不可用)", {
|
|
236
256
|
featureName: featureName,
|
|
237
257
|
privacyType: PrivacyType[privacyType],
|
|
@@ -240,7 +260,10 @@ export class PrivacyMgr extends BaseMgr {
|
|
|
240
260
|
callback(QueryPrivacyResult.Result_Invalid);
|
|
241
261
|
return;
|
|
242
262
|
} else if (result3 === AuthorizeResult.Result_Rejected) {
|
|
243
|
-
|
|
263
|
+
if (uiMgr) {
|
|
264
|
+
uiMgr.showToast("右上角...设置,开启[" + scopeDescription + "]权限,即可使用" + featureName, ToastDuration.Duration_Long);
|
|
265
|
+
}
|
|
266
|
+
|
|
244
267
|
LogUtils.Instance.info(PrivacyMgr.TAG, "用户拒绝授权请求", {
|
|
245
268
|
featureName: featureName,
|
|
246
269
|
privacyType: PrivacyType[privacyType],
|
|
@@ -2,6 +2,7 @@ import { Asset, assetManager, AssetManager, ImageAsset } from 'cc';
|
|
|
2
2
|
import { FwkErrorCode } from '../Definition/FwkErrorDefinition';
|
|
3
3
|
import { LogUtils } from '../Utils/LogUtils';
|
|
4
4
|
import { BaseMgr } from './BaseMgr';
|
|
5
|
+
import { ServiceLocator } from '../Utils/ServiceLocator';
|
|
5
6
|
|
|
6
7
|
export type ResBatch = string;
|
|
7
8
|
|
|
@@ -130,6 +131,8 @@ export class ResMgr extends BaseMgr {
|
|
|
130
131
|
this.destroy();
|
|
131
132
|
return;
|
|
132
133
|
}
|
|
134
|
+
|
|
135
|
+
ServiceLocator.Instance.register("ResMgr", this);
|
|
133
136
|
}
|
|
134
137
|
|
|
135
138
|
/**
|
|
@@ -3,6 +3,7 @@ import { PlatformID } from "../Definition/SystemDefinition";
|
|
|
3
3
|
import { FwkErrorCode } from "../Definition/FwkErrorDefinition";
|
|
4
4
|
import { LogUtils } from "../Utils/LogUtils";
|
|
5
5
|
import { BaseMgr } from "./BaseMgr";
|
|
6
|
+
import { ServiceLocator } from "../Utils/ServiceLocator";
|
|
6
7
|
|
|
7
8
|
/** 社交功能管理器 */
|
|
8
9
|
export class SocialMgr extends BaseMgr {
|
|
@@ -23,6 +24,8 @@ export class SocialMgr extends BaseMgr {
|
|
|
23
24
|
this.destroy();
|
|
24
25
|
return;
|
|
25
26
|
}
|
|
27
|
+
|
|
28
|
+
ServiceLocator.Instance.register("SocialMgr", this);
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
/**
|
|
@@ -15,6 +15,7 @@ import { AppItem, CopyrightInfo, ICPItem, PlatformID } from "../Definition/Syste
|
|
|
15
15
|
import { FwkErrorCode } from "../Definition/FwkErrorDefinition";
|
|
16
16
|
import { LogUtils } from "../Utils/LogUtils";
|
|
17
17
|
import { BaseMgr } from "./BaseMgr";
|
|
18
|
+
import { ServiceLocator } from "../Utils/ServiceLocator";
|
|
18
19
|
|
|
19
20
|
/** 系统管理器 */
|
|
20
21
|
export class SystemMgr extends BaseMgr {
|
|
@@ -39,6 +40,8 @@ export class SystemMgr extends BaseMgr {
|
|
|
39
40
|
this.destroy();
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
43
|
+
|
|
44
|
+
ServiceLocator.Instance.register("SystemMgr", this);
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FwkErrorCode } from "../Definition/FwkErrorDefinition";
|
|
2
2
|
import { LogUtils } from "../Utils/LogUtils";
|
|
3
|
+
import { ServiceLocator } from "../Utils/ServiceLocator";
|
|
3
4
|
import { BaseMgr } from "./BaseMgr";
|
|
4
5
|
|
|
5
6
|
interface ITimer {
|
|
@@ -27,6 +28,8 @@ export class TimerMgr extends BaseMgr {
|
|
|
27
28
|
this.destroy();
|
|
28
29
|
return;
|
|
29
30
|
}
|
|
31
|
+
|
|
32
|
+
ServiceLocator.Instance.register("TimerMgr", this);
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
/**
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Component, Node, Button, Prefab, instantiate, screen, UITransform, v3, view, ResolutionPolicy, math, Tween, tween, Label, Color, Sprite, SpriteFrame, BlockInputEvents, Texture2D } from 'cc';
|
|
2
|
-
import { ResMgr } from './ResMgr';
|
|
3
2
|
import { FwkErrorCode } from '../Definition/FwkErrorDefinition';
|
|
4
3
|
import { LogUtils } from '../Utils/LogUtils';
|
|
5
4
|
import { ToastDuration } from '../Definition/UIDefinition';
|
|
6
5
|
import { BaseMgr } from './BaseMgr';
|
|
6
|
+
import { ServiceLocator } from '../Utils/ServiceLocator';
|
|
7
|
+
import type { ResMgr } from './ResMgr';
|
|
7
8
|
|
|
8
9
|
/** UI 控制器基类 */
|
|
9
10
|
export class UICtrl extends Component {
|
|
@@ -230,6 +231,8 @@ export class UIMgr extends BaseMgr {
|
|
|
230
231
|
this.destroy();
|
|
231
232
|
return;
|
|
232
233
|
}
|
|
234
|
+
|
|
235
|
+
ServiceLocator.Instance.register("UIMgr", this);
|
|
233
236
|
}
|
|
234
237
|
|
|
235
238
|
/**
|
|
@@ -260,7 +263,12 @@ export class UIMgr extends BaseMgr {
|
|
|
260
263
|
* @return UI 节点
|
|
261
264
|
*/
|
|
262
265
|
public create_ui(ui_name: string, parent?: Node): Node {
|
|
263
|
-
let
|
|
266
|
+
let resMgr = ServiceLocator.Instance.get<ResMgr>("ResMgr");
|
|
267
|
+
if (!resMgr) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
let uiPrefab: Prefab = resMgr.getAsset("GUI", "UIPrefabs/" + ui_name);
|
|
264
272
|
if (!uiPrefab) {
|
|
265
273
|
LogUtils.Instance.error(UIMgr.TAG, FwkErrorCode.UI.PrefabNotFound, {
|
|
266
274
|
operation: "create_ui",
|
|
@@ -5,12 +5,13 @@ import { LogUtils } from "../Utils/LogUtils";
|
|
|
5
5
|
import { BaseMgr } from "./BaseMgr";
|
|
6
6
|
import { PlatformID } from "../Definition/SystemDefinition";
|
|
7
7
|
import { AbsPlatformAdapter } from "../Adapter/PlatformAdapter/AbsPlatformAdapter";
|
|
8
|
-
import { TimerMgr } from "./TimerMgr";
|
|
9
8
|
import { ObjectUtils } from "../Utils/ObjectUtils";
|
|
10
9
|
import { EventMgr } from "./EventMgr";
|
|
11
10
|
import { TimeUtils } from "../Utils/TimeUtils";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
11
|
+
import { ServiceLocator } from "../Utils/ServiceLocator";
|
|
12
|
+
import type { AdMgr } from "./AdMgr";
|
|
13
|
+
import type { SocialMgr } from "./SocialMgr";
|
|
14
|
+
import type { TimerMgr } from "./TimerMgr";
|
|
14
15
|
|
|
15
16
|
/** 用户管理器 */
|
|
16
17
|
export class UserMgr extends BaseMgr {
|
|
@@ -59,13 +60,18 @@ export class UserMgr extends BaseMgr {
|
|
|
59
60
|
return;
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
ServiceLocator.Instance.register("UserMgr", this);
|
|
64
|
+
|
|
62
65
|
EventMgr.Instance.on(FrameworkBase.Message.LifeCycle_onGameHide, this.onGameHideCallback, this);
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
protected onDestroy(): void {
|
|
66
69
|
EventMgr.Instance.off(FrameworkBase.Message.LifeCycle_onGameHide, this.onGameHideCallback, this);
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
let timerMgr = ServiceLocator.Instance.get<TimerMgr>("TimerMgr");
|
|
72
|
+
if (timerMgr) {
|
|
73
|
+
timerMgr.removeTimer(this.autoSaveUserDataExecute, this);
|
|
74
|
+
}
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
/**
|
|
@@ -105,7 +111,10 @@ export class UserMgr extends BaseMgr {
|
|
|
105
111
|
}
|
|
106
112
|
|
|
107
113
|
if (this.userBehaviorPlatformInfo.autoSaveInterval > 0 && this.userBehaviorPlatformInfo.supportServerUserData) {
|
|
108
|
-
|
|
114
|
+
let timerMgr = ServiceLocator.Instance.get<TimerMgr>("TimerMgr");
|
|
115
|
+
if (timerMgr) {
|
|
116
|
+
timerMgr.addTimer(0, this.userBehaviorPlatformInfo.autoSaveInterval, -1, this.autoSaveUserDataExecute, this);
|
|
117
|
+
}
|
|
109
118
|
}
|
|
110
119
|
|
|
111
120
|
LogUtils.Instance.info(UserMgr.TAG, "初始化完成");
|
|
@@ -807,8 +816,12 @@ export class UserMgr extends BaseMgr {
|
|
|
807
816
|
return;
|
|
808
817
|
}
|
|
809
818
|
|
|
810
|
-
|
|
811
|
-
|
|
819
|
+
let adMgr = ServiceLocator.Instance.get<AdMgr>("AdMgr");
|
|
820
|
+
let socialMgr = ServiceLocator.Instance.get<SocialMgr>("SocialMgr");
|
|
821
|
+
if (adMgr && socialMgr) {
|
|
822
|
+
if (adMgr.isRewardedVideoAdShowing() && socialMgr.isSharing()) {
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
812
825
|
}
|
|
813
826
|
|
|
814
827
|
LogUtils.Instance.info(UserMgr.TAG, "onGameHide 保存用户数据");
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
export class ServiceLocator {
|
|
3
|
+
private static _instance: ServiceLocator = new ServiceLocator();
|
|
4
|
+
|
|
5
|
+
public static get Instance(): ServiceLocator {
|
|
6
|
+
return this._instance;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
private _services: Map<string, any> = new Map();
|
|
10
|
+
|
|
11
|
+
public register(name: string, service: any): void {
|
|
12
|
+
this._services.set(name, service);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public get<T>(name: string): T {
|
|
16
|
+
return this._services.get(name) as T;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ export { NumberUtils } from './Framework/Utils/NumberUtils';
|
|
|
29
29
|
export { ObjectUtils } from './Framework/Utils/ObjectUtils';
|
|
30
30
|
export { TimeUtils } from './Framework/Utils/TimeUtils';
|
|
31
31
|
export { TweenUtils, type AnimOptions, type EasingType, TweenSequence, TweenParallel } from './Framework/Utils/TweenUtils';
|
|
32
|
+
export { ServiceLocator } from './Framework/Utils/ServiceLocator';
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* TweenChain 使用示例:
|