@chiyou/minigame-framework 1.0.0

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 (114) hide show
  1. package/README.md +66 -0
  2. package/dist/Framework/Adapter/AdAdapter/AbsAdAdapter.d.ts +78 -0
  3. package/dist/Framework/Adapter/AdAdapter/AbsAdAdapter.js +230 -0
  4. package/dist/Framework/Adapter/AdAdapter/AdAdapterBilibili.d.ts +31 -0
  5. package/dist/Framework/Adapter/AdAdapter/AdAdapterBilibili.js +224 -0
  6. package/dist/Framework/Adapter/AdAdapter/AdAdapterDouYin.d.ts +34 -0
  7. package/dist/Framework/Adapter/AdAdapter/AdAdapterDouYin.js +524 -0
  8. package/dist/Framework/Adapter/AdAdapter/AdAdapterHonor.d.ts +34 -0
  9. package/dist/Framework/Adapter/AdAdapter/AdAdapterHonor.js +631 -0
  10. package/dist/Framework/Adapter/AdAdapter/AdAdapterHuaWei.d.ts +33 -0
  11. package/dist/Framework/Adapter/AdAdapter/AdAdapterHuaWei.js +460 -0
  12. package/dist/Framework/Adapter/AdAdapter/AdAdapterJingDong.d.ts +31 -0
  13. package/dist/Framework/Adapter/AdAdapter/AdAdapterJingDong.js +227 -0
  14. package/dist/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.d.ts +33 -0
  15. package/dist/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.js +458 -0
  16. package/dist/Framework/Adapter/AdAdapter/AdAdapterOppo.d.ts +35 -0
  17. package/dist/Framework/Adapter/AdAdapter/AdAdapterOppo.js +770 -0
  18. package/dist/Framework/Adapter/AdAdapter/AdAdapterTapTap.d.ts +33 -0
  19. package/dist/Framework/Adapter/AdAdapter/AdAdapterTapTap.js +519 -0
  20. package/dist/Framework/Adapter/AdAdapter/AdAdapterVivo.d.ts +33 -0
  21. package/dist/Framework/Adapter/AdAdapter/AdAdapterVivo.js +492 -0
  22. package/dist/Framework/Adapter/AdAdapter/AdAdapterWeiXin.d.ts +33 -0
  23. package/dist/Framework/Adapter/AdAdapter/AdAdapterWeiXin.js +695 -0
  24. package/dist/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.d.ts +34 -0
  25. package/dist/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.js +597 -0
  26. package/dist/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.d.ts +33 -0
  27. package/dist/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.js +458 -0
  28. package/dist/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.d.ts +51 -0
  29. package/dist/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.js +17 -0
  30. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.d.ts +45 -0
  31. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.js +555 -0
  32. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.d.ts +44 -0
  33. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.js +148 -0
  34. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.d.ts +48 -0
  35. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.js +715 -0
  36. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.d.ts +44 -0
  37. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.js +296 -0
  38. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.d.ts +45 -0
  39. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.js +284 -0
  40. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.d.ts +44 -0
  41. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.js +283 -0
  42. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.d.ts +43 -0
  43. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.js +406 -0
  44. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.d.ts +43 -0
  45. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.js +248 -0
  46. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.d.ts +44 -0
  47. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.js +517 -0
  48. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.d.ts +44 -0
  49. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.js +295 -0
  50. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.d.ts +55 -0
  51. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.js +964 -0
  52. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.d.ts +44 -0
  53. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.js +295 -0
  54. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.d.ts +44 -0
  55. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.js +393 -0
  56. package/dist/Framework/Definition/AdDefinition.d.ts +130 -0
  57. package/dist/Framework/Definition/AdDefinition.js +208 -0
  58. package/dist/Framework/Definition/FrameworkBase.d.ts +13 -0
  59. package/dist/Framework/Definition/FrameworkBase.js +23 -0
  60. package/dist/Framework/Definition/PrivacyDefinition.d.ts +51 -0
  61. package/dist/Framework/Definition/PrivacyDefinition.js +70 -0
  62. package/dist/Framework/Definition/SocialDefinition.d.ts +16 -0
  63. package/dist/Framework/Definition/SocialDefinition.js +2 -0
  64. package/dist/Framework/Definition/SystemDefinition.d.ts +43 -0
  65. package/dist/Framework/Definition/SystemDefinition.js +28 -0
  66. package/dist/Framework/Definition/UIDefinition.d.ts +6 -0
  67. package/dist/Framework/Definition/UIDefinition.js +7 -0
  68. package/dist/Framework/Definition/UserDefinition.d.ts +14 -0
  69. package/dist/Framework/Definition/UserDefinition.js +10 -0
  70. package/dist/Framework/Manager/AdMgr.d.ts +57 -0
  71. package/dist/Framework/Manager/AdMgr.js +684 -0
  72. package/dist/Framework/Manager/AudioMgr.d.ts +28 -0
  73. package/dist/Framework/Manager/AudioMgr.js +265 -0
  74. package/dist/Framework/Manager/BaseMgr.d.ts +18 -0
  75. package/dist/Framework/Manager/BaseMgr.js +114 -0
  76. package/dist/Framework/Manager/EventMgr.d.ts +18 -0
  77. package/dist/Framework/Manager/EventMgr.js +90 -0
  78. package/dist/Framework/Manager/ExcelMgr.d.ts +24 -0
  79. package/dist/Framework/Manager/ExcelMgr.js +156 -0
  80. package/dist/Framework/Manager/LifeCycleMgr.d.ts +20 -0
  81. package/dist/Framework/Manager/LifeCycleMgr.js +110 -0
  82. package/dist/Framework/Manager/NodePoolMgr.d.ts +53 -0
  83. package/dist/Framework/Manager/NodePoolMgr.js +279 -0
  84. package/dist/Framework/Manager/PrivacyMgr.d.ts +15 -0
  85. package/dist/Framework/Manager/PrivacyMgr.js +176 -0
  86. package/dist/Framework/Manager/ResMgr.d.ts +49 -0
  87. package/dist/Framework/Manager/ResMgr.js +337 -0
  88. package/dist/Framework/Manager/SocialMgr.d.ts +23 -0
  89. package/dist/Framework/Manager/SocialMgr.js +220 -0
  90. package/dist/Framework/Manager/SystemMgr.d.ts +24 -0
  91. package/dist/Framework/Manager/SystemMgr.js +222 -0
  92. package/dist/Framework/Manager/TimerMgr.d.ts +11 -0
  93. package/dist/Framework/Manager/TimerMgr.js +63 -0
  94. package/dist/Framework/Manager/UIMgr.d.ts +33 -0
  95. package/dist/Framework/Manager/UIMgr.js +223 -0
  96. package/dist/Framework/Manager/UserMgr.d.ts +15 -0
  97. package/dist/Framework/Manager/UserMgr.js +148 -0
  98. package/dist/Framework/Utils/BezierUtils.d.ts +49 -0
  99. package/dist/Framework/Utils/BezierUtils.js +247 -0
  100. package/dist/Framework/Utils/CSVUtils.d.ts +35 -0
  101. package/dist/Framework/Utils/CSVUtils.js +341 -0
  102. package/dist/Framework/Utils/LogUtils.d.ts +7 -0
  103. package/dist/Framework/Utils/LogUtils.js +32 -0
  104. package/dist/Framework/Utils/NumberUtils.d.ts +16 -0
  105. package/dist/Framework/Utils/NumberUtils.js +44 -0
  106. package/dist/Framework/Utils/TaskUtils.d.ts +10 -0
  107. package/dist/Framework/Utils/TaskUtils.js +24 -0
  108. package/dist/Framework/Utils/TimeUtils.d.ts +19 -0
  109. package/dist/Framework/Utils/TimeUtils.js +33 -0
  110. package/dist/Framework/Utils/WXBizDataCryptUtils.d.ts +12 -0
  111. package/dist/Framework/Utils/WXBizDataCryptUtils.js +37 -0
  112. package/dist/index.d.ts +30 -0
  113. package/dist/index.js +35 -0
  114. package/package.json +40 -0
@@ -0,0 +1,684 @@
1
+ import { math, randomRangeInt, view } from 'cc';
2
+ import { LogUtils } from '../Utils/LogUtils';
3
+ import { AudioMgr } from './AudioMgr';
4
+ import { AdCallback, Ad_Record, InterstitialAd_Callback_Status, InterstitialAd_Record, RewardedVideoAd_Callback_Status, RewardedVideoAd_Record, AdSwitchType, AdType, AdDefinition } from '../Definition/AdDefinition';
5
+ import { PlatformID } from '../Definition/SystemDefinition';
6
+ import { UserMgr } from './UserMgr';
7
+ import { BaseMgr } from './BaseMgr';
8
+ import { AdAdapterWeiXin } from '../Adapter/AdAdapter/AdAdapterWeiXin';
9
+ import { AdAdapterBilibili } from '../Adapter/AdAdapter/AdAdapterBilibili';
10
+ import { AdAdapterDouYin } from '../Adapter/AdAdapter/AdAdapterDouYin';
11
+ import { AdAdapterHonor } from '../Adapter/AdAdapter/AdAdapterHonor';
12
+ import { AdAdapterHuaWei } from '../Adapter/AdAdapter/AdAdapterHuaWei';
13
+ import { AdAdapterJingDong } from '../Adapter/AdAdapter/AdAdapterJingDong';
14
+ import { AdAdapterKuaiShou } from '../Adapter/AdAdapter/AdAdapterKuaiShou';
15
+ import { AdAdapterOppo } from '../Adapter/AdAdapter/AdAdapterOppo';
16
+ import { AdAdapterTapTap } from '../Adapter/AdAdapter/AdAdapterTapTap';
17
+ import { AdAdapterVivo } from '../Adapter/AdAdapter/AdAdapterVivo';
18
+ import { AdAdapterXiaoMi } from '../Adapter/AdAdapter/AdAdapterXiaoMi';
19
+ import { AdAdapterZhiFuBao } from '../Adapter/AdAdapter/AdAdapterZhiFuBao';
20
+ export class AdMgr extends BaseMgr {
21
+ onLoad() {
22
+ if (AdMgr.Instance === null) {
23
+ AdMgr.Instance = this;
24
+ }
25
+ else {
26
+ this.destroy();
27
+ return;
28
+ }
29
+ }
30
+ init(contentHeight, adPlatformUnitMap, adPlatformSettingMap) {
31
+ let currentPlatformID = this.getCurrentPlatformID();
32
+ if (adPlatformUnitMap === null ||
33
+ adPlatformUnitMap.get(currentPlatformID) === null) {
34
+ return 0;
35
+ }
36
+ if (adPlatformSettingMap === null ||
37
+ adPlatformSettingMap.get(currentPlatformID) === null) {
38
+ return 0;
39
+ }
40
+ if (this.getPlatformAdapter() === null) {
41
+ return 0;
42
+ }
43
+ AdMgr.adPlatformUnitMap = adPlatformUnitMap;
44
+ AdMgr.adPlatformSettingMap = adPlatformSettingMap;
45
+ let adAdapterImpl = null;
46
+ switch (BaseMgr.Instance.getCurrentPlatformID()) {
47
+ case PlatformID.ID_MiniGame_WeiXin:
48
+ adAdapterImpl = this.node.addComponent(AdAdapterWeiXin);
49
+ break;
50
+ case PlatformID.ID_MiniGame_DouYin:
51
+ adAdapterImpl = this.node.addComponent(AdAdapterDouYin);
52
+ break;
53
+ case PlatformID.ID_MiniGame_KuaiShou:
54
+ adAdapterImpl = this.node.addComponent(AdAdapterKuaiShou);
55
+ break;
56
+ case PlatformID.ID_MiniGame_ZhiFuBao:
57
+ adAdapterImpl = this.node.addComponent(AdAdapterZhiFuBao);
58
+ break;
59
+ case PlatformID.ID_MiniGame_Bilibili:
60
+ adAdapterImpl = this.node.addComponent(AdAdapterBilibili);
61
+ break;
62
+ case PlatformID.ID_MiniGame_TapTap:
63
+ adAdapterImpl = this.node.addComponent(AdAdapterTapTap);
64
+ break;
65
+ case PlatformID.ID_MiniGame_JingDong:
66
+ adAdapterImpl = this.node.addComponent(AdAdapterJingDong);
67
+ break;
68
+ case PlatformID.ID_QuickGame_XiaoMi:
69
+ adAdapterImpl = this.node.addComponent(AdAdapterXiaoMi);
70
+ break;
71
+ case PlatformID.ID_QuickGame_Oppo:
72
+ adAdapterImpl = this.node.addComponent(AdAdapterOppo);
73
+ break;
74
+ case PlatformID.ID_QuickGame_Honor:
75
+ adAdapterImpl = this.node.addComponent(AdAdapterHonor);
76
+ break;
77
+ case PlatformID.ID_QuickGame_Vivo:
78
+ adAdapterImpl = this.node.addComponent(AdAdapterVivo);
79
+ break;
80
+ case PlatformID.ID_QuickGame_HuaWei:
81
+ adAdapterImpl = this.node.addComponent(AdAdapterHuaWei);
82
+ break;
83
+ default:
84
+ break;
85
+ }
86
+ if (adAdapterImpl !== null) {
87
+ BaseMgr.Instance.setAdAdapter(adAdapterImpl);
88
+ }
89
+ AdMgr.launchTime = new Date().getTime();
90
+ AdMgr.lastInterstitialAdTimestamp = 0;
91
+ AdMgr.interstitialAd_nowIntervalCount = 1;
92
+ if (this.getAdAdapter() === null) {
93
+ return 0;
94
+ }
95
+ if (!this.adSwithOn()) {
96
+ return 0;
97
+ }
98
+ this.clearAdRecord();
99
+ AdMgr.nowRunningBannerAd = "";
100
+ AdMgr.nowRunningCustomAd = "";
101
+ AdMgr.isPermanentAdShowing = false;
102
+ AdMgr.nowInterstitialAdScene = "InterstitialAd_Scene.Scene_Invalid";
103
+ AdMgr.adRecord.intersitialAdRecord.set(AdMgr.nowInterstitialAdScene, new InterstitialAd_Record());
104
+ AdMgr.interstitialAds = new Map();
105
+ AdMgr.interstitialAdCallback = function (res) {
106
+ LogUtils.Instance.log(AdMgr.TAG, "interstitialAdCallback");
107
+ LogUtils.Instance.log("", "scene=" + AdMgr.nowInterstitialAdScene + ",res=" + InterstitialAd_Callback_Status[res]);
108
+ if (res === InterstitialAd_Callback_Status.Status_Watching) {
109
+ AdMgr.Instance.hideAllPermanentAd();
110
+ }
111
+ else if (res === InterstitialAd_Callback_Status.Status_Close ||
112
+ res === InterstitialAd_Callback_Status.Status_Error) {
113
+ AdMgr.Instance.showAllPermanentAd();
114
+ }
115
+ if (res === InterstitialAd_Callback_Status.Status_Close) {
116
+ AdMgr.lastInterstitialAdTimestamp = new Date().getTime();
117
+ AdMgr.interstitialAd_nowIntervalCount = 1;
118
+ }
119
+ if (AdMgr.adRecord.intersitialAdRecord !== null &&
120
+ AdMgr.adRecord.intersitialAdRecord.has(AdMgr.nowInterstitialAdScene) &&
121
+ AdMgr.adRecord.intersitialAdRecord.get(AdMgr.nowInterstitialAdScene) !== null) {
122
+ let record = AdMgr.adRecord.intersitialAdRecord.get(AdMgr.nowInterstitialAdScene);
123
+ if (res === InterstitialAd_Callback_Status.Status_Watching) {
124
+ record.viewCount++;
125
+ }
126
+ else if (res === InterstitialAd_Callback_Status.Status_Error) {
127
+ record.errorCount++;
128
+ }
129
+ else if (res === InterstitialAd_Callback_Status.Status_Close) {
130
+ record.completeCount++;
131
+ }
132
+ AdMgr.adRecord.intersitialAdRecord.set(AdMgr.nowInterstitialAdScene, record);
133
+ }
134
+ if (AdMgr.interstitialAds !== null &&
135
+ AdMgr.interstitialAds.has(AdMgr.nowInterstitialAdScene) &&
136
+ AdMgr.interstitialAds.get(AdMgr.nowInterstitialAdScene) !== null) {
137
+ let adCallback = AdMgr.interstitialAds.get(AdMgr.nowInterstitialAdScene);
138
+ if (adCallback.callback && adCallback.target) {
139
+ adCallback.callback.apply(adCallback.target, [res]);
140
+ }
141
+ }
142
+ if (res !== InterstitialAd_Callback_Status.Status_Watching) {
143
+ AdMgr.nowInterstitialAdScene = "InterstitialAd_Scene.Scene_Invalid";
144
+ }
145
+ };
146
+ AdMgr.nowRewardedVideoAdScene = "RewardedVideoAd_Scene.Scene_Invalid";
147
+ AdMgr.adRecord.rewardedVideoAdRecord.set(AdMgr.nowRewardedVideoAdScene, new RewardedVideoAd_Record());
148
+ AdMgr.rewardedVideoAds = new Map();
149
+ AdMgr.rewardedVideoAdCallback = function (res) {
150
+ LogUtils.Instance.log(AdMgr.TAG, "rewardedVideoAdCallback");
151
+ LogUtils.Instance.log("", "scene=" + AdMgr.nowRewardedVideoAdScene + ",res=" + RewardedVideoAd_Callback_Status[res]);
152
+ if (res === RewardedVideoAd_Callback_Status.Status_Watching) {
153
+ AudioMgr.Instance.pauseMusic();
154
+ AdMgr.Instance.hideAllPermanentAd();
155
+ }
156
+ else if (res === RewardedVideoAd_Callback_Status.Status_Complete ||
157
+ res === RewardedVideoAd_Callback_Status.Status_Giveup ||
158
+ res === RewardedVideoAd_Callback_Status.Status_Error) {
159
+ AudioMgr.Instance.resumeMusic();
160
+ AdMgr.Instance.showAllPermanentAd();
161
+ }
162
+ if (res === RewardedVideoAd_Callback_Status.Status_Complete) {
163
+ AdMgr.interstitialAd_nowIntervalCount++;
164
+ }
165
+ if (AdMgr.adRecord.rewardedVideoAdRecord !== null &&
166
+ AdMgr.adRecord.rewardedVideoAdRecord.has(AdMgr.nowRewardedVideoAdScene) &&
167
+ AdMgr.adRecord.rewardedVideoAdRecord.get(AdMgr.nowRewardedVideoAdScene) !== null) {
168
+ let record = AdMgr.adRecord.rewardedVideoAdRecord.get(AdMgr.nowRewardedVideoAdScene);
169
+ if (res === RewardedVideoAd_Callback_Status.Status_Watching) {
170
+ record.viewCount++;
171
+ }
172
+ else if (res === RewardedVideoAd_Callback_Status.Status_Complete) {
173
+ record.completeCount++;
174
+ }
175
+ else if (res === RewardedVideoAd_Callback_Status.Status_Giveup) {
176
+ record.giveupCount++;
177
+ }
178
+ else if (res === RewardedVideoAd_Callback_Status.Status_Error) {
179
+ record.errorCount++;
180
+ }
181
+ AdMgr.adRecord.rewardedVideoAdRecord.set(AdMgr.nowRewardedVideoAdScene, record);
182
+ }
183
+ if (AdMgr.rewardedVideoAds !== null &&
184
+ AdMgr.rewardedVideoAds.has(AdMgr.nowRewardedVideoAdScene) &&
185
+ AdMgr.rewardedVideoAds.get(AdMgr.nowRewardedVideoAdScene) !== null) {
186
+ let adCallback = AdMgr.rewardedVideoAds.get(AdMgr.nowRewardedVideoAdScene);
187
+ if (adCallback.callback && adCallback.target) {
188
+ adCallback.callback.apply(adCallback.target, [res]);
189
+ }
190
+ }
191
+ if (res !== RewardedVideoAd_Callback_Status.Status_Watching) {
192
+ AdMgr.nowRewardedVideoAdScene = "RewardedVideoAd_Scene.Scene_Invalid";
193
+ }
194
+ };
195
+ this.getAdAdapter().onInit(this.getPlatformAdapter().getScreenInfo(), this, AdMgr.adPlatformUnitMap.get(currentPlatformID).intersitialAd, AdMgr.interstitialAdCallback, AdMgr.adPlatformUnitMap.get(currentPlatformID).rewardedVideoAd, AdMgr.rewardedVideoAdCallback);
196
+ LogUtils.Instance.log(AdMgr.TAG, "init() finished.");
197
+ return this.adjustSuitableUIConfig(contentHeight);
198
+ }
199
+ createAds() {
200
+ this.createInterstitialAd();
201
+ this.createRewardedVideoAd();
202
+ this.createPortalAd();
203
+ this.createAllPermanentAd();
204
+ }
205
+ isPermanentAdShowing() {
206
+ return AdMgr.isPermanentAdShowing;
207
+ }
208
+ adSwithOn() {
209
+ let currentPlatformID = this.getCurrentPlatformID();
210
+ if (!AdMgr.adPlatformUnitMap.has(currentPlatformID) ||
211
+ AdMgr.adPlatformUnitMap.get(currentPlatformID) === null ||
212
+ AdMgr.adPlatformUnitMap.get(currentPlatformID).switchType === AdSwitchType.Off) {
213
+ return false;
214
+ }
215
+ return true;
216
+ }
217
+ supportAdType(adType) {
218
+ if (!this.adSwithOn()) {
219
+ return false;
220
+ }
221
+ let adPlatformUnitInfo = AdMgr.adPlatformUnitMap.get(this.getCurrentPlatformID());
222
+ if (adPlatformUnitInfo === null) {
223
+ return false;
224
+ }
225
+ switch (adType) {
226
+ case AdType.Type_Banner:
227
+ let bannerAd = adPlatformUnitInfo.bannerAd;
228
+ if (bannerAd !== null && bannerAd.length > 0) {
229
+ return true;
230
+ }
231
+ return false;
232
+ case AdType.Type_Custom:
233
+ let customAd = adPlatformUnitInfo.customAd;
234
+ if (customAd !== null && customAd.length > 0) {
235
+ return true;
236
+ }
237
+ return false;
238
+ case AdType.Type_Interstitial:
239
+ let intersitialAd = adPlatformUnitInfo.intersitialAd;
240
+ if (intersitialAd !== null && intersitialAd.length > 0) {
241
+ return true;
242
+ }
243
+ return false;
244
+ case AdType.Type_RewardedVideo:
245
+ let rewardedVideoAd = adPlatformUnitInfo.rewardedVideoAd;
246
+ if (rewardedVideoAd !== null && rewardedVideoAd.length > 0) {
247
+ return true;
248
+ }
249
+ return false;
250
+ case AdType.Type_Portal:
251
+ let portalAd = adPlatformUnitInfo.portalAd;
252
+ if (portalAd !== null && portalAd.length > 0) {
253
+ return true;
254
+ }
255
+ default:
256
+ return false;
257
+ }
258
+ }
259
+ createBannerAd() {
260
+ AdMgr.nowRunningBannerAd = "";
261
+ if (!this.supportAdType(AdType.Type_Banner)) {
262
+ return;
263
+ }
264
+ if (this.getAdAdapter() === null) {
265
+ return;
266
+ }
267
+ let bannerAd_Info = AdDefinition.AdInfoConfig.BannerAd_Info;
268
+ if (bannerAd_Info === null || !bannerAd_Info.shouldShow) {
269
+ return;
270
+ }
271
+ let adUnitId = AdMgr.adPlatformUnitMap.get(this.getCurrentPlatformID()).bannerAd;
272
+ let result = this.getAdAdapter().createBannerAd(adUnitId);
273
+ if (result) {
274
+ AdMgr.nowRunningBannerAd = adUnitId;
275
+ }
276
+ }
277
+ destroyBannerAd() {
278
+ if (!this.supportAdType(AdType.Type_Banner)) {
279
+ return;
280
+ }
281
+ if (this.getAdAdapter() === null) {
282
+ return;
283
+ }
284
+ let adUnitId = AdMgr.adPlatformUnitMap.get(this.getCurrentPlatformID()).bannerAd;
285
+ this.getAdAdapter().destroyBannerAd(adUnitId);
286
+ AdMgr.nowRunningBannerAd = "";
287
+ }
288
+ showBannerAd() {
289
+ if (!this.supportAdType(AdType.Type_Banner)) {
290
+ return;
291
+ }
292
+ if (this.getAdAdapter() === null) {
293
+ return;
294
+ }
295
+ if (AdMgr.nowRunningBannerAd !== "") {
296
+ this.getAdAdapter().showBannerAd(AdMgr.nowRunningBannerAd);
297
+ }
298
+ }
299
+ hideBannerAd() {
300
+ if (!this.supportAdType(AdType.Type_Banner)) {
301
+ return;
302
+ }
303
+ if (this.getAdAdapter() === null) {
304
+ return;
305
+ }
306
+ if (AdMgr.nowRunningBannerAd !== "") {
307
+ this.getAdAdapter().hideBannerAd(AdMgr.nowRunningBannerAd);
308
+ }
309
+ }
310
+ createInterstitialAd() {
311
+ if (!this.supportAdType(AdType.Type_Interstitial)) {
312
+ return;
313
+ }
314
+ if (this.getAdAdapter() === null) {
315
+ return;
316
+ }
317
+ this.getAdAdapter().createInterstitialAd();
318
+ }
319
+ showInterstitialAd(scene, callback, target) {
320
+ if (AdMgr.Instance.isIntersititialAdShowing()) {
321
+ return;
322
+ }
323
+ if (scene === "" || scene === "InterstitialAd_Scene.Scene_Invalid") {
324
+ return;
325
+ }
326
+ AdMgr.nowInterstitialAdScene = scene;
327
+ if (!AdMgr.adRecord.intersitialAdRecord.has(AdMgr.nowInterstitialAdScene) ||
328
+ AdMgr.adRecord.intersitialAdRecord.get(AdMgr.nowInterstitialAdScene) === null) {
329
+ AdMgr.adRecord.intersitialAdRecord.set(AdMgr.nowInterstitialAdScene, new InterstitialAd_Record());
330
+ }
331
+ if (!this.supportAdType(AdType.Type_Interstitial)) {
332
+ AdMgr.interstitialAdCallback(InterstitialAd_Callback_Status.Status_NotSupport);
333
+ return;
334
+ }
335
+ let launchNoAdInterval = 0;
336
+ let interstitialAdIntervalBase = 60000;
337
+ if (AdMgr.adPlatformSettingMap.has(this.getCurrentPlatformID())) {
338
+ let adPlatformSettingInfo = AdMgr.adPlatformSettingMap.get(this.getCurrentPlatformID());
339
+ launchNoAdInterval = adPlatformSettingInfo.launchNoAdInterval_interstitialAd;
340
+ interstitialAdIntervalBase = adPlatformSettingInfo.registerUser_interstitialAd_IntervalBase;
341
+ if (UserMgr.Instance.isNewUser()) {
342
+ interstitialAdIntervalBase = adPlatformSettingInfo.registerUser_interstitialAd_IntervalBase;
343
+ }
344
+ }
345
+ let interstitialAdInterval = interstitialAdIntervalBase * AdMgr.interstitialAd_nowIntervalCount;
346
+ let now = new Date().getTime();
347
+ if (now - AdMgr.launchTime < launchNoAdInterval) {
348
+ AdMgr.interstitialAdCallback(InterstitialAd_Callback_Status.Status_InsufficientInterval);
349
+ return;
350
+ }
351
+ if (now - AdMgr.lastInterstitialAdTimestamp < interstitialAdInterval) {
352
+ AdMgr.interstitialAdCallback(InterstitialAd_Callback_Status.Status_InsufficientInterval);
353
+ return;
354
+ }
355
+ if (!AdMgr.interstitialAds.has(scene) ||
356
+ (AdMgr.interstitialAds.get(scene).callback !== callback && AdMgr.interstitialAds.get(scene).target !== target)) {
357
+ AdMgr.interstitialAds.set(scene, new AdCallback(callback, target));
358
+ }
359
+ this.getAdAdapter().showInterstitialAd();
360
+ }
361
+ destroyInterstitialAd() {
362
+ if (!this.supportAdType(AdType.Type_Interstitial)) {
363
+ return;
364
+ }
365
+ if (this.getAdAdapter() === null) {
366
+ return;
367
+ }
368
+ this.getAdAdapter().destroyInterstitialAd();
369
+ }
370
+ isIntersititialAdShowing() {
371
+ if (!this.supportAdType(AdType.Type_Interstitial)) {
372
+ return false;
373
+ }
374
+ if (this.getAdAdapter() === null) {
375
+ return false;
376
+ }
377
+ return this.getAdAdapter().isIntersititialAdShowing();
378
+ }
379
+ createRewardedVideoAd() {
380
+ if (!this.supportAdType(AdType.Type_RewardedVideo)) {
381
+ return;
382
+ }
383
+ if (this.getAdAdapter() === null) {
384
+ return;
385
+ }
386
+ this.getAdAdapter().createRewardedVideoAd();
387
+ }
388
+ showRewardedVideoAd(scene, callback, target) {
389
+ if (AdMgr.Instance.isRewardedVideoAdShowing()) {
390
+ return;
391
+ }
392
+ if (this.getAdAdapter() === null) {
393
+ return;
394
+ }
395
+ if (scene === "" || scene === "RewardedVideoAd_Scene.Scene_Invalid") {
396
+ return;
397
+ }
398
+ AdMgr.nowRewardedVideoAdScene = scene;
399
+ if (!this.supportAdType(AdType.Type_RewardedVideo)) {
400
+ AdMgr.rewardedVideoAdCallback(RewardedVideoAd_Callback_Status.Status_NotSupport);
401
+ return;
402
+ }
403
+ if (!AdMgr.adRecord.rewardedVideoAdRecord.has(AdMgr.nowRewardedVideoAdScene) ||
404
+ AdMgr.adRecord.rewardedVideoAdRecord.get(AdMgr.nowRewardedVideoAdScene) === null) {
405
+ AdMgr.adRecord.rewardedVideoAdRecord.set(AdMgr.nowRewardedVideoAdScene, new RewardedVideoAd_Record());
406
+ }
407
+ let record = AdMgr.adRecord.rewardedVideoAdRecord.get(AdMgr.nowRewardedVideoAdScene);
408
+ record.clickCount++;
409
+ AdMgr.adRecord.rewardedVideoAdRecord.set(AdMgr.nowRewardedVideoAdScene, record);
410
+ if (!AdMgr.rewardedVideoAds.has(scene) ||
411
+ (AdMgr.rewardedVideoAds.get(scene).callback !== callback && AdMgr.rewardedVideoAds.get(scene).target !== target)) {
412
+ AdMgr.rewardedVideoAds.set(scene, new AdCallback(callback, target));
413
+ }
414
+ let adPlatformUnitInfo = AdMgr.adPlatformUnitMap.get(this.getCurrentPlatformID());
415
+ if (adPlatformUnitInfo.switchType === AdSwitchType.On_Debug) {
416
+ let ranNumber = randomRangeInt(0, 100);
417
+ if (ranNumber <= 33) {
418
+ AdMgr.rewardedVideoAdCallback(RewardedVideoAd_Callback_Status.Status_Error);
419
+ }
420
+ else if (33 < ranNumber && ranNumber <= 66) {
421
+ AdMgr.rewardedVideoAdCallback(RewardedVideoAd_Callback_Status.Status_Giveup);
422
+ }
423
+ else {
424
+ AdMgr.rewardedVideoAdCallback(RewardedVideoAd_Callback_Status.Status_Complete);
425
+ }
426
+ }
427
+ else {
428
+ this.getAdAdapter().showRewardedVideoAd();
429
+ }
430
+ }
431
+ destroyRewardedVideoAd() {
432
+ if (!this.supportAdType(AdType.Type_RewardedVideo)) {
433
+ return;
434
+ }
435
+ if (this.getAdAdapter() === null) {
436
+ return;
437
+ }
438
+ this.getAdAdapter().destroyRewardedVideoAd();
439
+ }
440
+ isRewardedVideoAdShowing() {
441
+ if (this.getAdAdapter() === null) {
442
+ return false;
443
+ }
444
+ return this.getAdAdapter().isRewardedVideoAdShowing();
445
+ }
446
+ isRewardedVideoAdLoaded() {
447
+ if (this.getAdAdapter() === null) {
448
+ return false;
449
+ }
450
+ return this.getAdAdapter().isRewardedVideoAdLoaded();
451
+ }
452
+ createCustomAd() {
453
+ AdMgr.nowRunningCustomAd = "";
454
+ if (!this.supportAdType(AdType.Type_Custom)) {
455
+ return;
456
+ }
457
+ if (this.getAdAdapter() === null) {
458
+ return;
459
+ }
460
+ let customAd_Info = AdDefinition.AdInfoConfig.CustomAd_Info;
461
+ if (customAd_Info === null || !customAd_Info.shouldShow) {
462
+ return;
463
+ }
464
+ let adUnitId = AdMgr.adPlatformUnitMap.get(this.getCurrentPlatformID()).customAd;
465
+ let result = this.getAdAdapter().createCustomAd(adUnitId);
466
+ if (result) {
467
+ AdMgr.nowRunningCustomAd = adUnitId;
468
+ }
469
+ }
470
+ destroyCustomAd() {
471
+ if (!this.supportAdType(AdType.Type_Custom)) {
472
+ return;
473
+ }
474
+ if (this.getAdAdapter() === null) {
475
+ return;
476
+ }
477
+ let adUnitId = AdMgr.adPlatformUnitMap.get(this.getCurrentPlatformID()).customAd;
478
+ this.getAdAdapter().destroyCustomAd(adUnitId);
479
+ AdMgr.nowRunningCustomAd = "";
480
+ }
481
+ showCustomAd() {
482
+ if (!this.supportAdType(AdType.Type_Custom)) {
483
+ return;
484
+ }
485
+ if (this.getAdAdapter() === null) {
486
+ return;
487
+ }
488
+ if (AdMgr.nowRunningCustomAd !== "") {
489
+ this.getAdAdapter().showCustomAd(AdMgr.nowRunningCustomAd);
490
+ }
491
+ }
492
+ hideCustomAd() {
493
+ if (!this.supportAdType(AdType.Type_Custom)) {
494
+ return;
495
+ }
496
+ if (this.getAdAdapter() === null) {
497
+ return;
498
+ }
499
+ if (AdMgr.nowRunningCustomAd !== "") {
500
+ this.getAdAdapter().hideCustomAd(AdMgr.nowRunningCustomAd);
501
+ }
502
+ }
503
+ createPortalAd() {
504
+ if (!this.supportAdType(AdType.Type_Portal)) {
505
+ return;
506
+ }
507
+ if (this.getAdAdapter() === null) {
508
+ return;
509
+ }
510
+ let adUnitId = AdMgr.adPlatformUnitMap.get(this.getCurrentPlatformID()).portalAd;
511
+ this.getAdAdapter().createPortalAd(adUnitId);
512
+ }
513
+ destoryPortalAd() {
514
+ if (!this.supportAdType(AdType.Type_Portal)) {
515
+ return;
516
+ }
517
+ if (this.getAdAdapter() === null) {
518
+ return;
519
+ }
520
+ let adUnitId = AdMgr.adPlatformUnitMap.get(this.getCurrentPlatformID()).portalAd;
521
+ this.getAdAdapter().destroyPortalAd(adUnitId);
522
+ }
523
+ showPortalAd() {
524
+ if (!this.supportAdType(AdType.Type_Portal)) {
525
+ return;
526
+ }
527
+ if (this.getAdAdapter() === null) {
528
+ return;
529
+ }
530
+ let adUnitId = AdMgr.adPlatformUnitMap.get(this.getCurrentPlatformID()).portalAd;
531
+ this.getAdAdapter().showPortalAd(adUnitId);
532
+ }
533
+ hidePortalAd() {
534
+ if (!this.supportAdType(AdType.Type_Custom)) {
535
+ return;
536
+ }
537
+ if (this.getAdAdapter() === null) {
538
+ return;
539
+ }
540
+ let adUnitId = AdMgr.adPlatformUnitMap.get(this.getCurrentPlatformID()).portalAd;
541
+ this.getAdAdapter().hidePortalAd(adUnitId);
542
+ }
543
+ createAllPermanentAd() {
544
+ this.createBannerAd();
545
+ this.createCustomAd();
546
+ }
547
+ showAllPermanentAd() {
548
+ let delay = 0;
549
+ let currentPlatformID = this.getCurrentPlatformID();
550
+ if (AdMgr.adPlatformSettingMap.has(currentPlatformID)) {
551
+ let launchNoAdInterval = AdMgr.adPlatformSettingMap.get(currentPlatformID).launchNoAdInterval_permanentAd;
552
+ let now = new Date().getTime();
553
+ if (now - AdMgr.launchTime < launchNoAdInterval) {
554
+ delay = Math.floor((launchNoAdInterval - (now - AdMgr.launchTime)) / 1000);
555
+ }
556
+ }
557
+ if (!AdMgr.isPermanentAdShowing) {
558
+ LogUtils.Instance.log(AdMgr.TAG, "showAllPermanentAd, delay=" + delay);
559
+ this.scheduleOnce(() => {
560
+ AdMgr.isPermanentAdShowing = true;
561
+ this.showBannerAd();
562
+ this.showCustomAd();
563
+ }, delay);
564
+ }
565
+ }
566
+ hideAllPermanentAd() {
567
+ LogUtils.Instance.log(AdMgr.TAG, "hideAllPermanentAd");
568
+ AdMgr.isPermanentAdShowing = false;
569
+ this.hideBannerAd();
570
+ this.hideCustomAd();
571
+ }
572
+ getAdRecord() {
573
+ return AdMgr.adRecord;
574
+ }
575
+ clearAdRecord() {
576
+ AdMgr.adRecord.intersitialAdRecord.clear();
577
+ AdMgr.adRecord.rewardedVideoAdRecord.clear();
578
+ }
579
+ // [0] bannerAd_shouldShow
580
+ // [1] customAd_shouldShow
581
+ // [2] yOffset
582
+ adjustSuitableUIConfig(contentHeight) {
583
+ LogUtils.Instance.log(AdMgr.TAG, "adjustSuitableUIConfig() contentHeight=" + contentHeight);
584
+ LogUtils.Instance.log(AdMgr.TAG, "screen");
585
+ LogUtils.Instance.log("", screen);
586
+ let screenSize = new math.Size(0, 0);
587
+ if (screen["width"] && screen["height"]) {
588
+ screenSize.width = screen.width;
589
+ screenSize.height = screen.height;
590
+ }
591
+ else if (screen["availWidth"] && screen["availHeight"]) {
592
+ screenSize.width = screen.availWidth;
593
+ screenSize.height = screen.availHeight;
594
+ }
595
+ let designSize = view.getDesignResolutionSize();
596
+ LogUtils.Instance.log(AdMgr.TAG, "designSize=" + designSize + ", screenSize=" + screenSize);
597
+ let screenDisplayWidth = designSize.width;
598
+ let screenDisplayHeight = designSize.width * screenSize.y / screenSize.x;
599
+ LogUtils.Instance.log("", "screenDisplayWidth=" + screenDisplayWidth + ", screenDisplayHeight=" + screenDisplayHeight);
600
+ let bannerAdHeight = 0;
601
+ let bannerAdYMargin = 0;
602
+ let bannerAdDisplayHeight = 0;
603
+ let bannerAdYMarginDisplayHeight = 0;
604
+ let currentPlatformID = this.getCurrentPlatformID();
605
+ if (AdDefinition.BannerAdStyleConfig.has(currentPlatformID)) {
606
+ let bannerAd_PlatformInfo = AdDefinition.BannerAdStyleConfig.get(currentPlatformID);
607
+ bannerAdHeight = bannerAd_PlatformInfo.height;
608
+ bannerAdYMargin = bannerAd_PlatformInfo.yMargin;
609
+ if (bannerAd_PlatformInfo.scaleRatio > 0) {
610
+ bannerAdHeight *= bannerAd_PlatformInfo.scaleRatio;
611
+ }
612
+ }
613
+ bannerAdDisplayHeight = bannerAdHeight * designSize.height / screenSize.y;
614
+ bannerAdYMarginDisplayHeight = bannerAdYMargin * designSize.height / screenSize.y;
615
+ LogUtils.Instance.log("", "bannerAdDisplayHeight=" + bannerAdDisplayHeight);
616
+ let customAdHeight = 0;
617
+ let customAdYMargin = 0;
618
+ let customAdDisplayHeight = 0;
619
+ let customAdYMarginDisplayHeight = 0;
620
+ if (AdDefinition.CustomAdStyleConfig.has(currentPlatformID)) {
621
+ let customAd_PlatformInfo = AdDefinition.CustomAdStyleConfig.get(currentPlatformID);
622
+ customAdHeight = customAd_PlatformInfo.height;
623
+ customAdYMargin = customAd_PlatformInfo.yMargin;
624
+ if (customAd_PlatformInfo.scaleRatio > 0) {
625
+ customAdHeight *= customAd_PlatformInfo.scaleRatio;
626
+ }
627
+ }
628
+ customAdDisplayHeight = customAdHeight * designSize.height / screenSize.y;
629
+ customAdYMarginDisplayHeight = customAdYMargin * designSize.height / screenSize.y;
630
+ LogUtils.Instance.log("", "customAdDisplayHeight=" + customAdDisplayHeight);
631
+ let height_1 = bannerAdDisplayHeight + bannerAdYMarginDisplayHeight + 30;
632
+ let height_2 = bannerAdDisplayHeight + bannerAdYMarginDisplayHeight + customAdDisplayHeight + customAdYMarginDisplayHeight + 50;
633
+ LogUtils.Instance.log("", "height_1=" + height_1);
634
+ LogUtils.Instance.log("", "height_2=" + height_2);
635
+ let solution = 0;
636
+ if (height_2 <= screenDisplayHeight - contentHeight) {
637
+ solution = 2;
638
+ }
639
+ else if (height_1 <= screenDisplayHeight - contentHeight) {
640
+ solution = 1;
641
+ }
642
+ LogUtils.Instance.log("", "solution=" + solution);
643
+ let yOffset = 0;
644
+ if (solution === 0) {
645
+ AdDefinition.AdInfoConfig.BannerAd_Info.shouldShow = false;
646
+ AdDefinition.AdInfoConfig.CustomAd_Info.shouldShow = false;
647
+ yOffset = 0;
648
+ }
649
+ else if (solution === 1) {
650
+ AdDefinition.AdInfoConfig.BannerAd_Info.shouldShow = true;
651
+ AdDefinition.AdInfoConfig.CustomAd_Info.shouldShow = false;
652
+ yOffset = bannerAdDisplayHeight / 2;
653
+ }
654
+ else if (solution === 2) {
655
+ AdDefinition.AdInfoConfig.BannerAd_Info.shouldShow = true;
656
+ AdDefinition.AdInfoConfig.CustomAd_Info.shouldShow = true;
657
+ yOffset = (bannerAdDisplayHeight - customAdDisplayHeight) / 2;
658
+ }
659
+ LogUtils.Instance.log("", "yOffset=" + yOffset);
660
+ AdMgr.contentTop = designSize.y - (designSize.y - contentHeight) / 2 + yOffset;
661
+ AdMgr.contentBottom = (designSize.y - contentHeight) / 2 + yOffset;
662
+ LogUtils.Instance.log(AdMgr.TAG, "contentTop=" + AdMgr.contentTop + ",contentBottom=" + AdMgr.contentBottom);
663
+ return yOffset;
664
+ }
665
+ }
666
+ AdMgr.Instance = null;
667
+ AdMgr.TAG = "AudioMgr";
668
+ AdMgr.adPlatformUnitMap = null;
669
+ AdMgr.adPlatformSettingMap = null;
670
+ AdMgr.launchTime = 0;
671
+ AdMgr.interstitialAd_nowIntervalCount = 0;
672
+ AdMgr.interstitialAds = new Map();
673
+ AdMgr.nowInterstitialAdScene = "InterstitialAd_Scene.Scene_Invalid";
674
+ AdMgr.interstitialAdCallback = null;
675
+ AdMgr.lastInterstitialAdTimestamp = 0;
676
+ AdMgr.rewardedVideoAds = new Map();
677
+ AdMgr.nowRewardedVideoAdScene = "";
678
+ AdMgr.rewardedVideoAdCallback = null;
679
+ AdMgr.nowRunningBannerAd = "";
680
+ AdMgr.nowRunningCustomAd = "";
681
+ AdMgr.isPermanentAdShowing = false;
682
+ AdMgr.adRecord = new Ad_Record();
683
+ AdMgr.contentTop = 0;
684
+ AdMgr.contentBottom = 0;