@chiyou/minigame-framework 1.0.0 → 1.0.2

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 (152) hide show
  1. package/assets/AssetsPackage/GUI/Images/Block.png +0 -0
  2. package/assets/AssetsPackage/GUI/Images/Block.png.meta +134 -0
  3. package/assets/AssetsPackage/GUI/Images.meta +9 -0
  4. package/assets/AssetsPackage/GUI/UIPrefabs/ChessBoard_Card.prefab +509 -0
  5. package/assets/AssetsPackage/GUI/UIPrefabs/ChessBoard_Card.prefab.meta +13 -0
  6. package/assets/AssetsPackage/GUI/UIPrefabs.meta +9 -0
  7. package/assets/AssetsPackage/GUI.meta +11 -0
  8. package/assets/AssetsPackage/SpriteAtlas/Card_Pattern.plist +1106 -0
  9. package/assets/AssetsPackage/SpriteAtlas/Card_Pattern.plist.meta +3329 -0
  10. package/assets/AssetsPackage/SpriteAtlas/Card_Pattern.png +0 -0
  11. package/assets/AssetsPackage/SpriteAtlas/Card_Pattern.png.meta +134 -0
  12. package/assets/AssetsPackage/SpriteAtlas/SA_Card.plist +1196 -0
  13. package/assets/AssetsPackage/SpriteAtlas/SA_Card.plist.meta +3605 -0
  14. package/assets/AssetsPackage/SpriteAtlas/SA_Card.png +0 -0
  15. package/assets/AssetsPackage/SpriteAtlas/SA_Card.png.meta +134 -0
  16. package/assets/AssetsPackage/SpriteAtlas.meta +11 -0
  17. package/assets/AssetsPackage/SpriteFrame/Card_PatternType_Back.png +0 -0
  18. package/assets/AssetsPackage/SpriteFrame/Card_PatternType_Back.png.meta +134 -0
  19. package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Back_BG.png +0 -0
  20. package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Back_BG.png.meta +134 -0
  21. package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Back_FG.png +0 -0
  22. package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Back_FG.png.meta +134 -0
  23. package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Front_BG.png +0 -0
  24. package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Front_BG.png.meta +134 -0
  25. package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Front_FG.png +0 -0
  26. package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Front_FG.png.meta +134 -0
  27. package/assets/AssetsPackage/SpriteFrame.meta +11 -0
  28. package/assets/AssetsPackage.meta +9 -0
  29. package/assets/Scenes/Game.scene +831 -0
  30. package/assets/Scenes/Game.scene.meta +11 -0
  31. package/assets/Scenes.meta +9 -0
  32. package/assets/Scripts/Biz.meta +9 -0
  33. package/assets/Scripts/Framework/Adapter/AdAdapter/AbsAdAdapter.ts +312 -0
  34. package/assets/Scripts/Framework/Adapter/AdAdapter/AbsAdAdapter.ts.meta +9 -0
  35. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterBilibili.ts +294 -0
  36. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterBilibili.ts.meta +9 -0
  37. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterDouYin.ts +650 -0
  38. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterDouYin.ts.meta +9 -0
  39. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterHonor.ts +782 -0
  40. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterHonor.ts.meta +9 -0
  41. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterHuaWei.ts +582 -0
  42. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterHuaWei.ts.meta +9 -0
  43. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterJingDong.ts +298 -0
  44. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterJingDong.ts.meta +9 -0
  45. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.ts +575 -0
  46. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.ts.meta +9 -0
  47. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterOppo.ts +946 -0
  48. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterOppo.ts.meta +9 -0
  49. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterTapTap.ts +643 -0
  50. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterTapTap.ts.meta +9 -0
  51. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterVivo.ts +616 -0
  52. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterVivo.ts.meta +9 -0
  53. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterWeiXin.ts +847 -0
  54. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterWeiXin.ts.meta +9 -0
  55. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.ts +747 -0
  56. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.ts.meta +9 -0
  57. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.ts +579 -0
  58. package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.ts.meta +9 -0
  59. package/assets/Scripts/Framework/Adapter/AdAdapter.meta +9 -0
  60. package/assets/Scripts/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.ts +102 -0
  61. package/assets/Scripts/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.ts.meta +9 -0
  62. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.ts +660 -0
  63. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.ts.meta +9 -0
  64. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.ts +224 -0
  65. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.ts.meta +9 -0
  66. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.ts +827 -0
  67. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.ts.meta +9 -0
  68. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.ts +378 -0
  69. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.ts.meta +9 -0
  70. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.ts +363 -0
  71. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.ts.meta +9 -0
  72. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.ts +368 -0
  73. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.ts.meta +9 -0
  74. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.ts +498 -0
  75. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.ts.meta +9 -0
  76. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.ts +323 -0
  77. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.ts.meta +9 -0
  78. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.ts +617 -0
  79. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.ts.meta +9 -0
  80. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.ts +377 -0
  81. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.ts.meta +9 -0
  82. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.ts +1136 -0
  83. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.ts.meta +9 -0
  84. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.ts +377 -0
  85. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.ts.meta +9 -0
  86. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.ts +483 -0
  87. package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.ts.meta +9 -0
  88. package/assets/Scripts/Framework/Adapter/PlatformAdapter.meta +9 -0
  89. package/assets/Scripts/Framework/Adapter.meta +9 -0
  90. package/assets/Scripts/Framework/Definition/AdDefinition.ts +284 -0
  91. package/assets/Scripts/Framework/Definition/AdDefinition.ts.meta +9 -0
  92. package/assets/Scripts/Framework/Definition/FrameworkBase.ts +15 -0
  93. package/assets/Scripts/Framework/Definition/FrameworkBase.ts.meta +9 -0
  94. package/assets/Scripts/Framework/Definition/PrivacyDefinition.ts +95 -0
  95. package/assets/Scripts/Framework/Definition/PrivacyDefinition.ts.meta +9 -0
  96. package/assets/Scripts/Framework/Definition/SocialDefinition.ts +21 -0
  97. package/assets/Scripts/Framework/Definition/SocialDefinition.ts.meta +9 -0
  98. package/assets/Scripts/Framework/Definition/SystemDefinition.ts +58 -0
  99. package/assets/Scripts/Framework/Definition/SystemDefinition.ts.meta +9 -0
  100. package/assets/Scripts/Framework/Definition/UIDefinition.ts +10 -0
  101. package/assets/Scripts/Framework/Definition/UIDefinition.ts.meta +9 -0
  102. package/assets/Scripts/Framework/Definition/UserDefinition.ts +17 -0
  103. package/assets/Scripts/Framework/Definition/UserDefinition.ts.meta +9 -0
  104. package/assets/Scripts/Framework/Definition.meta +9 -0
  105. package/assets/Scripts/Framework/Manager/AdMgr.ts +812 -0
  106. package/assets/Scripts/Framework/Manager/AdMgr.ts.meta +9 -0
  107. package/assets/Scripts/Framework/Manager/AudioMgr.ts +296 -0
  108. package/assets/Scripts/Framework/Manager/AudioMgr.ts.meta +9 -0
  109. package/assets/Scripts/Framework/Manager/BaseMgr.ts +130 -0
  110. package/assets/Scripts/Framework/Manager/BaseMgr.ts.meta +9 -0
  111. package/assets/Scripts/Framework/Manager/EventMgr.ts +102 -0
  112. package/assets/Scripts/Framework/Manager/EventMgr.ts.meta +9 -0
  113. package/assets/Scripts/Framework/Manager/ExcelMgr.ts +188 -0
  114. package/assets/Scripts/Framework/Manager/ExcelMgr.ts.meta +9 -0
  115. package/assets/Scripts/Framework/Manager/LifeCycleMgr.ts +142 -0
  116. package/assets/Scripts/Framework/Manager/LifeCycleMgr.ts.meta +9 -0
  117. package/assets/Scripts/Framework/Manager/NodePoolMgr.ts +385 -0
  118. package/assets/Scripts/Framework/Manager/NodePoolMgr.ts.meta +9 -0
  119. package/assets/Scripts/Framework/Manager/PrivacyMgr.ts +189 -0
  120. package/assets/Scripts/Framework/Manager/PrivacyMgr.ts.meta +9 -0
  121. package/assets/Scripts/Framework/Manager/ResMgr.ts +420 -0
  122. package/assets/Scripts/Framework/Manager/ResMgr.ts.meta +9 -0
  123. package/assets/Scripts/Framework/Manager/SocialMgr.ts +250 -0
  124. package/assets/Scripts/Framework/Manager/SocialMgr.ts.meta +9 -0
  125. package/assets/Scripts/Framework/Manager/SystemMgr.ts +264 -0
  126. package/assets/Scripts/Framework/Manager/SystemMgr.ts.meta +9 -0
  127. package/assets/Scripts/Framework/Manager/TimerMgr.ts +80 -0
  128. package/assets/Scripts/Framework/Manager/TimerMgr.ts.meta +9 -0
  129. package/assets/Scripts/Framework/Manager/UIMgr.ts +267 -0
  130. package/assets/Scripts/Framework/Manager/UIMgr.ts.meta +9 -0
  131. package/assets/Scripts/Framework/Manager/UserMgr.ts +162 -0
  132. package/assets/Scripts/Framework/Manager/UserMgr.ts.meta +9 -0
  133. package/assets/Scripts/Framework/Manager.meta +9 -0
  134. package/assets/Scripts/Framework/Utils/BezierUtils.ts +273 -0
  135. package/assets/Scripts/Framework/Utils/BezierUtils.ts.meta +9 -0
  136. package/assets/Scripts/Framework/Utils/CSVUtils.ts +396 -0
  137. package/assets/Scripts/Framework/Utils/CSVUtils.ts.meta +9 -0
  138. package/assets/Scripts/Framework/Utils/LogUtils.ts +32 -0
  139. package/assets/Scripts/Framework/Utils/LogUtils.ts.meta +9 -0
  140. package/assets/Scripts/Framework/Utils/NumberUtils.ts +51 -0
  141. package/assets/Scripts/Framework/Utils/NumberUtils.ts.meta +9 -0
  142. package/assets/Scripts/Framework/Utils/TaskUtils.ts +27 -0
  143. package/assets/Scripts/Framework/Utils/TaskUtils.ts.meta +9 -0
  144. package/assets/Scripts/Framework/Utils/TimeUtils.ts +38 -0
  145. package/assets/Scripts/Framework/Utils/TimeUtils.ts.meta +9 -0
  146. package/assets/Scripts/Framework/Utils/WXBizDataCryptUtils.ts +54 -0
  147. package/assets/Scripts/Framework/Utils/WXBizDataCryptUtils.ts.meta +9 -0
  148. package/assets/Scripts/Framework/Utils.meta +9 -0
  149. package/assets/Scripts/Framework.meta +9 -0
  150. package/assets/Scripts/index.ts +39 -0
  151. package/assets/Scripts.meta +9 -0
  152. package/package.json +2 -4
@@ -0,0 +1,747 @@
1
+ import { BannerAd_Info, BannerAd_PlatformInfo, InterstitialAd_Callback_Status, RewardedVideoAd_Callback_Status, CustomAd_Info, CustomAd_PlatformInfo, AdDefinition } from "../../Definition/AdDefinition";
2
+ import { PlatformID } from "../../Definition/SystemDefinition";
3
+ import { LogUtils } from "../../Utils/LogUtils";
4
+ import { AbsAdAdapter, BannerAdPosition, CustomAdPosition, InterstitialAdStatus, RewardedVideoAdStatus } from "./AbsAdAdapter";
5
+
6
+ class XMBannerAd {
7
+ unitId: string;
8
+ ad: any;
9
+ errorListener: Function;
10
+ loadListener: Function;
11
+ resizeListener: Function;
12
+ isRecreating: boolean;
13
+ isFirstLoad: boolean;
14
+
15
+ constructor(adUnitId: string, ad: any, isFirstLoad: boolean) {
16
+ this.unitId = adUnitId;
17
+ this.ad = ad;
18
+ this.errorListener = null;
19
+ this.loadListener = null;
20
+ this.resizeListener = null;
21
+ this.isRecreating = false;
22
+ this.isFirstLoad = isFirstLoad;
23
+ }
24
+
25
+ public destroy(): void {
26
+ if (this.ad !== null) {
27
+ this.errorListener = null;
28
+ this.loadListener = null;
29
+ if (this.resizeListener !== null) {
30
+ this.ad.offResize(this.resizeListener);
31
+ this.resizeListener = null;
32
+ }
33
+
34
+ this.ad.destroy();
35
+ this.ad = null;
36
+ }
37
+ this.isRecreating = false;
38
+ }
39
+ }
40
+
41
+ class XMInterstitialAd {
42
+ unitId: string;
43
+ ad: any;
44
+ status: InterstitialAdStatus;
45
+ callback: Function;
46
+ errorListener: Function;
47
+ loadListener: Function;
48
+ closeListener: Function;
49
+ isShowImmediately: boolean;
50
+
51
+ constructor(adUnitId: string, callback: Function) {
52
+ this.unitId = adUnitId;
53
+ this.ad = null;
54
+ this.status = InterstitialAdStatus.Status_Init;
55
+ this.callback = callback;
56
+ this.errorListener = null;
57
+ this.loadListener = null;
58
+ this.closeListener = null;
59
+ this.isShowImmediately = false;
60
+ }
61
+
62
+ public destroy(): void {
63
+ if (this.ad !== null) {
64
+ if (this.errorListener !== null) {
65
+ this.ad.offError(this.errorListener);
66
+ this.errorListener = null;
67
+ }
68
+ if (this.loadListener !== null) {
69
+ this.ad.offLoad(this.loadListener);
70
+ this.loadListener = null;
71
+ }
72
+ if (this.closeListener !== null) {
73
+ this.ad.offClose(this.closeListener);
74
+ this.closeListener = null;
75
+ }
76
+
77
+ this.ad.destroy();
78
+ this.ad = null;
79
+ }
80
+ this.isShowImmediately = false;
81
+ this.status = InterstitialAdStatus.Status_Destroyed;
82
+ }
83
+ }
84
+
85
+ class XMRewardedVideoAd {
86
+ unitId: string;
87
+ ad: any;
88
+ status: RewardedVideoAdStatus;
89
+ callback: Function;
90
+ errorListener: Function;
91
+ loadListener: Function;
92
+ closeListener: Function;
93
+ isShowImmediately: boolean;
94
+
95
+ constructor(adUnitId: string, callback: Function) {
96
+ this.unitId = adUnitId;
97
+ this.ad = null;
98
+ this.status = RewardedVideoAdStatus.Status_Destroyed;
99
+ this.callback = callback;
100
+ this.errorListener = null;
101
+ this.loadListener = null;
102
+ this.closeListener = null;
103
+ this.isShowImmediately = false;
104
+ }
105
+
106
+ public destroy(): void {
107
+ if (this.ad !== null) {
108
+ if (this.errorListener !== null) {
109
+ this.ad.offError(this.errorListener);
110
+ this.errorListener = null;
111
+ }
112
+ if (this.loadListener !== null) {
113
+ this.ad.offLoad(this.loadListener);
114
+ this.loadListener = null;
115
+ }
116
+ if (this.closeListener !== null) {
117
+ this.ad.offClose(this.closeListener);
118
+ this.closeListener = null;
119
+ }
120
+
121
+ this.ad.destroy();
122
+ this.ad = null;
123
+ }
124
+ this.isShowImmediately = false;
125
+ this.status = RewardedVideoAdStatus.Status_Destroyed;
126
+ }
127
+ }
128
+
129
+ class XMCustomAd {
130
+ unitId: string;
131
+ ad: any;
132
+ errorListener: Function;
133
+ loadListener: Function;
134
+ isRecreating: boolean;
135
+ isFirstLoad: boolean;
136
+
137
+ constructor(adUnitId: string, ad: any, isFirstLoad: boolean) {
138
+ this.unitId = adUnitId;
139
+ this.ad = ad;
140
+ this.errorListener = null;
141
+ this.loadListener = null;
142
+ this.isRecreating = false;
143
+ this.isFirstLoad = isFirstLoad;
144
+ }
145
+
146
+ public destroy(): void {
147
+ if (this.ad !== null) {
148
+ this.errorListener = null;
149
+ this.loadListener = null;
150
+
151
+ this.ad.destroy();
152
+ this.ad = null;
153
+ }
154
+ this.isRecreating = false;
155
+ }
156
+ }
157
+
158
+ export class AdAdapterXiaoMi extends AbsAdAdapter {
159
+ static TAG: string = "AdAdapterXiaoMi";
160
+
161
+ private xmInterstitialAd: XMInterstitialAd = null;
162
+ private xmRewardedVideoAd: XMRewardedVideoAd = null;
163
+ private xmBannerAds: XMBannerAd[] = [];
164
+ private xmCustomAds: XMCustomAd[] = [];
165
+
166
+ public init(interstitialAdUnitId: string, interstitialAdCallback: Function, rewardedVideoAdUnitId: string, rewardedVideoAdCallback: Function): void {
167
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "init()");
168
+
169
+ this.xmInterstitialAd = new XMInterstitialAd(interstitialAdUnitId, interstitialAdCallback);
170
+ this.xmRewardedVideoAd = new XMRewardedVideoAd(rewardedVideoAdUnitId, rewardedVideoAdCallback);
171
+
172
+ this.xmBannerAds = [];
173
+ this.xmCustomAds = [];
174
+ }
175
+
176
+ public createBannerAd(adUnitId: string): boolean {
177
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "createBannerAd()");
178
+
179
+ let isFirstLoad: boolean = true;
180
+ for (let i = 0; i < this.xmBannerAds.length; i++) {
181
+ if (this.xmBannerAds[i].unitId === adUnitId) {
182
+ isFirstLoad = this.xmBannerAds[i].isFirstLoad;
183
+ break;
184
+ }
185
+ }
186
+
187
+ this.destroyBannerAd(adUnitId);
188
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "createBannerAd() adUnitId=" + adUnitId);
189
+
190
+ let bannerAdInfo: BannerAd_Info = AdDefinition.AdInfoConfig.BannerAd_Info;
191
+ if (bannerAdInfo === null || !bannerAdInfo.shouldShow) {
192
+ return false;
193
+ }
194
+
195
+ let bannerAdPlatformInfo: BannerAd_PlatformInfo = AdDefinition.BannerAdStyleConfig.get(PlatformID.ID_QuickGame_XiaoMi);
196
+ if (bannerAdPlatformInfo === null) {
197
+ return false;
198
+ }
199
+
200
+ let bannerAdParam: any = {
201
+ adUnitId: adUnitId,
202
+ };
203
+ if (bannerAdPlatformInfo.canAutoRefresh) {
204
+ bannerAdParam.adIntervals = bannerAdPlatformInfo.refreshInterval;
205
+ }
206
+
207
+ let bannerAd: any = window["qg"].createBannerAd(bannerAdParam);
208
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "qg.createBannerAd() " + (bannerAd !== null ? "success" : "fail"));
209
+ LogUtils.Instance.log("", bannerAd);
210
+ if (!bannerAd) {
211
+ return false;
212
+ }
213
+
214
+ let xmBannerAd: XMBannerAd = new XMBannerAd(adUnitId, bannerAd, isFirstLoad);
215
+ this.xmBannerAds.push(xmBannerAd);
216
+
217
+ xmBannerAd.errorListener = (err) => {
218
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmBannerAd.ad.onError()");
219
+ if (err) {
220
+ LogUtils.Instance.log("", err);
221
+ }
222
+
223
+ if (!xmBannerAd.isRecreating) {
224
+ xmBannerAd.isRecreating = true;
225
+
226
+ this.scheduleOnce(() => {
227
+ xmBannerAd.isRecreating = false;
228
+ this.createBannerAd(adUnitId);
229
+ }, 15);
230
+ }
231
+ };
232
+ xmBannerAd.ad.onError(xmBannerAd.errorListener);
233
+
234
+ xmBannerAd.resizeListener = (res) => {
235
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmBannerAd.ad.onResize()");
236
+ if (res) {
237
+ LogUtils.Instance.log("", res);
238
+ }
239
+ };
240
+ xmBannerAd.ad.onResize(xmBannerAd.resizeListener);
241
+
242
+ xmBannerAd.loadListener = () => {
243
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmBannerAd.ad.onLoad()");
244
+
245
+ if (xmBannerAd.isFirstLoad) {
246
+ xmBannerAd.isFirstLoad = false;
247
+ }
248
+
249
+ if (this.adMgr.isPermanentAdShowing()) {
250
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmBannerAd.ad.show()");
251
+ xmBannerAd.ad.show();
252
+ }
253
+ };
254
+ xmBannerAd.ad.onLoad(xmBannerAd.loadListener);
255
+
256
+ if (!bannerAdPlatformInfo.canAutoRefresh) {
257
+ if (!xmBannerAd.isRecreating) {
258
+ xmBannerAd.isRecreating = true;
259
+
260
+ this.scheduleOnce(() => {
261
+ xmBannerAd.isRecreating = false;
262
+ this.createBannerAd(adUnitId);
263
+ }, bannerAdPlatformInfo.refreshInterval);
264
+ }
265
+ }
266
+
267
+ return true;
268
+ }
269
+
270
+ public destroyBannerAd(adUnitId: string): void {
271
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "destroyBannerAd(): adUnitId=" + adUnitId);
272
+
273
+ let index = -1;
274
+ for (let i = 0; i < this.xmBannerAds.length; i++) {
275
+ if (this.xmBannerAds[i].unitId === adUnitId) {
276
+ index = i;
277
+ break;
278
+ }
279
+ }
280
+
281
+ if (index >= 0) {
282
+ this.xmBannerAds[index].destroy();
283
+ this.xmBannerAds.splice(index, 1);
284
+ }
285
+ }
286
+
287
+ public showBannerAd(adUnitId: string): void {
288
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "showBannerAd(): adUnitId=" + adUnitId);
289
+
290
+ for (let i = 0; i < this.xmBannerAds.length; i++) {
291
+ if (this.xmBannerAds[i].unitId === adUnitId) {
292
+ this.xmBannerAds[i].ad.show();
293
+ break;
294
+ }
295
+ }
296
+ }
297
+
298
+ public hideBannerAd(adUnitId: string): void {
299
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "hideBannerAd(): adUnitId=" + adUnitId);
300
+
301
+ // 小米Banner隐藏后不再展示,故不做操作
302
+ // for (let i = 0; i < this.xmBannerAds.length; i++) {
303
+ // if (this.xmBannerAds[i].unitId === adUnitId) {
304
+ // this.xmBannerAds[i].ad.hide();
305
+ // break;
306
+ // }
307
+ // }
308
+ }
309
+
310
+ public createInterstitialAd(): void {
311
+ // 小米插屏广告就是不要destory,直接再次create
312
+ // this.destroyInterstitialAd();
313
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "createInterstitialAd() adUnitId=" + this.xmInterstitialAd.unitId);
314
+
315
+ let interstitialAd: any = window["qg"].createInterstitialAd({
316
+ adUnitId: this.xmInterstitialAd.unitId
317
+ });
318
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "qg.createInterstitialAd() " + (interstitialAd !== null ? "success" : "fail"));
319
+ LogUtils.Instance.log("", interstitialAd);
320
+ if (!interstitialAd) {
321
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Error;
322
+ this.xmInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Error);
323
+ return;
324
+ }
325
+
326
+ this.xmInterstitialAd.ad = interstitialAd;
327
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Init;
328
+
329
+ this.xmInterstitialAd.errorListener = (err) => {
330
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.ad.onError()");
331
+ if (err) {
332
+ LogUtils.Instance.log("", err);
333
+ }
334
+
335
+ if (this.xmInterstitialAd.status !== InterstitialAdStatus.Status_Watching) {
336
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Error;
337
+ this.xmInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Error);
338
+ }
339
+ };
340
+ this.xmInterstitialAd.ad.onError(this.xmInterstitialAd.errorListener);
341
+
342
+ this.xmInterstitialAd.loadListener = () => {
343
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.ad.onLoad()");
344
+
345
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Loaded;
346
+
347
+ if (this.xmInterstitialAd.isShowImmediately) {
348
+ this.xmInterstitialAd.isShowImmediately = false;
349
+ this._showInterstitialAd();
350
+ }
351
+ };
352
+ this.xmInterstitialAd.ad.onLoad(this.xmInterstitialAd.loadListener);
353
+
354
+ this.xmInterstitialAd.closeListener = () => {
355
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.ad.onClose()");
356
+
357
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Watched;
358
+ this.xmInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Close);
359
+
360
+ this.createInterstitialAd();
361
+ };
362
+ this.xmInterstitialAd.ad.onClose(this.xmInterstitialAd.closeListener);
363
+ }
364
+
365
+ public showInterstitialAd(): void {
366
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "showInterstitialAd()");
367
+
368
+ if (this.xmInterstitialAd.ad === null) {
369
+ return;
370
+ }
371
+
372
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.status=" + InterstitialAdStatus[this.xmInterstitialAd.status]);
373
+ switch(this.xmInterstitialAd.status) {
374
+ case InterstitialAdStatus.Status_Destroyed:
375
+ case InterstitialAdStatus.Status_Watching:
376
+ case InterstitialAdStatus.Status_StartToWatch:
377
+ break;
378
+ case InterstitialAdStatus.Status_Loaded:
379
+ this._showInterstitialAd();
380
+ break;
381
+ case InterstitialAdStatus.Status_Watched:
382
+ case InterstitialAdStatus.Status_Init:
383
+ case InterstitialAdStatus.Status_Error:
384
+ this.createInterstitialAd();
385
+ break;
386
+ default:
387
+ break;
388
+ }
389
+ }
390
+
391
+ public destroyInterstitialAd(): void {
392
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "destroyInterstitialAd()");
393
+ this.xmInterstitialAd.destroy();
394
+ }
395
+
396
+ public isIntersititialAdShowing(): boolean {
397
+ if (this.xmInterstitialAd.ad === null) {
398
+ return false;
399
+ }
400
+ if (this.xmInterstitialAd.status === InterstitialAdStatus.Status_Watching) {
401
+ return true;
402
+ }
403
+ return false;
404
+ }
405
+
406
+ protected _loadInterstitialAd(isShowImmediately: boolean): void {
407
+
408
+ }
409
+
410
+ protected _showInterstitialAd(): void {
411
+ if (this.xmInterstitialAd.status !== InterstitialAdStatus.Status_Loaded) {
412
+ return;
413
+ }
414
+
415
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_StartToWatch;
416
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.ad.show()");
417
+ this.xmInterstitialAd.ad.show()
418
+ .then(() => {
419
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.ad.show() success");
420
+
421
+ if (this.xmInterstitialAd.status === InterstitialAdStatus.Status_StartToWatch) {
422
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Watching;
423
+ this.xmInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Watching);
424
+ }
425
+ }).catch((err) => {
426
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.ad.show() error");
427
+ if (err) {
428
+ LogUtils.Instance.log("", err);
429
+ }
430
+
431
+ if (this.xmInterstitialAd.status === InterstitialAdStatus.Status_StartToWatch) {
432
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Loaded;
433
+ }
434
+ });
435
+ }
436
+
437
+ public createRewardedVideoAd(): void {
438
+ this.destroyRewardedVideoAd();
439
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "createRewardedVideoAd() adUnitId=" + this.xmRewardedVideoAd.unitId);
440
+
441
+ let rewardedVideoAd: any = window["qg"].createRewardedVideoAd({
442
+ adUnitId: this.xmRewardedVideoAd.unitId
443
+ });
444
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "qg.createRewardedVideoAd() " + (rewardedVideoAd !== null ? "success" : "fail"));
445
+ LogUtils.Instance.log("", rewardedVideoAd);
446
+ if (!rewardedVideoAd) {
447
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Error;
448
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Error);
449
+ return;
450
+ }
451
+
452
+ this.xmRewardedVideoAd.ad = rewardedVideoAd;
453
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Init;
454
+
455
+ this.xmRewardedVideoAd.errorListener = (err) => {
456
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.onError()");
457
+ if (err) {
458
+ LogUtils.Instance.log("", err);
459
+ }
460
+
461
+ if (this.xmRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Watching) {
462
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Error;
463
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Error);
464
+ }
465
+ };
466
+ this.xmRewardedVideoAd.ad.onError(this.xmRewardedVideoAd.errorListener);
467
+
468
+ this.xmRewardedVideoAd.loadListener = () => {
469
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.onLoad()");
470
+
471
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Loaded;
472
+
473
+ if (this.xmRewardedVideoAd.isShowImmediately) {
474
+ this.xmRewardedVideoAd.isShowImmediately = false;
475
+ this._showRewardedVideoAd();
476
+ }
477
+ };
478
+ this.xmRewardedVideoAd.ad.onLoad(this.xmRewardedVideoAd.loadListener);
479
+
480
+ this.xmRewardedVideoAd.closeListener = (res) => {
481
+ let isEnded: boolean = (res !== null) ? res.isEnded : false;
482
+
483
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.onClose()");
484
+ LogUtils.Instance.log("", "isEnded=" + isEnded);
485
+
486
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Watched;
487
+ if (isEnded) {
488
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Complete);
489
+ } else {
490
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Giveup);
491
+ }
492
+
493
+ this.scheduleOnce(() => {
494
+ if (this.xmRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Loaded) {
495
+ this._loadRewardedVideoAd(false);
496
+ }
497
+ }, 2);
498
+ };
499
+ this.xmRewardedVideoAd.ad.onClose(this.xmRewardedVideoAd.closeListener);
500
+
501
+ this.scheduleOnce(() => {
502
+ if (this.xmRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Loaded) {
503
+ this._loadRewardedVideoAd(false);
504
+ }
505
+ }, 2);
506
+ }
507
+
508
+ public showRewardedVideoAd(): void {
509
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "showRewardedVideoAd()");
510
+
511
+ if (this.xmRewardedVideoAd.ad === null) {
512
+ return;
513
+ }
514
+
515
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.status=" + RewardedVideoAdStatus[this.xmRewardedVideoAd.status]);
516
+ switch(this.xmRewardedVideoAd.status) {
517
+ case RewardedVideoAdStatus.Status_Destroyed:
518
+ case RewardedVideoAdStatus.Status_Watching:
519
+ case RewardedVideoAdStatus.Status_StartToWatch:
520
+ break;
521
+ case RewardedVideoAdStatus.Status_Loaded:
522
+ this._showRewardedVideoAd();
523
+ break;
524
+ case RewardedVideoAdStatus.Status_Watched:
525
+ case RewardedVideoAdStatus.Status_Error:
526
+ case RewardedVideoAdStatus.Status_Init:
527
+ this._loadRewardedVideoAd(true);
528
+ break;
529
+ default:
530
+ break;
531
+ }
532
+ }
533
+
534
+ public destroyRewardedVideoAd(): void {
535
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "destroyRewardedVideoAd()");
536
+ this.xmRewardedVideoAd.destroy();
537
+ }
538
+
539
+ public isRewardedVideoAdLoaded(): boolean {
540
+ if (this.xmRewardedVideoAd.ad === null) {
541
+ return false;
542
+ }
543
+ if (this.xmRewardedVideoAd.status === RewardedVideoAdStatus.Status_Loaded) {
544
+ return true;
545
+ }
546
+ return false;
547
+ }
548
+
549
+ public isRewardedVideoAdShowing(): boolean {
550
+ if (this.xmRewardedVideoAd.ad === null) {
551
+ return false;
552
+ }
553
+ if (this.xmRewardedVideoAd.status === RewardedVideoAdStatus.Status_Watching) {
554
+ return true;
555
+ }
556
+ return false;
557
+ }
558
+
559
+ protected _loadRewardedVideoAd(isShowImmediately: boolean): void {
560
+ this.xmRewardedVideoAd.isShowImmediately = isShowImmediately;
561
+
562
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.load()");
563
+ this.xmRewardedVideoAd.ad.load().then(() => {
564
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.load() success");
565
+ }).catch((err) => {
566
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.load() error");
567
+ if (err) {
568
+ LogUtils.Instance.log("", err);
569
+ }
570
+ });
571
+ }
572
+
573
+ protected _showRewardedVideoAd(): void {
574
+ if (this.xmRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Loaded) {
575
+ return;
576
+ }
577
+
578
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_StartToWatch;
579
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.show()");
580
+ this.xmRewardedVideoAd.ad.show()
581
+ .then(() => {
582
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.show() success");
583
+
584
+ if (this.xmRewardedVideoAd.status === RewardedVideoAdStatus.Status_StartToWatch) {
585
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Watching;
586
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Watching);
587
+ }
588
+ }).catch((err) => {
589
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.show() error");
590
+ if (err) {
591
+ LogUtils.Instance.log("", err);
592
+ }
593
+
594
+ if (this.xmRewardedVideoAd.status === RewardedVideoAdStatus.Status_StartToWatch) {
595
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Loaded;
596
+ }
597
+ });
598
+ }
599
+
600
+ public createCustomAd(adUnitId: string): boolean {
601
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "createCustomAd()");
602
+
603
+ let isFirstLoad: boolean = true;
604
+ for (let i = 0; i < this.xmCustomAds.length; i++) {
605
+ if (this.xmCustomAds[i].unitId === adUnitId) {
606
+ isFirstLoad = this.xmCustomAds[i].isFirstLoad;
607
+ break;
608
+ }
609
+ }
610
+
611
+ this.destroyCustomAd(adUnitId);
612
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "createCustomAd() adUnitId=" + adUnitId);
613
+
614
+ let customAdInfo: CustomAd_Info = AdDefinition.AdInfoConfig.CustomAd_Info;
615
+ if (customAdInfo === null || !customAdInfo.shouldShow) {
616
+ return;
617
+ }
618
+
619
+ let customAdPlatformInfo: CustomAd_PlatformInfo = AdDefinition.CustomAdStyleConfig.get(PlatformID.ID_QuickGame_XiaoMi);
620
+ if (customAdPlatformInfo === null) {
621
+ return false;
622
+ }
623
+
624
+ let customAdPostion: CustomAdPosition = this.calcCustomAdPosition(customAdInfo, customAdPlatformInfo);
625
+ let customAdParam: any = {
626
+ adUnitId: adUnitId,
627
+ style: {
628
+ left: customAdPostion.left,
629
+ top: customAdPostion.top,
630
+ width: customAdPostion.realWidth,
631
+ height: customAdPostion.realHeight,
632
+ }
633
+ };
634
+ if (customAdPlatformInfo.canAutoRefresh) {
635
+ customAdParam.adIntervals = customAdPlatformInfo.refreshInterval;
636
+ }
637
+
638
+ let customAd: any = window["qg"].createCustomAd(customAdParam);
639
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "qg.createCustomAd() " + (customAd !== null ? "success" : "fail"));
640
+ LogUtils.Instance.log("", customAd);
641
+ if (!customAd) {
642
+ return false;
643
+ }
644
+
645
+ let xmCustomAd: XMCustomAd = new XMCustomAd(adUnitId, customAd, isFirstLoad);
646
+ this.xmCustomAds.push(xmCustomAd);
647
+
648
+ xmCustomAd.errorListener = (err) => {
649
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmCustomAd.ad.onError()");
650
+ if (err) {
651
+ LogUtils.Instance.log("", err);
652
+ }
653
+
654
+ if (!xmCustomAd.isRecreating) {
655
+ xmCustomAd.isRecreating = true;
656
+
657
+ this.scheduleOnce(() => {
658
+ xmCustomAd.isRecreating = false;
659
+ this.createCustomAd(adUnitId);
660
+ }, 15);
661
+ }
662
+ };
663
+ xmCustomAd.ad.onError(xmCustomAd.errorListener);
664
+
665
+ xmCustomAd.loadListener = () => {
666
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmCustomAd.ad.onLoad()");
667
+
668
+ if (xmCustomAd.isFirstLoad) {
669
+ xmCustomAd.isFirstLoad = false;
670
+ }
671
+
672
+ if (this.adMgr.isPermanentAdShowing()) {
673
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmCustomAd.ad.show()");
674
+ xmCustomAd.ad.show();
675
+ }
676
+ };
677
+ xmCustomAd.ad.onLoad(xmCustomAd.loadListener);
678
+
679
+ if (!customAdPlatformInfo.canAutoRefresh) {
680
+ if (!xmCustomAd.isRecreating) {
681
+ xmCustomAd.isRecreating = true;
682
+
683
+ this.scheduleOnce(() => {
684
+ xmCustomAd.isRecreating = false;
685
+ this.createCustomAd(adUnitId);
686
+ }, customAdPlatformInfo.refreshInterval);
687
+ }
688
+ }
689
+
690
+ return true;
691
+ }
692
+
693
+ public destroyCustomAd(adUnitId: string): void {
694
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "destroyCustomAd(): adUnitId=" + adUnitId);
695
+
696
+ let index: number = -1;
697
+ for (let i = 0; i < this.xmCustomAds.length; i++) {
698
+ if (this.xmCustomAds[i].unitId === adUnitId) {
699
+ index = i;
700
+ break;
701
+ }
702
+ }
703
+
704
+ if (index >= 0) {
705
+ this.xmCustomAds[index].destroy();
706
+ this.xmCustomAds.splice(index, 1);
707
+ }
708
+ }
709
+
710
+ public showCustomAd(adUnitId: string): void {
711
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "showCustomAd(): adUnitId=" + adUnitId);
712
+
713
+ for (let i = 0; i < this.xmCustomAds.length; i++) {
714
+ if (this.xmCustomAds[i].unitId === adUnitId) {
715
+ this.xmCustomAds[i].ad.show();
716
+ break;
717
+ }
718
+ }
719
+ }
720
+
721
+ public hideCustomAd(adUnitId: string): void {
722
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "hideCustomAd(): adUnitId=" + adUnitId);
723
+
724
+ for (let i = 0; i < this.xmCustomAds.length; i++) {
725
+ if (this.xmCustomAds[i].unitId === adUnitId) {
726
+ this.xmCustomAds[i].ad.hide();
727
+ break;
728
+ }
729
+ }
730
+ }
731
+
732
+ public createPortalAd(adUnitId: string): void {
733
+
734
+ }
735
+
736
+ public destroyPortalAd(adUnitId: string): void {
737
+
738
+ }
739
+
740
+ public showPortalAd(adUnitId: string): void {
741
+
742
+ }
743
+
744
+ public hidePortalAd(adUnitId: string): void {
745
+
746
+ }
747
+ }