"use strict"; cc._RF.push(module, '04012iuvzpIxqz3qRDIGJ5b', 'Interstitial'); // Script/sdk/vivo/Interstitial.ts "use strict"; // Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.InterstitialType = void 0; var NativeAdComponent_1 = require("./NativeAdComponent"); var SDK_1 = require("../SDK"); var Utils_1 = require("../tools/Utils"); var VivoAd_1 = require("./VivoAd"); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; var InterstitialType; (function (InterstitialType) { InterstitialType[InterstitialType["INTERSTITIAL_GAME_OVER"] = 0] = "INTERSTITIAL_GAME_OVER"; InterstitialType[InterstitialType["INTERSTITIAL_GAME_STARE"] = 1] = "INTERSTITIAL_GAME_STARE"; InterstitialType[InterstitialType["INTERSTITIAL_GAME_PAUSE"] = 2] = "INTERSTITIAL_GAME_PAUSE"; //游戏暂停 })(InterstitialType = exports.InterstitialType || (exports.InterstitialType = {})); var Interstitial = /** @class */ (function (_super) { __extends(Interstitial, _super); function Interstitial() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._insetList = []; return _this; } Interstitial.prototype.init = function (config) { this._config = config; Utils_1.default.instance.log('创建Interstitial广告'); }; Interstitial.prototype.showBanner = function (banner) { // "banner":{"type":0, "x":0,"y":0,"top":false } if (banner) { //存在插屏节点banner数据 if (banner.enable != 1) { return; } var type = banner.type; //显示banner类型 var bannerType = NativeAdComponent_1.NativeType.BANNER; //正常banner if (type == 1) { //大banner bannerType = NativeAdComponent_1.NativeType.BANNER_BUTTON; } else if (type == 2) { //小banner带详情按键 bannerType = NativeAdComponent_1.NativeType.BANNER_LITTLE_BUTTON; } VivoAd_1.default.Instance.getBanner().showBanner(bannerType, banner.top, banner.x, banner.y); } }; /** * 展示原生插屏 * 默认id节点为第一个0,有多个时,按服务端配置为准,进行传参 * @param id 默认0 * @param isforever true时,每次调用都会展示,false时,受服务器调用次数控制,默认false */ Interstitial.prototype.showInterstitial = function (type) { if (type === void 0) { type = InterstitialType.INTERSTITIAL_GAME_OVER; } var self = this; //显示banner //广告数据是否存在 if (this._config == null) { return; } var adNodeList = JSON.parse(this._config.insertAdNodeList); if (this._config.masterEnable != 1) { //所有广告是否打开 return; } if (adNodeList == null || adNodeList.length <= 0) { Utils_1.default.instance.log("---------showInterstitial 未配置广告节点adNodeList为空"); return; } //当前节点是否打开 var adNode = adNodeList[type]; if (adNode == null) { Utils_1.default.instance.log("---------showInterstitial 节点未配置广告nodeId:" + type); // isforever = false; return; } //插屏关闭,banner正常展示 if (this._config.insertAdEnable != 1) { //插屏是否打开 this.showBanner(adNode.banner); return; } //插屏节点关闭,banner正常展示 if (adNode && adNode.enable != 1) { // isforever = false; this.showBanner(adNode.banner); return; } var nativeDate = VivoAd_1.default.Instance.getVivoNativeData(); if (nativeDate == null || !nativeDate.isReady()) { Utils_1.default.instance.log("---------showInterstitial 广告数据不存在-----"); this.showBanner(adNode.banner); return; } var node = cc.director.getScene().children[0]; var insertAd = node.getChildByName("insertAd"); if (insertAd) { insertAd.removeFromParent(); // return ; } var go = function () { self.show(node, nativeDate, adNode); }; this.delayShow(go); }; Interstitial.prototype.show = function (node, nativeDate, adDate) { var _this = this; var self = this; var clickCallBack = function () { VivoAd_1.default.Instance.creatorNativeData(); SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_CLICK, "原生插屏点击"); }; var showCallBack = function () { //缓存下一条广告 VivoAd_1.default.Instance.hideBanner(); VivoAd_1.default.Instance.creatorNativeData(); SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_SHOW, "原生插屏展示"); }; var closeCallBack = function () { if (adDate) { //关闭插屏后,展示插屏节点内banner if (adDate.show_banner && adDate.show_banner > 0) { // self.showNativeBanner(self.bannerTop, self.bannerType, self.banner_y, self.banner_x); _this.showBanner(adDate.banner); } } //清理所有展示插屏 self.cleanInset(); SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_CLOSE, "原生插屏关闭"); }; Utils_1.default.instance.loadPrefabs("sdk/res/prefabs/NativeInsertAd", function (prefabs) { var adNode = cc.instantiate(prefabs); var nativeAd = adNode.addComponent(NativeAdComponent_1.default); nativeAd.initData(nativeDate); nativeAd.listionCall(showCallBack, clickCallBack, closeCallBack); // adNode.active = false; nativeAd.showAd(NativeAdComponent_1.NativeType.INSET, self._config); node.addChild(adNode, 1000, "insert"); //加节点名,防止重复加广告 self.cacheInset(adNode); }); }; Interstitial.prototype.cleanInset = function () { if (this._insetList && this._insetList.length > 0) { this._insetList.forEach(function (node) { if (node) { node.removeFromParent(); node.destroy(); } }); this._insetList = []; } }; Interstitial.prototype.cacheInset = function (adNode) { this.cleanInset(); if (this._insetList) { this._insetList.push(adNode); } }; Interstitial.prototype.delayShow = function (go) { var self = this; //插屏延时展示 if (self._config) { var dayTime = self._config.insertAdMaxDayTimes; Utils_1.default.instance.log("-------delayTime: " + dayTime); var mistakeRate = this._config.insertAdDayTimesMistakeRate; var random = Utils_1.default.instance.getRandomInt(1, 100); Utils_1.default.instance.log("-------delayTime random: " + random + " limitClick: " + SDK_1.default.Instance.limitClick); if (SDK_1.default.Instance.limitClick >= this._config.maxClickCount || mistakeRate < random) { dayTime = 0; } Utils_1.default.instance.log("-------delayTime: " + dayTime); self.scheduleOnce(function () { go(); }, dayTime); } }; Interstitial = __decorate([ ccclass ], Interstitial); return Interstitial; }(cc.Component)); exports.default = Interstitial; cc._RF.pop();