@chiyou/minigame-framework 1.4.7 → 1.4.9

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.
@@ -2,7 +2,7 @@ import { BannerAd_Info, BannerAd_PlatformInfo, InterstitialAd_Callback_Status, R
2
2
  import { PlatformID } from "../../Definition/SystemDefinition";
3
3
  import { LogUtils } from "../../Utils/LogUtils";
4
4
  import { FwkErrorCode } from "../../Definition/FwkErrorDefinition";
5
- import { AbsAdAdapter, CustomAdPosition, InterstitialAdStatus, RewardedVideoAdStatus } from "./AbsAdAdapter";
5
+ import { AbsAdAdapter, InterstitialAdStatus, RewardedVideoAdStatus } from "./AbsAdAdapter";
6
6
  import { TimeUtils } from "../../Utils/TimeUtils";
7
7
 
8
8
  class XMBannerAd {
@@ -65,7 +65,7 @@ class XMInterstitialAd {
65
65
  constructor(adUnitId: string, callback: Function) {
66
66
  this.unitId = adUnitId;
67
67
  this.ad = null;
68
- this.status = InterstitialAdStatus.Status_Init;
68
+ this.status = InterstitialAdStatus.Status_New;
69
69
  this.callback = callback;
70
70
  this.errorListener = null;
71
71
  this.loadListener = null;
@@ -109,7 +109,7 @@ class XMRewardedVideoAd {
109
109
  constructor(adUnitId: string, callback: Function) {
110
110
  this.unitId = adUnitId;
111
111
  this.ad = null;
112
- this.status = RewardedVideoAdStatus.Status_Destroyed;
112
+ this.status = RewardedVideoAdStatus.Status_New;
113
113
  this.callback = callback;
114
114
  this.errorListener = null;
115
115
  this.loadListener = null;
@@ -300,7 +300,8 @@ export class AdAdapterXiaoMi extends AbsAdAdapter {
300
300
  adUnitId: adUnitId,
301
301
  error: err
302
302
  });
303
- this.xmBannerAds[i].closeListener();
303
+
304
+ this.recreateBannerAd(this.xmBannerAds[i], 30, false);
304
305
  });
305
306
  break;
306
307
  }
@@ -365,8 +366,7 @@ export class AdAdapterXiaoMi extends AbsAdAdapter {
365
366
  reason: "平台API返回null",
366
367
  adUnitId: this.xmInterstitialAd.unitId
367
368
  });
368
- this.xmInterstitialAd.status = InterstitialAdStatus.Status_Error;
369
- this.xmInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Error);
369
+ this.xmInterstitialAd.callback(InterstitialAd_Callback_Status.Status_NotSupport);
370
370
  return;
371
371
  }
372
372
 
@@ -374,7 +374,7 @@ export class AdAdapterXiaoMi extends AbsAdAdapter {
374
374
  this.xmInterstitialAd.status = InterstitialAdStatus.Status_Init;
375
375
 
376
376
  this.xmInterstitialAd.errorListener = (err) => {
377
- LogUtils.Instance.error(AdAdapterXiaoMi.TAG, FwkErrorCode.XiaoMi_Ad.ShowFailed, {
377
+ LogUtils.Instance.error(AdAdapterXiaoMi.TAG, FwkErrorCode.XiaoMi_Ad.LoadFailed, {
378
378
  operation: "xmInterstitialAd.ad.onError",
379
379
  reason: "插屏广告加载失败",
380
380
  adUnitId: this.xmInterstitialAd.unitId,
@@ -382,7 +382,7 @@ export class AdAdapterXiaoMi extends AbsAdAdapter {
382
382
  });
383
383
 
384
384
  if (this.xmInterstitialAd.status !== InterstitialAdStatus.Status_Watching) {
385
- this.xmInterstitialAd.status = InterstitialAdStatus.Status_Error;
385
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_LoadError;
386
386
  this.xmInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Error);
387
387
  }
388
388
  };
@@ -437,7 +437,7 @@ export class AdAdapterXiaoMi extends AbsAdAdapter {
437
437
  break;
438
438
  case InterstitialAdStatus.Status_Watched:
439
439
  case InterstitialAdStatus.Status_Init:
440
- case InterstitialAdStatus.Status_Error:
440
+ case InterstitialAdStatus.Status_LoadError:
441
441
  this.createInterstitialAd();
442
442
  break;
443
443
  default:
@@ -511,8 +511,7 @@ export class AdAdapterXiaoMi extends AbsAdAdapter {
511
511
  reason: "平台API返回null",
512
512
  adUnitId: this.xmRewardedVideoAd.unitId
513
513
  });
514
- this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Error;
515
- this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Error);
514
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_NotSupport);
516
515
  return;
517
516
  }
518
517
 
@@ -520,7 +519,7 @@ export class AdAdapterXiaoMi extends AbsAdAdapter {
520
519
  this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Init;
521
520
 
522
521
  this.xmRewardedVideoAd.errorListener = (err) => {
523
- LogUtils.Instance.error(AdAdapterXiaoMi.TAG, FwkErrorCode.XiaoMi_Ad.ShowFailed, {
522
+ LogUtils.Instance.error(AdAdapterXiaoMi.TAG, FwkErrorCode.XiaoMi_Ad.LoadFailed, {
524
523
  operation: "xmRewardedVideoAd.ad.onError",
525
524
  reason: "激励视频广告加载失败",
526
525
  adUnitId: this.xmRewardedVideoAd.unitId,
@@ -528,8 +527,8 @@ export class AdAdapterXiaoMi extends AbsAdAdapter {
528
527
  });
529
528
 
530
529
  if (this.xmRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Watching) {
531
- this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Error;
532
- this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Error);
530
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_LoadError;
531
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_LoadError, err?.errCode, err?.errMsg);
533
532
  }
534
533
  };
535
534
  this.xmRewardedVideoAd.ad.onError(this.xmRewardedVideoAd.errorListener);
@@ -541,6 +540,7 @@ export class AdAdapterXiaoMi extends AbsAdAdapter {
541
540
  });
542
541
 
543
542
  this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Loaded;
543
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_LoadSuccess);
544
544
 
545
545
  if (this.xmRewardedVideoAd.isShowImmediately) {
546
546
  this.xmRewardedVideoAd.isShowImmediately = false;
@@ -559,9 +559,9 @@ export class AdAdapterXiaoMi extends AbsAdAdapter {
559
559
 
560
560
  this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Watched;
561
561
  if (isEnded) {
562
- this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Complete);
562
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Show_Complete);
563
563
  } else {
564
- this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Giveup);
564
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Show_Giveup);
565
565
  }
566
566
 
567
567
  this.scheduleOnce(() => {
@@ -598,7 +598,7 @@ export class AdAdapterXiaoMi extends AbsAdAdapter {
598
598
  this._showRewardedVideoAd();
599
599
  break;
600
600
  case RewardedVideoAdStatus.Status_Watched:
601
- case RewardedVideoAdStatus.Status_Error:
601
+ case RewardedVideoAdStatus.Status_LoadError:
602
602
  case RewardedVideoAdStatus.Status_Init:
603
603
  this._loadRewardedVideoAd(true);
604
604
  break;
@@ -641,12 +641,7 @@ export class AdAdapterXiaoMi extends AbsAdAdapter {
641
641
  this.xmRewardedVideoAd.ad.load().then(() => {
642
642
 
643
643
  }).catch((err) => {
644
- LogUtils.Instance.error(AdAdapterXiaoMi.TAG, FwkErrorCode.XiaoMi_Ad.LoadFailed, {
645
- operation: "xmRewardedVideoAd.ad.load",
646
- reason: "激励视频广告加载失败",
647
- adUnitId: this.xmRewardedVideoAd.unitId,
648
- error: err
649
- });
644
+
650
645
  });
651
646
  }
652
647
 
@@ -665,7 +660,7 @@ export class AdAdapterXiaoMi extends AbsAdAdapter {
665
660
 
666
661
  if (this.xmRewardedVideoAd.status === RewardedVideoAdStatus.Status_StartToWatch) {
667
662
  this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Watching;
668
- this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Watching);
663
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Show_Watching);
669
664
  }
670
665
  }).catch((err) => {
671
666
  LogUtils.Instance.error(AdAdapterXiaoMi.TAG, FwkErrorCode.XiaoMi_Ad.ShowFailed, {
@@ -16,7 +16,7 @@ class ZFBRewardedVideoAd {
16
16
  constructor(adUnitId: string, callback: Function) {
17
17
  this.unitId = adUnitId;
18
18
  this.ad = null;
19
- this.status = RewardedVideoAdStatus.Status_Destroyed;
19
+ this.status = RewardedVideoAdStatus.Status_New;
20
20
  this.callback = callback;
21
21
  this.errorListener = null;
22
22
  this.loadListener = null;
@@ -32,6 +32,7 @@ class ZFBRewardedVideoAd {
32
32
 
33
33
  this.ad = null;
34
34
  }
35
+ // 平台不提供 destory方法,所以这里不处理
35
36
  this.isShowImmediately = false;
36
37
  this.status = RewardedVideoAdStatus.Status_Destroyed;
37
38
  }
@@ -106,8 +107,7 @@ export class AdAdapterZhiFuBao extends AbsAdAdapter {
106
107
  reason: "平台API返回null",
107
108
  adUnitId: this.zfbRewardedVideoAd.unitId
108
109
  });
109
- this.zfbRewardedVideoAd.status = RewardedVideoAdStatus.Status_Error;
110
- this.zfbRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Error);
110
+ this.zfbRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_NotSupport);
111
111
  return;
112
112
  }
113
113
 
@@ -115,7 +115,7 @@ export class AdAdapterZhiFuBao extends AbsAdAdapter {
115
115
  this.zfbRewardedVideoAd.status = RewardedVideoAdStatus.Status_Init;
116
116
 
117
117
  this.zfbRewardedVideoAd.errorListener = (err) => {
118
- LogUtils.Instance.error(AdAdapterZhiFuBao.TAG, FwkErrorCode.ZhiFuBao_Ad.ShowFailed, {
118
+ LogUtils.Instance.error(AdAdapterZhiFuBao.TAG, FwkErrorCode.ZhiFuBao_Ad.LoadFailed, {
119
119
  operation: "zfbRewardedVideoAd.ad.onError",
120
120
  reason: "激励视频广告加载失败",
121
121
  adUnitId: this.zfbRewardedVideoAd.unitId,
@@ -123,8 +123,8 @@ export class AdAdapterZhiFuBao extends AbsAdAdapter {
123
123
  });
124
124
 
125
125
  if (this.zfbRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Watching) {
126
- this.zfbRewardedVideoAd.status = RewardedVideoAdStatus.Status_Error;
127
- this.zfbRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Error);
126
+ this.zfbRewardedVideoAd.status = RewardedVideoAdStatus.Status_LoadError;
127
+ this.zfbRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_LoadError, err?.error, err?.errorMessage);
128
128
  }
129
129
  };
130
130
  this.zfbRewardedVideoAd.ad.onError(this.zfbRewardedVideoAd.errorListener);
@@ -136,6 +136,7 @@ export class AdAdapterZhiFuBao extends AbsAdAdapter {
136
136
  });
137
137
 
138
138
  this.zfbRewardedVideoAd.status = RewardedVideoAdStatus.Status_Loaded;
139
+ this.zfbRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_LoadSuccess);
139
140
 
140
141
  if (this.zfbRewardedVideoAd.isShowImmediately) {
141
142
  this.zfbRewardedVideoAd.isShowImmediately = false;
@@ -155,9 +156,9 @@ export class AdAdapterZhiFuBao extends AbsAdAdapter {
155
156
 
156
157
  this.zfbRewardedVideoAd.status = RewardedVideoAdStatus.Status_Watched;
157
158
  if (isEnded) {
158
- this.zfbRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Complete);
159
+ this.zfbRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Show_Complete);
159
160
  } else {
160
- this.zfbRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Giveup);
161
+ this.zfbRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Show_Giveup);
161
162
  }
162
163
 
163
164
  this.scheduleOnce(() => {
@@ -194,7 +195,7 @@ export class AdAdapterZhiFuBao extends AbsAdAdapter {
194
195
  this._showRewardedVideoAd();
195
196
  break;
196
197
  case RewardedVideoAdStatus.Status_Watched:
197
- case RewardedVideoAdStatus.Status_Error:
198
+ case RewardedVideoAdStatus.Status_LoadError:
198
199
  case RewardedVideoAdStatus.Status_Init:
199
200
  this._loadRewardedVideoAd(true);
200
201
  break;
@@ -237,12 +238,7 @@ export class AdAdapterZhiFuBao extends AbsAdAdapter {
237
238
  this.zfbRewardedVideoAd.ad.load().then(() => {
238
239
 
239
240
  }).catch((err) => {
240
- LogUtils.Instance.error(AdAdapterZhiFuBao.TAG, FwkErrorCode.ZhiFuBao_Ad.LoadFailed, {
241
- operation: "zfbRewardedVideoAd.ad.load",
242
- reason: "激励视频广告加载失败",
243
- adUnitId: this.zfbRewardedVideoAd.unitId,
244
- error: err
245
- });
241
+
246
242
  });
247
243
  }
248
244
 
@@ -261,7 +257,7 @@ export class AdAdapterZhiFuBao extends AbsAdAdapter {
261
257
 
262
258
  if (this.zfbRewardedVideoAd.status === RewardedVideoAdStatus.Status_StartToWatch) {
263
259
  this.zfbRewardedVideoAd.status = RewardedVideoAdStatus.Status_Watching;
264
- this.zfbRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Watching);
260
+ this.zfbRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Show_Watching);
265
261
  }
266
262
  }).catch((err) => {
267
263
  LogUtils.Instance.error(AdAdapterZhiFuBao.TAG, FwkErrorCode.ZhiFuBao_Ad.ShowFailed, {
@@ -21,44 +21,6 @@ export class AdCallback {
21
21
  }
22
22
  }
23
23
 
24
- export class RewardedVideoAd_Record {
25
- clickCount: number;
26
- viewCount: number;
27
- completeCount: number;
28
- giveupCount: number;
29
- errorCount: number;
30
-
31
- constructor() {
32
- this.clickCount = 0;
33
- this.viewCount = 0;
34
- this.completeCount = 0;
35
- this.giveupCount = 0;
36
- this.errorCount = 0;
37
- }
38
- }
39
-
40
- export class InterstitialAd_Record {
41
- viewCount: number;
42
- completeCount: number;
43
- errorCount: number;
44
-
45
- constructor() {
46
- this.viewCount = 0;
47
- this.completeCount = 0;
48
- this.errorCount = 0;
49
- }
50
- }
51
-
52
- export class Ad_Record {
53
- intersitialAdRecord: Map<InterstitialAd_Scene, InterstitialAd_Record>;
54
- rewardedVideoAdRecord: Map<InterstitialAd_Scene, RewardedVideoAd_Record>;
55
-
56
- constructor() {
57
- this.intersitialAdRecord = new Map<InterstitialAd_Scene, InterstitialAd_Record>();
58
- this.rewardedVideoAdRecord = new Map<InterstitialAd_Scene, RewardedVideoAd_Record>();
59
- }
60
- }
61
-
62
24
  export enum InterstitialAd_Callback_Status {
63
25
  Status_NotSupport = -2,
64
26
  Status_Error = -1,
@@ -69,10 +31,11 @@ export enum InterstitialAd_Callback_Status {
69
31
 
70
32
  export enum RewardedVideoAd_Callback_Status {
71
33
  Status_NotSupport = -2,
72
- Status_Error = -1,
73
- Status_Complete = 0,
74
- Status_Giveup = 1,
75
- Status_Watching = 2,
34
+ Status_LoadError = -1,
35
+ Status_LoadSuccess = 0,
36
+ Status_Show_Watching = 1,
37
+ Status_Show_Complete = 2,
38
+ Status_Show_Giveup = 3,
76
39
  }
77
40
 
78
41
  export enum AdSwitchType {
@@ -92,7 +92,7 @@ export enum AnalyticsEventId {
92
92
  /** 广告观看完成(isEnded=true) */
93
93
  AdShowComplete = "ad_show_complete",
94
94
  /** 广告跳过(isEnded=false) */
95
- AdShowSkip = "ad_show_skip",
95
+ AdShowGiveup = "ad_show_giveup",
96
96
  }
97
97
 
98
98
  /** 关卡结束结果 */
@@ -38,7 +38,7 @@ export namespace FwkErrorCode {
38
38
  export const AdapterNotFound = 4003; // 04003 - 广告适配器未创建
39
39
  export const SwitchOff = 4004; // 04004 - 广告开关已关闭
40
40
  export const NotSupported = 4005; // 04005 - 广告类型不支持
41
- export const ShowFailed = 4006; // 04006 - 广告展示失败
41
+ export const LoadFailed = 4006; // 04006 - 广告加载失败
42
42
  }
43
43
 
44
44
  // 音频模块错误码(05xxx)
@@ -285,8 +285,8 @@ export const ErrorDescription: Record<number, string> = {
285
285
  [FwkErrorCode.Ad.AdapterNotFound]: "广告适配器未创建",
286
286
  [FwkErrorCode.Ad.SwitchOff]: "广告开关已关闭",
287
287
  [FwkErrorCode.Ad.NotSupported]: "广告类型不支持",
288
- [FwkErrorCode.Ad.ShowFailed]: "广告展示失败",
289
-
288
+ [FwkErrorCode.Ad.LoadFailed]: "广告加载失败",
289
+
290
290
  // 音频模块(05xxx)
291
291
  [FwkErrorCode.Audio.LoadFailed]: "音频加载失败",
292
292
  [FwkErrorCode.Audio.PlayFailed]: "音频播放失败",
@@ -1,7 +1,7 @@
1
1
  import { math, randomRangeInt, view } from 'cc';
2
2
  import { LogUtils } from '../Utils/LogUtils';
3
3
  import { FwkErrorCode } from '../Definition/FwkErrorDefinition';
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';
4
+ import { AdCallback, InterstitialAd_Callback_Status, RewardedVideoAd_Callback_Status, AdSwitchType, AdType, BannerAd_Info, CustomAd_Info, BannerAd_PlatformInfo, CustomAd_PlatformInfo, InterstitialAd_Scene, RewardedVideoAd_Scene, AdPlatformSettingInfo, AdPlatformUnitInfo, AdDefinition } from '../Definition/AdDefinition';
5
5
  import { PlatformID } from '../Definition/SystemDefinition';
6
6
  import { BaseMgr } from './BaseMgr';
7
7
  import { AbsAdAdapter } from '../Adapter/AdAdapter/AbsAdAdapter';
@@ -19,6 +19,7 @@ import { AdAdapterZhiFuBao } from '../Adapter/AdAdapter/AdAdapterZhiFuBao';
19
19
  import { ServiceLocator } from '../Utils/ServiceLocator';
20
20
  import type { UserMgr } from './UserMgr';
21
21
  import type { AudioMgr } from './AudioMgr';
22
+ import type { AnalyticsMgr } from './AnalyticsMgr';
22
23
 
23
24
  /** 广告管理器 */
24
25
  export class AdMgr extends BaseMgr {
@@ -61,16 +62,23 @@ export class AdMgr extends BaseMgr {
61
62
  /** 是否有常驻广告正在显示 */
62
63
  private static isPermanentAdShowing: boolean = false;
63
64
 
64
- /** 广告记录 */
65
- private static adRecord: Ad_Record = new Ad_Record();
66
-
67
65
  /** 内容区域顶部 */
68
66
  private static contentTop: number = 0;
69
67
  /** 内容区域底部 */
70
68
  private static contentBottom: number = 0;
71
69
 
70
+ private rewardedVideoAdCallbackToBusinessStatusSet: Set<RewardedVideoAd_Callback_Status> = new Set<RewardedVideoAd_Callback_Status>(
71
+ [
72
+ RewardedVideoAd_Callback_Status.Status_LoadError,
73
+ RewardedVideoAd_Callback_Status.Status_Show_Complete,
74
+ RewardedVideoAd_Callback_Status.Status_Show_Giveup,
75
+ RewardedVideoAd_Callback_Status.Status_Show_Watching,
76
+ ]
77
+ );
78
+
72
79
  private audioMgr: AudioMgr = null;
73
80
  private userMgr: UserMgr = null;
81
+ private _analyticsMgr: AnalyticsMgr = null;
74
82
 
75
83
  onLoad(): void {
76
84
  super.onLoad();
@@ -194,23 +202,20 @@ export class AdMgr extends BaseMgr {
194
202
  return 0;
195
203
  }
196
204
 
197
- this.clearAdRecord();
198
-
199
205
  AdMgr.nowRunningBannerAd = "";
200
206
  AdMgr.nowRunningCustomAd = "";
201
207
  AdMgr.isPermanentAdShowing = false;
202
208
 
203
209
  AdMgr.nowInterstitialAdScene = "InterstitialAd_Scene.Scene_Invalid";
204
- AdMgr.adRecord.intersitialAdRecord.set(AdMgr.nowInterstitialAdScene, new InterstitialAd_Record());
205
210
  AdMgr.interstitialAds = new Map<InterstitialAd_Scene, AdCallback>();
206
211
 
207
212
  AdMgr.interstitialAdCallback = function (res: InterstitialAd_Callback_Status) {
208
213
  if (res === InterstitialAd_Callback_Status.Status_Error) {
209
- LogUtils.Instance.error(AdMgr.TAG, FwkErrorCode.Ad.ShowFailed, {
214
+ LogUtils.Instance.error(AdMgr.TAG, FwkErrorCode.Ad.LoadFailed, {
210
215
  operation: "interstitialAdCallback",
211
216
  scene: AdMgr.nowInterstitialAdScene,
212
217
  result: InterstitialAd_Callback_Status[res],
213
- reason: "插屏广告展示失败"
218
+ reason: "插屏广告加载失败"
214
219
  });
215
220
  } else {
216
221
  LogUtils.Instance.info(AdMgr.TAG, "插屏广告回调", {
@@ -232,20 +237,6 @@ export class AdMgr extends BaseMgr {
232
237
  AdMgr.interstitialAd_nowIntervalCount = 1;
233
238
  }
234
239
 
235
- if (AdMgr.adRecord.intersitialAdRecord !== null &&
236
- AdMgr.adRecord.intersitialAdRecord.has(AdMgr.nowInterstitialAdScene) &&
237
- AdMgr.adRecord.intersitialAdRecord.get(AdMgr.nowInterstitialAdScene) !== null) {
238
- let record: InterstitialAd_Record = AdMgr.adRecord.intersitialAdRecord.get(AdMgr.nowInterstitialAdScene);
239
- if (res === InterstitialAd_Callback_Status.Status_Watching) {
240
- record.viewCount++;
241
- } else if (res === InterstitialAd_Callback_Status.Status_Error) {
242
- record.errorCount++;
243
- } else if (res === InterstitialAd_Callback_Status.Status_Close) {
244
- record.completeCount++;
245
- }
246
- AdMgr.adRecord.intersitialAdRecord.set(AdMgr.nowInterstitialAdScene, record);
247
- }
248
-
249
240
  if (AdMgr.interstitialAds !== null &&
250
241
  AdMgr.interstitialAds.has(AdMgr.nowInterstitialAdScene) &&
251
242
  AdMgr.interstitialAds.get(AdMgr.nowInterstitialAdScene) !== null) {
@@ -261,16 +252,44 @@ export class AdMgr extends BaseMgr {
261
252
  }
262
253
 
263
254
  AdMgr.nowRewardedVideoAdScene = "RewardedVideoAd_Scene.Scene_Invalid";
264
- AdMgr.adRecord.rewardedVideoAdRecord.set(AdMgr.nowRewardedVideoAdScene, new RewardedVideoAd_Record());
265
255
  AdMgr.rewardedVideoAds = new Map<RewardedVideoAd_Scene, AdCallback>();
266
256
 
267
- AdMgr.rewardedVideoAdCallback = function (res: RewardedVideoAd_Callback_Status) {
268
- if (res === RewardedVideoAd_Callback_Status.Status_Error) {
269
- LogUtils.Instance.error(AdMgr.TAG, FwkErrorCode.Ad.ShowFailed, {
257
+ AdMgr.rewardedVideoAdCallback = function (res: RewardedVideoAd_Callback_Status, errCode?: number, errMsg?: string) {
258
+ // ===== 友盟广告事件上报 =====
259
+ if (AdMgr.Instance._analyticsMgr === null) {
260
+ AdMgr.Instance._analyticsMgr = ServiceLocator.Instance.get<AnalyticsMgr>("AnalyticsMgr");
261
+ }
262
+ const analytics = AdMgr.Instance._analyticsMgr;
263
+ const scene = AdMgr.nowRewardedVideoAdScene;
264
+ switch (res) {
265
+ case RewardedVideoAd_Callback_Status.Status_LoadSuccess:
266
+ analytics?.trackAdLoadSuccess();
267
+ break;
268
+ case RewardedVideoAd_Callback_Status.Status_LoadError:
269
+ analytics?.trackAdLoadError(errCode ?? 0, errMsg ?? '');
270
+ break;
271
+ case RewardedVideoAd_Callback_Status.Status_Show_Watching:
272
+ analytics?.trackAdShow(scene);
273
+ break;
274
+ case RewardedVideoAd_Callback_Status.Status_Show_Complete:
275
+ analytics?.trackAdShowComplete(scene);
276
+ break;
277
+ case RewardedVideoAd_Callback_Status.Status_Show_Giveup:
278
+ analytics?.trackAdShowGiveup(scene);
279
+ break;
280
+ }
281
+ // ===== 友盟上报结束 =====
282
+
283
+ if (AdMgr.Instance.audioMgr === null) {
284
+ AdMgr.Instance.audioMgr = ServiceLocator.Instance.get<AudioMgr>("AudioMgr");
285
+ }
286
+
287
+ if (res === RewardedVideoAd_Callback_Status.Status_LoadError) {
288
+ LogUtils.Instance.error(AdMgr.TAG, FwkErrorCode.Ad.LoadFailed, {
270
289
  operation: "rewardedVideoAdCallback",
271
290
  scene: AdMgr.nowRewardedVideoAdScene,
272
291
  result: RewardedVideoAd_Callback_Status[res],
273
- reason: "激励视频广告展示失败"
292
+ reason: "激励视频广告加载失败"
274
293
  });
275
294
  } else {
276
295
  LogUtils.Instance.info(AdMgr.TAG, "激励视频广告回调", {
@@ -280,23 +299,15 @@ export class AdMgr extends BaseMgr {
280
299
  });
281
300
  }
282
301
 
283
- if (res === RewardedVideoAd_Callback_Status.Status_Watching) {
284
- if (AdMgr.Instance.audioMgr === null) {
285
- AdMgr.Instance.audioMgr = ServiceLocator.Instance.get<AudioMgr>("AudioMgr");
286
- }
287
-
302
+ if (res === RewardedVideoAd_Callback_Status.Status_Show_Watching) {
288
303
  if (AdMgr.Instance.audioMgr) {
289
304
  AdMgr.Instance.audioMgr.pauseMusic();
290
305
  }
291
306
 
292
307
  AdMgr.Instance.hideAllPermanentAd();
293
- } else if (res === RewardedVideoAd_Callback_Status.Status_Complete ||
294
- res === RewardedVideoAd_Callback_Status.Status_Giveup ||
295
- res === RewardedVideoAd_Callback_Status.Status_Error) {
296
- if (AdMgr.Instance.audioMgr === null) {
297
- AdMgr.Instance.audioMgr = ServiceLocator.Instance.get<AudioMgr>("AudioMgr");
298
- }
299
-
308
+ } else if (res === RewardedVideoAd_Callback_Status.Status_Show_Complete ||
309
+ res === RewardedVideoAd_Callback_Status.Status_Show_Giveup ||
310
+ res === RewardedVideoAd_Callback_Status.Status_LoadError) {
300
311
  if (AdMgr.Instance.audioMgr) {
301
312
  AdMgr.Instance.audioMgr.resumeMusic();
302
313
  }
@@ -304,36 +315,24 @@ export class AdMgr extends BaseMgr {
304
315
  AdMgr.Instance.showAllPermanentAd();
305
316
  }
306
317
 
307
- if (res === RewardedVideoAd_Callback_Status.Status_Complete) {
318
+ if (res === RewardedVideoAd_Callback_Status.Status_Show_Complete) {
308
319
  AdMgr.interstitialAd_nowIntervalCount++;
309
320
  }
310
321
 
311
- if (AdMgr.adRecord.rewardedVideoAdRecord !== null &&
312
- AdMgr.adRecord.rewardedVideoAdRecord.has(AdMgr.nowRewardedVideoAdScene) &&
313
- AdMgr.adRecord.rewardedVideoAdRecord.get(AdMgr.nowRewardedVideoAdScene) !== null) {
314
- let record: RewardedVideoAd_Record = AdMgr.adRecord.rewardedVideoAdRecord.get(AdMgr.nowRewardedVideoAdScene);
315
- if (res === RewardedVideoAd_Callback_Status.Status_Watching) {
316
- record.viewCount++;
317
- } else if (res === RewardedVideoAd_Callback_Status.Status_Complete) {
318
- record.completeCount++;
319
- } else if (res === RewardedVideoAd_Callback_Status.Status_Giveup) {
320
- record.giveupCount++;
321
- } else if (res === RewardedVideoAd_Callback_Status.Status_Error) {
322
- record.errorCount++;
322
+ if (AdMgr.Instance.rewardedVideoAdCallbackToBusinessStatusSet.has(res)) {
323
+ if (AdMgr.rewardedVideoAds !== null &&
324
+ AdMgr.rewardedVideoAds.has(AdMgr.nowRewardedVideoAdScene) &&
325
+ AdMgr.rewardedVideoAds.get(AdMgr.nowRewardedVideoAdScene) !== null) {
326
+ let adCallback: AdCallback = AdMgr.rewardedVideoAds.get(AdMgr.nowRewardedVideoAdScene);
327
+ if (adCallback.callback && adCallback.target) {
328
+ adCallback.callback.apply(adCallback.target, [res]);
329
+ }
323
330
  }
324
- AdMgr.adRecord.rewardedVideoAdRecord.set(AdMgr.nowRewardedVideoAdScene, record);
325
331
  }
326
332
 
327
- if (AdMgr.rewardedVideoAds !== null &&
328
- AdMgr.rewardedVideoAds.has(AdMgr.nowRewardedVideoAdScene) &&
329
- AdMgr.rewardedVideoAds.get(AdMgr.nowRewardedVideoAdScene) !== null) {
330
- let adCallback: AdCallback = AdMgr.rewardedVideoAds.get(AdMgr.nowRewardedVideoAdScene);
331
- if (adCallback.callback && adCallback.target) {
332
- adCallback.callback.apply(adCallback.target, [res]);
333
- }
334
- }
335
-
336
- if (res !== RewardedVideoAd_Callback_Status.Status_Watching) {
333
+ if (res === RewardedVideoAd_Callback_Status.Status_LoadError ||
334
+ res === RewardedVideoAd_Callback_Status.Status_Show_Complete ||
335
+ res === RewardedVideoAd_Callback_Status.Status_Show_Giveup) {
337
336
  AdMgr.nowRewardedVideoAdScene = "RewardedVideoAd_Scene.Scene_Invalid";
338
337
  }
339
338
  }
@@ -424,6 +423,7 @@ export class AdMgr extends BaseMgr {
424
423
  if (portalAd !== null && portalAd.length > 0) {
425
424
  return true;
426
425
  }
426
+ return false;
427
427
  default:
428
428
  return false;
429
429
  }
@@ -521,15 +521,14 @@ export class AdMgr extends BaseMgr {
521
521
  return;
522
522
  }
523
523
 
524
- if (scene === "" || scene === "InterstitialAd_Scene.Scene_Invalid") {
524
+ if (this.getAdAdapter() === null) {
525
525
  return;
526
526
  }
527
- AdMgr.nowInterstitialAdScene = scene;
528
527
 
529
- if (!AdMgr.adRecord.intersitialAdRecord.has(AdMgr.nowInterstitialAdScene) ||
530
- AdMgr.adRecord.intersitialAdRecord.get(AdMgr.nowInterstitialAdScene) === null) {
531
- AdMgr.adRecord.intersitialAdRecord.set(AdMgr.nowInterstitialAdScene, new InterstitialAd_Record());
528
+ if (scene === "" || scene === "InterstitialAd_Scene.Scene_Invalid") {
529
+ return;
532
530
  }
531
+ AdMgr.nowInterstitialAdScene = scene;
533
532
 
534
533
  if (!this.supportAdType(AdType.Type_Interstitial)) {
535
534
  AdMgr.interstitialAdCallback(InterstitialAd_Callback_Status.Status_NotSupport);
@@ -636,14 +635,6 @@ export class AdMgr extends BaseMgr {
636
635
  return;
637
636
  }
638
637
 
639
- if (!AdMgr.adRecord.rewardedVideoAdRecord.has(AdMgr.nowRewardedVideoAdScene) ||
640
- AdMgr.adRecord.rewardedVideoAdRecord.get(AdMgr.nowRewardedVideoAdScene) === null) {
641
- AdMgr.adRecord.rewardedVideoAdRecord.set(AdMgr.nowRewardedVideoAdScene, new RewardedVideoAd_Record());
642
- }
643
- let record: RewardedVideoAd_Record = AdMgr.adRecord.rewardedVideoAdRecord.get(AdMgr.nowRewardedVideoAdScene);
644
- record.clickCount++;
645
- AdMgr.adRecord.rewardedVideoAdRecord.set(AdMgr.nowRewardedVideoAdScene, record);
646
-
647
638
  if (!AdMgr.rewardedVideoAds.has(scene) ||
648
639
  (AdMgr.rewardedVideoAds.get(scene).callback !== callback && AdMgr.rewardedVideoAds.get(scene).target !== target)) {
649
640
  AdMgr.rewardedVideoAds.set(scene, new AdCallback(callback, target));
@@ -653,11 +644,11 @@ export class AdMgr extends BaseMgr {
653
644
  if (adPlatformUnitInfo.switchType === AdSwitchType.On_Debug) {
654
645
  let ranNumber = randomRangeInt(0, 100);
655
646
  if (ranNumber <= 33) {
656
- AdMgr.rewardedVideoAdCallback(RewardedVideoAd_Callback_Status.Status_Error);
647
+ AdMgr.rewardedVideoAdCallback(RewardedVideoAd_Callback_Status.Status_LoadError);
657
648
  } else if (33 < ranNumber && ranNumber <= 66) {
658
- AdMgr.rewardedVideoAdCallback(RewardedVideoAd_Callback_Status.Status_Giveup);
649
+ AdMgr.rewardedVideoAdCallback(RewardedVideoAd_Callback_Status.Status_Show_Giveup);
659
650
  } else {
660
- AdMgr.rewardedVideoAdCallback(RewardedVideoAd_Callback_Status.Status_Complete);
651
+ AdMgr.rewardedVideoAdCallback(RewardedVideoAd_Callback_Status.Status_Show_Complete);
661
652
  }
662
653
  } else {
663
654
  this.getAdAdapter().showRewardedVideoAd();
@@ -782,7 +773,7 @@ export class AdMgr extends BaseMgr {
782
773
  }
783
774
 
784
775
  /** 销毁互跳广告 */
785
- public destoryPortalAd(): void {
776
+ public destroyPortalAd(): void {
786
777
  if (!this.supportAdType(AdType.Type_Portal)) {
787
778
  return;
788
779
  }
@@ -811,7 +802,7 @@ export class AdMgr extends BaseMgr {
811
802
 
812
803
  /** 隐藏互跳广告 */
813
804
  public hidePortalAd(): void {
814
- if (!this.supportAdType(AdType.Type_Custom)) {
805
+ if (!this.supportAdType(AdType.Type_Portal)) {
815
806
  return;
816
807
  }
817
808
 
@@ -866,20 +857,6 @@ export class AdMgr extends BaseMgr {
866
857
  this.hideCustomAd();
867
858
  }
868
859
 
869
- /**
870
- * 获取广告记录
871
- * @return 广告记录
872
- */
873
- public getAdRecord(): Ad_Record {
874
- return AdMgr.adRecord;
875
- }
876
-
877
- /** 清除广告记录 */
878
- public clearAdRecord(): void {
879
- AdMgr.adRecord.intersitialAdRecord.clear();
880
- AdMgr.adRecord.rewardedVideoAdRecord.clear();
881
- }
882
-
883
860
  /**
884
861
  * 适配合适的 UI 配置
885
862
  * @param contentHeight 内容区域高度