@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,847 @@
1
+ import { AbsAdAdapter, BannerAdPosition, CustomAdPosition, InterstitialAdStatus, PortalAdPosition, RewardedVideoAdStatus } from './AbsAdAdapter';
2
+ import { LogUtils } from '../../Utils/LogUtils';
3
+ import { BannerAd_Info, BannerAd_PlatformInfo, InterstitialAd_Callback_Status, RewardedVideoAd_Callback_Status, CustomAd_Info, CustomAd_PlatformInfo, PortalAd_PlatformInfo, AdDefinition } from '../../Definition/AdDefinition';
4
+ import { PlatformID } from '../../Definition/SystemDefinition';
5
+
6
+ class WXInterstitialAd {
7
+ unitId: string;
8
+ ad: any;
9
+ status: InterstitialAdStatus;
10
+ callback: Function;
11
+ errorListener: Function;
12
+ loadListener: Function;
13
+ closeListener: Function;
14
+ isShowImmediately: boolean;
15
+
16
+ constructor(adUnitId: string, callback: Function) {
17
+ this.unitId = adUnitId;
18
+ this.ad = null;
19
+ this.status = InterstitialAdStatus.Status_Init;
20
+ this.callback = callback;
21
+ this.errorListener = null;
22
+ this.loadListener = null;
23
+ this.closeListener = null;
24
+ this.isShowImmediately = false;
25
+ }
26
+
27
+ public destroy(): void {
28
+ if (this.ad !== null) {
29
+ if (this.errorListener !== null) {
30
+ this.ad.offError(this.errorListener);
31
+ this.errorListener = null;
32
+ }
33
+ if (this.loadListener !== null) {
34
+ this.ad.offLoad(this.loadListener);
35
+ this.loadListener = null;
36
+ }
37
+ if (this.closeListener !== null) {
38
+ this.ad.offClose(this.closeListener);
39
+ this.closeListener = null;
40
+ }
41
+
42
+ this.ad.destroy();
43
+ this.ad = null;
44
+ }
45
+ this.isShowImmediately = false;
46
+ this.status = InterstitialAdStatus.Status_Destroyed;
47
+ }
48
+ }
49
+
50
+ class WXRewardedVideoAd {
51
+ unitId: string;
52
+ ad: any;
53
+ status: RewardedVideoAdStatus;
54
+ callback: Function;
55
+ errorListener: Function;
56
+ loadListener: Function;
57
+ closeListener: Function;
58
+ isShowImmediately: boolean;
59
+
60
+ constructor(adUnitId: string, callback: Function) {
61
+ this.unitId = adUnitId;
62
+ this.ad = null;
63
+ this.status = RewardedVideoAdStatus.Status_Init;
64
+ this.callback = callback;
65
+ this.errorListener = null;
66
+ this.loadListener = null;
67
+ this.closeListener = null;
68
+ this.isShowImmediately = false;
69
+ }
70
+
71
+ public destroy(): void {
72
+ if (this.ad !== null) {
73
+ if (this.errorListener !== null) {
74
+ this.ad.offError(this.errorListener);
75
+ this.errorListener = null;
76
+ }
77
+ if (this.loadListener !== null) {
78
+ this.ad.offLoad(this.loadListener);
79
+ this.loadListener = null;
80
+ }
81
+ if (this.closeListener !== null) {
82
+ this.ad.offClose(this.closeListener);
83
+ this.closeListener = null;
84
+ }
85
+
86
+ this.ad.destroy();
87
+ this.ad = null;
88
+ }
89
+ this.isShowImmediately = false;
90
+ this.status = RewardedVideoAdStatus.Status_Destroyed;
91
+ }
92
+ }
93
+
94
+ class WXCustomAd {
95
+ unitId: string;
96
+ ad: any;
97
+ errorListener: Function;
98
+ loadListener: Function;
99
+ resizeListener: Function;
100
+ closeListener: Function;
101
+ isRecreating: boolean;
102
+ isFirstLoad: boolean;
103
+
104
+ constructor(adUnitId: string, ad: any, isFirstLoad: boolean) {
105
+ this.unitId = adUnitId;
106
+ this.ad = ad;
107
+ this.errorListener = null;
108
+ this.loadListener = null;
109
+ this.resizeListener = null;
110
+ this.closeListener = null;
111
+ this.isRecreating = false;
112
+ this.isFirstLoad = isFirstLoad;
113
+ }
114
+
115
+ public destroy(): void {
116
+ if (this.ad !== null) {
117
+ if (this.errorListener !== null) {
118
+ this.ad.offError(this.errorListener);
119
+ this.errorListener = null;
120
+ }
121
+ if (this.loadListener !== null) {
122
+ this.ad.offLoad(this.loadListener);
123
+ this.loadListener = null;
124
+ }
125
+ if (this.resizeListener !== null) {
126
+ this.ad.offResize(this.resizeListener);
127
+ this.resizeListener = null;
128
+ }
129
+ if (this.closeListener !== null) {
130
+ this.ad.offClose(this.closeListener);
131
+ this.closeListener = null;
132
+ }
133
+
134
+ this.ad.destroy();
135
+ this.ad = null;
136
+ }
137
+ this.isRecreating = false;
138
+ }
139
+ }
140
+
141
+ export class AdAdapterWeiXin extends AbsAdAdapter {
142
+ static TAG: string = "AdAdapterWeiXin";
143
+
144
+ private wxInterstitialAd: WXInterstitialAd = null;
145
+ private wxRewardedVideoAd: WXRewardedVideoAd = null;
146
+ private wxCustomAds: WXCustomAd[] = [];
147
+
148
+ public init(interstitialAdUnitId: string, interstitialAdCallback: Function,
149
+ rewardedVideoAdUnitId: string, rewardedVideoAdCallback: Function): void {
150
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "init()");
151
+
152
+ this.wxInterstitialAd = new WXInterstitialAd(interstitialAdUnitId, interstitialAdCallback);
153
+ this.wxRewardedVideoAd = new WXRewardedVideoAd(rewardedVideoAdUnitId, rewardedVideoAdCallback);
154
+
155
+ this.wxCustomAds = [];
156
+ }
157
+
158
+ public createBannerAd(adUnitId: string): boolean {
159
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "createBannerAd()");
160
+
161
+ let isFirstLoad: boolean = true;
162
+ for (let i = 0; i < this.wxCustomAds.length; i++) {
163
+ if (this.wxCustomAds[i].unitId === adUnitId) {
164
+ isFirstLoad = this.wxCustomAds[i].isFirstLoad;
165
+ break;
166
+ }
167
+ }
168
+
169
+ this.destroyBannerAd(adUnitId);
170
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "createBannerAd() adUnitId=" + adUnitId);
171
+
172
+ let bannerAdInfo: BannerAd_Info = AdDefinition.AdInfoConfig.BannerAd_Info;
173
+ if (bannerAdInfo === null || !bannerAdInfo.shouldShow) {
174
+ return false;
175
+ }
176
+
177
+ let bannerAdPlatformInfo: BannerAd_PlatformInfo = AdDefinition.BannerAdStyleConfig.get(PlatformID.ID_MiniGame_WeiXin);
178
+ if (bannerAdPlatformInfo === null) {
179
+ return false;
180
+ }
181
+
182
+ let bannerAdPostion: BannerAdPosition = this.calcBannerAdPosition(bannerAdInfo, bannerAdPlatformInfo);
183
+ let customAdParam: any = {
184
+ adUnitId: adUnitId,
185
+ style: {
186
+ left: bannerAdPostion.left,
187
+ top: bannerAdPostion.top,
188
+ width: bannerAdPostion.realWidth,
189
+ fixed: true,
190
+ }
191
+ };
192
+ if (bannerAdPlatformInfo.canAutoRefresh) {
193
+ customAdParam.adIntervals = bannerAdPlatformInfo.refreshInterval;
194
+ }
195
+
196
+ let customAd: any = window["wx"].createCustomAd(customAdParam);
197
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wx.createCustomAd() " + (customAd !== null ? "success" : "fail"));
198
+ LogUtils.Instance.log("", customAd);
199
+ if (!customAd) {
200
+ return false;
201
+ }
202
+
203
+ let wxCustomAd: WXCustomAd = new WXCustomAd(adUnitId, customAd, isFirstLoad);
204
+ this.wxCustomAds.push(wxCustomAd);
205
+
206
+ wxCustomAd.errorListener = (err) => {
207
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.onError()");
208
+ if (err) {
209
+ LogUtils.Instance.log("", err);
210
+ }
211
+
212
+ if (!wxCustomAd.isRecreating) {
213
+ wxCustomAd.isRecreating = true;
214
+
215
+ this.scheduleOnce(() => {
216
+ wxCustomAd.isRecreating = false;
217
+ this.createCustomAd(adUnitId);
218
+ }, 15);
219
+ }
220
+ };
221
+ wxCustomAd.ad.onError(wxCustomAd.errorListener);
222
+
223
+ wxCustomAd.loadListener = () => {
224
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.onLoad()");
225
+
226
+ if (wxCustomAd.isFirstLoad) {
227
+ wxCustomAd.isFirstLoad = false;
228
+ }
229
+
230
+ if (this.adMgr.isPermanentAdShowing()) {
231
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.show()");
232
+ wxCustomAd.ad.show()
233
+ .then(() => {
234
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.show() success");
235
+ }).catch((err) => {
236
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.show() fail");
237
+ if (err) {
238
+ LogUtils.Instance.log("", err);
239
+ }
240
+ });
241
+ }
242
+ };
243
+ wxCustomAd.ad.onLoad(wxCustomAd.loadListener);
244
+
245
+ wxCustomAd.resizeListener = (res) => {
246
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.onResize()");
247
+ if (res) {
248
+ LogUtils.Instance.log("", res);
249
+ }
250
+ };
251
+ wxCustomAd.ad.onResize(wxCustomAd.resizeListener);
252
+
253
+ wxCustomAd.closeListener = () => {
254
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.onClose()");
255
+ };
256
+ wxCustomAd.ad.onClose(wxCustomAd.closeListener);
257
+
258
+ if (!bannerAdPlatformInfo.canAutoRefresh) {
259
+ if (!wxCustomAd.isRecreating) {
260
+ wxCustomAd.isRecreating = true;
261
+
262
+ this.scheduleOnce(() => {
263
+ wxCustomAd.isRecreating = false;
264
+ this.createBannerAd(adUnitId);
265
+ }, bannerAdPlatformInfo.refreshInterval);
266
+ }
267
+ }
268
+
269
+ return true;
270
+ }
271
+
272
+ public destroyBannerAd(adUnitId: string): void {
273
+ this.destroyCustomAd(adUnitId);
274
+ }
275
+
276
+ public showBannerAd(adUnitId: string): void {
277
+ this.showCustomAd(adUnitId);
278
+ }
279
+
280
+ public hideBannerAd(adUnitId: string): void {
281
+ this.hideCustomAd(adUnitId);
282
+ }
283
+
284
+ public createInterstitialAd(): void {
285
+ this.destroyInterstitialAd();
286
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "createInterstitialAd() adUnitId=" + this.wxInterstitialAd.unitId);
287
+
288
+ let interstitialAd: any = window["wx"].createInterstitialAd({
289
+ adUnitId: this.wxInterstitialAd.unitId
290
+ });
291
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wx.createInterstitialAd() " + (interstitialAd !== null ? "success" : "fail"));
292
+ LogUtils.Instance.log("", interstitialAd);
293
+ if (!interstitialAd) {
294
+ this.wxInterstitialAd.status = InterstitialAdStatus.Status_Error;
295
+ this.wxInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Error);
296
+ return;
297
+ }
298
+
299
+ this.wxInterstitialAd.ad = interstitialAd;
300
+ this.wxInterstitialAd.status = InterstitialAdStatus.Status_Init;
301
+
302
+ this.wxInterstitialAd.errorListener = (err) => {
303
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxInterstitialAd.ad.onError()");
304
+ if (err) {
305
+ LogUtils.Instance.log("", err);
306
+ }
307
+
308
+ if (this.wxInterstitialAd.status !== InterstitialAdStatus.Status_Watching) {
309
+ this.wxInterstitialAd.status = InterstitialAdStatus.Status_Error;
310
+ this.wxInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Error);
311
+ }
312
+ };
313
+ this.wxInterstitialAd.ad.onError(this.wxInterstitialAd.errorListener);
314
+
315
+ this.wxInterstitialAd.loadListener = () => {
316
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxInterstitialAd.ad.onLoad()");
317
+
318
+ this.wxInterstitialAd.status = InterstitialAdStatus.Status_Loaded;
319
+
320
+ if (this.wxInterstitialAd.isShowImmediately) {
321
+ this.wxInterstitialAd.isShowImmediately = false;
322
+ this._showInterstitialAd();
323
+ }
324
+ };
325
+ this.wxInterstitialAd.ad.onLoad(this.wxInterstitialAd.loadListener);
326
+
327
+ this.wxInterstitialAd.closeListener = () => {
328
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxInterstitialAd.ad.onClose()");
329
+
330
+ this.wxInterstitialAd.status = InterstitialAdStatus.Status_Watched;
331
+ this.wxInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Close);
332
+
333
+ this.scheduleOnce(() => {
334
+ if (this.wxInterstitialAd.status !== InterstitialAdStatus.Status_Loaded) {
335
+ this._loadInterstitialAd(false);
336
+ }
337
+ }, 2);
338
+ };
339
+ this.wxInterstitialAd.ad.onClose(this.wxInterstitialAd.closeListener);
340
+
341
+ this.scheduleOnce(() => {
342
+ if (this.wxInterstitialAd.status !== InterstitialAdStatus.Status_Loaded) {
343
+ this._loadInterstitialAd(false);
344
+ }
345
+ }, 2);
346
+ }
347
+
348
+ public showInterstitialAd(): void {
349
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "showInterstitialAd()");
350
+
351
+ if (this.wxInterstitialAd.ad === null) {
352
+ return;
353
+ }
354
+
355
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxInterstitialAd.status=" + InterstitialAdStatus[this.wxInterstitialAd.status]);
356
+ switch(this.wxInterstitialAd.status) {
357
+ case InterstitialAdStatus.Status_Destroyed:
358
+ case InterstitialAdStatus.Status_Watching:
359
+ case InterstitialAdStatus.Status_StartToWatch:
360
+ break;
361
+ case InterstitialAdStatus.Status_Loaded:
362
+ this._showInterstitialAd();
363
+ break;
364
+ case InterstitialAdStatus.Status_Watched:
365
+ case InterstitialAdStatus.Status_Init:
366
+ case InterstitialAdStatus.Status_Error:
367
+ this._loadInterstitialAd(true);
368
+ break;
369
+ default:
370
+ break;
371
+ }
372
+ }
373
+
374
+ public destroyInterstitialAd(): void {
375
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "destroyInterstitialAd()");
376
+ this.wxInterstitialAd.destroy();
377
+ }
378
+
379
+ public isIntersititialAdShowing(): boolean {
380
+ if (this.wxInterstitialAd.ad === null) {
381
+ return false;
382
+ }
383
+ if (this.wxInterstitialAd.status === InterstitialAdStatus.Status_Watching) {
384
+ return true;
385
+ }
386
+ return false;
387
+ }
388
+
389
+ protected _loadInterstitialAd(isShowImmediately: boolean): void {
390
+ this.wxInterstitialAd.isShowImmediately = isShowImmediately;
391
+
392
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxInterstitialAd.ad.load()");
393
+ this.wxInterstitialAd.ad.load()
394
+ .then(() => {
395
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxInterstitialAd.ad.load() success");
396
+ }).catch((err) => {
397
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxInterstitialAd.ad.load() error");
398
+ if (err) {
399
+ LogUtils.Instance.log("", err);
400
+ }
401
+ });
402
+ }
403
+
404
+ protected _showInterstitialAd(): void {
405
+ if (this.wxInterstitialAd.status !== InterstitialAdStatus.Status_Loaded) {
406
+ return;
407
+ }
408
+
409
+ this.wxInterstitialAd.status = InterstitialAdStatus.Status_StartToWatch;
410
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxInterstitialAd.ad.show()");
411
+ this.wxInterstitialAd.ad.show()
412
+ .then(() => {
413
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxInterstitialAd.ad.show() success");
414
+
415
+ if (this.wxInterstitialAd.status === InterstitialAdStatus.Status_StartToWatch) {
416
+ this.wxInterstitialAd.status = InterstitialAdStatus.Status_Watching;
417
+ this.wxInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Watching);
418
+ }
419
+ }).catch((err) => {
420
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxInterstitialAd.ad.show() error");
421
+ if (err) {
422
+ LogUtils.Instance.log("", err);
423
+ }
424
+
425
+ if (this.wxInterstitialAd.status === InterstitialAdStatus.Status_StartToWatch) {
426
+ this.wxInterstitialAd.status = InterstitialAdStatus.Status_Loaded;
427
+ }
428
+ });
429
+ }
430
+
431
+ public createRewardedVideoAd(): void {
432
+ this.destroyRewardedVideoAd();
433
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "createRewardedVideoAd() adUnitId=" + this.wxRewardedVideoAd.unitId);
434
+
435
+ let rewardedVideoAd: any = window["wx"].createRewardedVideoAd({
436
+ adUnitId: this.wxRewardedVideoAd.unitId,
437
+ });
438
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wx.createRewardedVideoAd() " + (rewardedVideoAd !== null ? "success" : "fail"));
439
+ LogUtils.Instance.log("", rewardedVideoAd);
440
+ if (!rewardedVideoAd) {
441
+ this.wxRewardedVideoAd.status = RewardedVideoAdStatus.Status_Error;
442
+ this.wxRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Error);
443
+ return;
444
+ }
445
+
446
+ this.wxRewardedVideoAd.ad = rewardedVideoAd;
447
+ this.wxRewardedVideoAd.status = RewardedVideoAdStatus.Status_Init;
448
+
449
+ this.wxRewardedVideoAd.errorListener = (err) => {
450
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxRewardedVideoAd.ad.onError()");
451
+
452
+ if (err) {
453
+ LogUtils.Instance.log("", err);
454
+ }
455
+
456
+ if (this.wxRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Watching) {
457
+ this.wxRewardedVideoAd.status = RewardedVideoAdStatus.Status_Error;
458
+ this.wxRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Error);
459
+ }
460
+ };
461
+ this.wxRewardedVideoAd.ad.onError(this.wxRewardedVideoAd.errorListener);
462
+
463
+ this.wxRewardedVideoAd.loadListener = (res: any) => {
464
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxRewardedVideoAd.ad.onLoad()");
465
+
466
+ this.wxRewardedVideoAd.status = RewardedVideoAdStatus.Status_Loaded;
467
+
468
+ if (this.wxRewardedVideoAd.isShowImmediately) {
469
+ this.wxRewardedVideoAd.isShowImmediately = false;
470
+ this._showRewardedVideoAd();
471
+ }
472
+ };
473
+ this.wxRewardedVideoAd.ad.onLoad(this.wxRewardedVideoAd.loadListener);
474
+
475
+ this.wxRewardedVideoAd.closeListener = (res) => {
476
+ let isEnded: boolean = (res !== null) ? res.isEnded : false;
477
+
478
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxRewardedVideoAd.ad.onClose()");
479
+ LogUtils.Instance.log("", "isEnded=" + isEnded);
480
+
481
+ this.wxRewardedVideoAd.status = RewardedVideoAdStatus.Status_Watched;
482
+ if (isEnded) {
483
+ this.wxRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Complete);
484
+ } else {
485
+ this.wxRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Giveup);
486
+ }
487
+
488
+ this.scheduleOnce(() => {
489
+ if (this.wxRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Loaded) {
490
+ this._loadRewardedVideoAd(false);
491
+ }
492
+ }, 2);
493
+ };
494
+ this.wxRewardedVideoAd.ad.onClose(this.wxRewardedVideoAd.closeListener);
495
+
496
+ this.scheduleOnce(() => {
497
+ if (this.wxRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Loaded) {
498
+ this._loadRewardedVideoAd(false);
499
+ }
500
+ }, 2);
501
+ }
502
+
503
+ public showRewardedVideoAd(): void {
504
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "showRewardedVideoAd()");
505
+
506
+ if (this.wxRewardedVideoAd.ad === null) {
507
+ return;
508
+ }
509
+
510
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxRewardedVideoAd.status=" + RewardedVideoAdStatus[this.wxRewardedVideoAd.status]);
511
+ switch(this.wxRewardedVideoAd.status) {
512
+ case RewardedVideoAdStatus.Status_Destroyed:
513
+ case RewardedVideoAdStatus.Status_StartToWatch:
514
+ case RewardedVideoAdStatus.Status_Watching:
515
+ break;
516
+ case RewardedVideoAdStatus.Status_Loaded:
517
+ this._showRewardedVideoAd();
518
+ break;
519
+ case RewardedVideoAdStatus.Status_Watched:
520
+ case RewardedVideoAdStatus.Status_Init:
521
+ case RewardedVideoAdStatus.Status_Error:
522
+ this._loadRewardedVideoAd(true);
523
+ break;
524
+ default:
525
+ break;
526
+ }
527
+ }
528
+
529
+ public destroyRewardedVideoAd(): void {
530
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "destroyRewardedVideoAd()");
531
+ this.wxRewardedVideoAd.destroy();
532
+ }
533
+
534
+ public isRewardedVideoAdLoaded(): boolean {
535
+ if (this.wxRewardedVideoAd.ad === null) {
536
+ return false;
537
+ }
538
+ if (this.wxRewardedVideoAd.status === RewardedVideoAdStatus.Status_Loaded) {
539
+ return true;
540
+ }
541
+ return false;
542
+ }
543
+
544
+ public isRewardedVideoAdShowing(): boolean {
545
+ if (this.wxRewardedVideoAd.ad === null) {
546
+ return false;
547
+ }
548
+ if (this.wxRewardedVideoAd.status === RewardedVideoAdStatus.Status_Watching) {
549
+ return true;
550
+ }
551
+ return false;
552
+ }
553
+
554
+ protected _loadRewardedVideoAd(isShowImmediately: boolean): void {
555
+ this.wxRewardedVideoAd.isShowImmediately = isShowImmediately;
556
+
557
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxRewardedVideoAd.ad.load()");
558
+ this.wxRewardedVideoAd.ad.load()
559
+ .then(() => {
560
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxRewardedVideoAd.ad.load() success");
561
+ }).catch((err) => {
562
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxRewardedVideoAd.ad.load() error");
563
+ if (err) {
564
+ LogUtils.Instance.log("", err);
565
+ }
566
+ });
567
+ }
568
+
569
+ protected _showRewardedVideoAd(): void {
570
+ if (this.wxRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Loaded) {
571
+ return;
572
+ }
573
+
574
+ this.wxRewardedVideoAd.status = RewardedVideoAdStatus.Status_StartToWatch;
575
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxRewardedVideoAd.ad.show()");
576
+ this.wxRewardedVideoAd.ad.show()
577
+ .then(() => {
578
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxRewardedVideoAd.ad.show() success");
579
+
580
+ if (this.wxRewardedVideoAd.status === RewardedVideoAdStatus.Status_StartToWatch) {
581
+ this.wxRewardedVideoAd.status = RewardedVideoAdStatus.Status_Watching;
582
+ this.wxRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Watching);
583
+ }
584
+ }).catch((err) => {
585
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxRewardedVideoAd.ad.show() error");
586
+ if (err) {
587
+ LogUtils.Instance.log("", err);
588
+ }
589
+
590
+ if (this.wxRewardedVideoAd.status === RewardedVideoAdStatus.Status_StartToWatch) {
591
+ this.wxRewardedVideoAd.status = RewardedVideoAdStatus.Status_Loaded;
592
+ }
593
+ });
594
+ }
595
+
596
+ public createCustomAd(adUnitId: string): boolean {
597
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "createCustomAd()");
598
+
599
+ let isFirstLoad: boolean = true;
600
+ for (let i = 0; i < this.wxCustomAds.length; i++) {
601
+ if (this.wxCustomAds[i].unitId === adUnitId) {
602
+ isFirstLoad = this.wxCustomAds[i].isFirstLoad;
603
+ break;
604
+ }
605
+ }
606
+
607
+ this.destroyCustomAd(adUnitId);
608
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "createCustomAd() adUnitId=" + adUnitId);
609
+
610
+ let customAdInfo: CustomAd_Info = AdDefinition.AdInfoConfig.CustomAd_Info;
611
+ if (customAdInfo === null || !customAdInfo.shouldShow) {
612
+ return;
613
+ }
614
+
615
+ let customAdPlatformInfo: CustomAd_PlatformInfo = AdDefinition.CustomAdStyleConfig.get(PlatformID.ID_MiniGame_WeiXin);
616
+ if (customAdPlatformInfo === null) {
617
+ return false;
618
+ }
619
+
620
+ let customAdPostion: CustomAdPosition = this.calcCustomAdPosition(customAdInfo, customAdPlatformInfo);
621
+ let customAdParam: any = {
622
+ adUnitId: adUnitId,
623
+ style: {
624
+ left: customAdPostion.left,
625
+ top: customAdPostion.top,
626
+ width: customAdPostion.realWidth,
627
+ fixed: true,
628
+ }
629
+ };
630
+ if (customAdPlatformInfo.canAutoRefresh) {
631
+ customAdParam.adIntervals = customAdPlatformInfo.refreshInterval;
632
+ }
633
+
634
+ let customAd: any = window["wx"].createCustomAd(customAdParam);
635
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wx.createCustomAd() " + (customAd !== null ? "success" : "fail"));
636
+ LogUtils.Instance.log("", customAd);
637
+ if (!customAd) {
638
+ return false;
639
+ }
640
+
641
+ let wxCustomAd: WXCustomAd = new WXCustomAd(adUnitId, customAd, isFirstLoad);
642
+ this.wxCustomAds.push(wxCustomAd);
643
+
644
+ wxCustomAd.errorListener = (err) => {
645
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.onError()");
646
+ if (err) {
647
+ LogUtils.Instance.log("", err);
648
+ }
649
+
650
+ if (!wxCustomAd.isRecreating) {
651
+ wxCustomAd.isRecreating = true;
652
+
653
+ this.scheduleOnce(() => {
654
+ wxCustomAd.isRecreating = false;
655
+ this.createCustomAd(adUnitId);
656
+ }, 15);
657
+ }
658
+ };
659
+ wxCustomAd.ad.onError(wxCustomAd.errorListener);
660
+
661
+ wxCustomAd.loadListener = () => {
662
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.onLoad()");
663
+
664
+ if (wxCustomAd.isFirstLoad) {
665
+ wxCustomAd.isFirstLoad = false;
666
+ }
667
+
668
+ if (this.adMgr.isPermanentAdShowing()) {
669
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.show()");
670
+ wxCustomAd.ad.show()
671
+ .then(() => {
672
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.show() success");
673
+ }).catch((err) => {
674
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.show() fail");
675
+ if (err) {
676
+ LogUtils.Instance.log("", err);
677
+ }
678
+ });
679
+ }
680
+ };
681
+ wxCustomAd.ad.onLoad(wxCustomAd.loadListener);
682
+
683
+ wxCustomAd.resizeListener = (res) => {
684
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.onResize()");
685
+ if (res) {
686
+ LogUtils.Instance.log("", res);
687
+ }
688
+ };
689
+ wxCustomAd.ad.onResize(wxCustomAd.resizeListener);
690
+
691
+ wxCustomAd.closeListener = () => {
692
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.onClose()");
693
+ };
694
+ wxCustomAd.ad.onClose(wxCustomAd.closeListener);
695
+
696
+ if (!customAdPlatformInfo.canAutoRefresh) {
697
+ if (!wxCustomAd.isRecreating) {
698
+ wxCustomAd.isRecreating = true;
699
+
700
+ this.scheduleOnce(() => {
701
+ wxCustomAd.isRecreating = false;
702
+ this.createCustomAd(adUnitId);
703
+ }, customAdPlatformInfo.refreshInterval);
704
+ }
705
+ }
706
+
707
+ return true;
708
+ }
709
+
710
+ public destroyCustomAd(adUnitId: string): void {
711
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "destroyCustomAd(): adUnitId=" + adUnitId);
712
+
713
+ let index: number = -1;
714
+ for (let i = 0; i < this.wxCustomAds.length; i++) {
715
+ if (this.wxCustomAds[i].unitId === adUnitId) {
716
+ index = i;
717
+ break;
718
+ }
719
+ }
720
+
721
+ if (index >= 0) {
722
+ this.wxCustomAds[index].destroy();
723
+ this.wxCustomAds.splice(index, 1);
724
+ }
725
+ }
726
+
727
+ public showCustomAd(adUnitId: string): void {
728
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "showCustomAd(): adUnitId=" + adUnitId);
729
+
730
+ for (let i = 0; i < this.wxCustomAds.length; i++) {
731
+ if (this.wxCustomAds[i].unitId === adUnitId) {
732
+ let customAd = this.wxCustomAds[i];
733
+ if (!customAd.ad.isShow()) {
734
+ customAd.ad.show();
735
+ }
736
+ break;
737
+ }
738
+ }
739
+ }
740
+
741
+ public hideCustomAd(adUnitId: string): void {
742
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "hideCustomAd(): adUnitId=" + adUnitId);
743
+
744
+ for (let i = 0; i < this.wxCustomAds.length; i++) {
745
+ if (this.wxCustomAds[i].unitId === adUnitId) {
746
+ let customAd = this.wxCustomAds[i];
747
+ if (customAd.ad.isShow()) {
748
+ customAd.ad.hide();
749
+ }
750
+ break;
751
+ }
752
+ }
753
+ }
754
+
755
+ public createPortalAd(adUnitId: string): boolean {
756
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "createPortalAd()");
757
+
758
+ let isFirstLoad: boolean = true;
759
+ for (let i = 0; i < this.wxCustomAds.length; i++) {
760
+ if (this.wxCustomAds[i].unitId === adUnitId) {
761
+ isFirstLoad = this.wxCustomAds[i].isFirstLoad;
762
+ break;
763
+ }
764
+ }
765
+
766
+ this.destroyPortalAd(adUnitId);
767
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "createPortalAd() adUnitId=" + adUnitId);
768
+
769
+ let portalAdPlatformInfo: PortalAd_PlatformInfo = AdDefinition.PortalAdStyleConfig.get(PlatformID.ID_MiniGame_WeiXin);
770
+ if (portalAdPlatformInfo === null) {
771
+ return false;
772
+ }
773
+
774
+ let portalAdPostion: PortalAdPosition = this.calcPortalAdPosition(portalAdPlatformInfo);
775
+ let customAdParam: any = {
776
+ adUnitId: adUnitId,
777
+ style: {
778
+ left: portalAdPostion.left,
779
+ top: portalAdPostion.top,
780
+ width: portalAdPostion.realWidth,
781
+ fixed: true,
782
+ },
783
+ adIntervals: 30,
784
+ }
785
+
786
+ let customAd: any = window["wx"].createCustomAd(customAdParam);
787
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wx.createCustomAd() " + (customAd !== null ? "success" : "fail"));
788
+ LogUtils.Instance.log("", customAd);
789
+ if (!customAd) {
790
+ return;
791
+ }
792
+
793
+ let wxCustomAd: WXCustomAd = new WXCustomAd(adUnitId, customAd, isFirstLoad);
794
+ this.wxCustomAds.push(wxCustomAd);
795
+
796
+ wxCustomAd.errorListener = (err) => {
797
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.onError()");
798
+ if (err) {
799
+ LogUtils.Instance.log("", err);
800
+ }
801
+
802
+ if (!wxCustomAd.isRecreating) {
803
+ wxCustomAd.isRecreating = true;
804
+
805
+ this.scheduleOnce(() => {
806
+ wxCustomAd.isRecreating = false;
807
+ this.createPortalAd(adUnitId);
808
+ }, 15);
809
+ }
810
+ };
811
+ wxCustomAd.ad.onError(wxCustomAd.errorListener);
812
+
813
+ wxCustomAd.loadListener = () => {
814
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.onLoad()");
815
+
816
+ if (wxCustomAd.isFirstLoad) {
817
+ wxCustomAd.isFirstLoad = false;
818
+ }
819
+ };
820
+ wxCustomAd.ad.onLoad(wxCustomAd.loadListener);
821
+
822
+ wxCustomAd.resizeListener = (res) => {
823
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.onResize()");
824
+ if (res) {
825
+ LogUtils.Instance.log("", res);
826
+ }
827
+ };
828
+ wxCustomAd.ad.onResize(wxCustomAd.resizeListener);
829
+
830
+ wxCustomAd.closeListener = () => {
831
+ LogUtils.Instance.log(AdAdapterWeiXin.TAG, "wxCustomAd.ad.onClose()");
832
+ };
833
+ wxCustomAd.ad.onClose(wxCustomAd.closeListener);
834
+ }
835
+
836
+ public destroyPortalAd(adUnitId: string): void {
837
+ this.destroyCustomAd(adUnitId);
838
+ }
839
+
840
+ public showPortalAd(adUnitId: string): void {
841
+ this.showCustomAd(adUnitId);
842
+ }
843
+
844
+ public hidePortalAd(adUnitId: string): void {
845
+ this.hideCustomAd(adUnitId);
846
+ }
847
+ }