040128ae-bf3a-48c6-acf7-a910c8189e5b.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. "use strict";
  2. cc._RF.push(module, '04012iuvzpIxqz3qRDIGJ5b', 'Interstitial');
  3. // Script/sdk/vivo/Interstitial.ts
  4. "use strict";
  5. // Learn TypeScript:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  7. // Learn Attribute:
  8. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  9. // Learn life-cycle callbacks:
  10. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  11. var __extends = (this && this.__extends) || (function () {
  12. var extendStatics = function (d, b) {
  13. extendStatics = Object.setPrototypeOf ||
  14. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  15. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  16. return extendStatics(d, b);
  17. };
  18. return function (d, b) {
  19. extendStatics(d, b);
  20. function __() { this.constructor = d; }
  21. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  22. };
  23. })();
  24. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  25. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  26. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  27. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  28. return c > 3 && r && Object.defineProperty(target, key, r), r;
  29. };
  30. Object.defineProperty(exports, "__esModule", { value: true });
  31. exports.InterstitialType = void 0;
  32. var NativeAdComponent_1 = require("./NativeAdComponent");
  33. var SDK_1 = require("../SDK");
  34. var Utils_1 = require("../tools/Utils");
  35. var VivoAd_1 = require("./VivoAd");
  36. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  37. var InterstitialType;
  38. (function (InterstitialType) {
  39. InterstitialType[InterstitialType["INTERSTITIAL_GAME_OVER"] = 0] = "INTERSTITIAL_GAME_OVER";
  40. InterstitialType[InterstitialType["INTERSTITIAL_GAME_STARE"] = 1] = "INTERSTITIAL_GAME_STARE";
  41. InterstitialType[InterstitialType["INTERSTITIAL_GAME_PAUSE"] = 2] = "INTERSTITIAL_GAME_PAUSE"; //游戏暂停
  42. })(InterstitialType = exports.InterstitialType || (exports.InterstitialType = {}));
  43. var Interstitial = /** @class */ (function (_super) {
  44. __extends(Interstitial, _super);
  45. function Interstitial() {
  46. var _this = _super !== null && _super.apply(this, arguments) || this;
  47. _this._insetList = [];
  48. return _this;
  49. }
  50. Interstitial.prototype.init = function (config) {
  51. this._config = config;
  52. Utils_1.default.instance.log('创建Interstitial广告');
  53. };
  54. Interstitial.prototype.showBanner = function (banner) {
  55. // "banner":{"type":0, "x":0,"y":0,"top":false }
  56. if (banner) { //存在插屏节点banner数据
  57. if (banner.enable != 1) {
  58. return;
  59. }
  60. var type = banner.type; //显示banner类型
  61. var bannerType = NativeAdComponent_1.NativeType.BANNER; //正常banner
  62. if (type == 1) { //大banner
  63. bannerType = NativeAdComponent_1.NativeType.BANNER_BUTTON;
  64. }
  65. else if (type == 2) { //小banner带详情按键
  66. bannerType = NativeAdComponent_1.NativeType.BANNER_LITTLE_BUTTON;
  67. }
  68. VivoAd_1.default.Instance.getBanner().showBanner(bannerType, banner.top, banner.x, banner.y);
  69. }
  70. };
  71. /**
  72. * 展示原生插屏
  73. * 默认id节点为第一个0,有多个时,按服务端配置为准,进行传参
  74. * @param id 默认0
  75. * @param isforever true时,每次调用都会展示,false时,受服务器调用次数控制,默认false
  76. */
  77. Interstitial.prototype.showInterstitial = function (type) {
  78. if (type === void 0) { type = InterstitialType.INTERSTITIAL_GAME_OVER; }
  79. var self = this;
  80. //显示banner
  81. //广告数据是否存在
  82. if (this._config == null) {
  83. return;
  84. }
  85. var adNodeList = JSON.parse(this._config.insertAdNodeList);
  86. if (this._config.masterEnable != 1) { //所有广告是否打开
  87. return;
  88. }
  89. if (adNodeList == null || adNodeList.length <= 0) {
  90. Utils_1.default.instance.log("---------showInterstitial 未配置广告节点adNodeList为空");
  91. return;
  92. }
  93. //当前节点是否打开
  94. var adNode = adNodeList[type];
  95. if (adNode == null) {
  96. Utils_1.default.instance.log("---------showInterstitial 节点未配置广告nodeId:" + type);
  97. // isforever = false;
  98. return;
  99. }
  100. //插屏关闭,banner正常展示
  101. if (this._config.insertAdEnable != 1) { //插屏是否打开
  102. this.showBanner(adNode.banner);
  103. return;
  104. }
  105. //插屏节点关闭,banner正常展示
  106. if (adNode && adNode.enable != 1) {
  107. // isforever = false;
  108. this.showBanner(adNode.banner);
  109. return;
  110. }
  111. var nativeDate = VivoAd_1.default.Instance.getVivoNativeData();
  112. if (nativeDate == null || !nativeDate.isReady()) {
  113. Utils_1.default.instance.log("---------showInterstitial 广告数据不存在-----");
  114. this.showBanner(adNode.banner);
  115. return;
  116. }
  117. var node = cc.director.getScene().children[0];
  118. var insertAd = node.getChildByName("insertAd");
  119. if (insertAd) {
  120. insertAd.removeFromParent();
  121. // return ;
  122. }
  123. var go = function () {
  124. self.show(node, nativeDate, adNode);
  125. };
  126. this.delayShow(go);
  127. };
  128. Interstitial.prototype.show = function (node, nativeDate, adDate) {
  129. var _this = this;
  130. var self = this;
  131. var clickCallBack = function () {
  132. VivoAd_1.default.Instance.creatorNativeData();
  133. SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_CLICK, "原生插屏点击");
  134. };
  135. var showCallBack = function () {
  136. //缓存下一条广告
  137. VivoAd_1.default.Instance.hideBanner();
  138. VivoAd_1.default.Instance.creatorNativeData();
  139. SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_SHOW, "原生插屏展示");
  140. };
  141. var closeCallBack = function () {
  142. if (adDate) { //关闭插屏后,展示插屏节点内banner
  143. if (adDate.show_banner && adDate.show_banner > 0) {
  144. // self.showNativeBanner(self.bannerTop, self.bannerType, self.banner_y, self.banner_x);
  145. _this.showBanner(adDate.banner);
  146. }
  147. }
  148. //清理所有展示插屏
  149. self.cleanInset();
  150. SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_CLOSE, "原生插屏关闭");
  151. };
  152. Utils_1.default.instance.loadPrefabs("sdk/res/prefabs/NativeInsertAd", function (prefabs) {
  153. var adNode = cc.instantiate(prefabs);
  154. var nativeAd = adNode.addComponent(NativeAdComponent_1.default);
  155. nativeAd.initData(nativeDate);
  156. nativeAd.listionCall(showCallBack, clickCallBack, closeCallBack);
  157. // adNode.active = false;
  158. nativeAd.showAd(NativeAdComponent_1.NativeType.INSET, self._config);
  159. node.addChild(adNode, 1000, "insert"); //加节点名,防止重复加广告
  160. self.cacheInset(adNode);
  161. });
  162. };
  163. Interstitial.prototype.cleanInset = function () {
  164. if (this._insetList && this._insetList.length > 0) {
  165. this._insetList.forEach(function (node) {
  166. if (node) {
  167. node.removeFromParent();
  168. node.destroy();
  169. }
  170. });
  171. this._insetList = [];
  172. }
  173. };
  174. Interstitial.prototype.cacheInset = function (adNode) {
  175. this.cleanInset();
  176. if (this._insetList) {
  177. this._insetList.push(adNode);
  178. }
  179. };
  180. Interstitial.prototype.delayShow = function (go) {
  181. var self = this;
  182. //插屏延时展示
  183. if (self._config) {
  184. var dayTime = self._config.insertAdMaxDayTimes;
  185. Utils_1.default.instance.log("-------delayTime: " + dayTime);
  186. var mistakeRate = this._config.insertAdDayTimesMistakeRate;
  187. var random = Utils_1.default.instance.getRandomInt(1, 100);
  188. Utils_1.default.instance.log("-------delayTime random: " + random + " limitClick: " + SDK_1.default.Instance.limitClick);
  189. if (SDK_1.default.Instance.limitClick >= this._config.maxClickCount || mistakeRate < random) {
  190. dayTime = 0;
  191. }
  192. Utils_1.default.instance.log("-------delayTime: " + dayTime);
  193. self.scheduleOnce(function () {
  194. go();
  195. }, dayTime);
  196. }
  197. };
  198. Interstitial = __decorate([
  199. ccclass
  200. ], Interstitial);
  201. return Interstitial;
  202. }(cc.Component));
  203. exports.default = Interstitial;
  204. cc._RF.pop();