123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- "use strict";
- cc._RF.push(module, 'd3ac8XKEnNI47JfbyPhFplQ', 'NativeAdComponent');
- // Script/sdk/vivo/NativeAdComponent.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.NativeType = void 0;
- 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 NativeType;
- (function (NativeType) {
- NativeType[NativeType["INSET"] = 0] = "INSET";
- NativeType[NativeType["BANNER"] = 1] = "BANNER";
- NativeType[NativeType["ICON"] = 2] = "ICON";
- NativeType[NativeType["SPLASH"] = 3] = "SPLASH";
- NativeType[NativeType["BANNER_BUTTON"] = 4] = "BANNER_BUTTON";
- NativeType[NativeType["BANNER_NO_NATIVE"] = 5] = "BANNER_NO_NATIVE";
- NativeType[NativeType["BANNER_LITTLE_BUTTON"] = 6] = "BANNER_LITTLE_BUTTON";
- NativeType[NativeType["ICON_GAME"] = 7] = "ICON_GAME";
- NativeType[NativeType["INSET_NO_NATIVE"] = 8] = "INSET_NO_NATIVE";
- })(NativeType = exports.NativeType || (exports.NativeType = {}));
- /**原生广告 */
- var NativeAdComponent = /** @class */ (function (_super) {
- __extends(NativeAdComponent, _super);
- function NativeAdComponent() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this.iconShow = false;
- _this._closeButton = null; //关闭按钮
- _this._content = null; //内容按钮
- _this._type = NativeType.INSET; //默认插屏
- _this._nativeCurrentAd = null; //广告内容
- _this._config = null; //广告配置
- _this._adCallBack = null; //banner和icon刷新回调
- _this._clickCallBack = null; //点击回调
- _this._showCallBack = null; //展示回调
- _this._closeCallBack = null; //关闭回调
- _this._title = null; //广告标题
- _this._info = null; //广告描述
- _this._isClick = false; //防止重复点击
- _this._splashCallBacks = null; //开屏回调
- _this._labelCall = null; //开屏倒时候任务
- _this._vivoNativeDate = null;
- return _this;
- }
- NativeAdComponent.prototype.start = function () {
- Utils_1.default.instance.log("-----------------iconShow: " + this.iconShow);
- if (this.iconShow) {
- var shareVivoNativeDate = VivoAd_1.default.Instance.getVivoNativeData();
- if (shareVivoNativeDate == null || !shareVivoNativeDate.isReady()) {
- this.node.active = false;
- return;
- }
- this.initData(shareVivoNativeDate);
- var clickCallBack = function () {
- VivoAd_1.default.Instance.creatorNativeData();
- SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_CLICK, "原生icon点击");
- };
- var showCallBack = function () {
- //缓存下一条广告
- SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_SHOW, "原生icon展示");
- };
- var closeCallBack = function () {
- SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_CLOSE, "原生icon关闭");
- };
- this.listionCall(showCallBack, clickCallBack, closeCallBack);
- this.showAd(NativeType.ICON_GAME, VivoAd_1.default.Instance.getConfig());
- this.node.active = true;
- }
- };
- NativeAdComponent.prototype.initButton = function () {
- var curContent = this.node.getChildByName("content");
- if (curContent) {
- this._content = curContent.getChildByName("contentAd").getComponent(cc.Sprite);
- var button = curContent.getChildByName("Button");
- if (button && button.active) {
- //广告详情按键默认关闭
- button.on(cc.Node.EventType.TOUCH_START, this.adClick, this);
- if (this._type == NativeType.BANNER_BUTTON || this._type == NativeType.BANNER_LITTLE_BUTTON) {
- button.active = false;
- if (this._config.insertAdNodeList) { //存在插屏列表
- var adNodeList = JSON.parse(this._config.insertAdNodeList);
- //黑夜首节点是否存在
- var adNode = adNodeList[0];
- if (adNode) {
- //广告详情是否打开
- if (adNode.bntDetails && adNode.bntDetails > 0) {
- button.active = true;
- }
- }
- }
- button.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.5, 1.1), cc.scaleTo(0.5, 1))));
- }
- }
- curContent.on(cc.Node.EventType.TOUCH_START, this.adClick, this);
- }
- };
- NativeAdComponent.prototype.onDisable = function () {
- if (this._adCallBack) {
- this.unschedule(this._adCallBack);
- }
- };
- NativeAdComponent.prototype.initData = function (vivoNativeDate) {
- this._vivoNativeDate = vivoNativeDate;
- };
- NativeAdComponent.prototype.init = function () {
- var _this = this;
- this.node.active = true;
- var self = this;
- // let nativeData = {
- // imgUrlList: "https://pic.cr173.com/up/2019-9/201991783518653750.jpg",
- // icon: "https://p.e5n.com/up/2019-9/2019917834498180.jpg",
- // title: "超强马丽",
- // desc: "这个游戏很不错",
- // clickBtnTxt: "立即查看"
- // }
- this._nativeCurrentAd = this._vivoNativeDate.getNativeDate();
- if (this._nativeCurrentAd == null) {
- console.log("------没有广告数据");
- VivoAd_1.default.Instance.creatorNativeData(function (success) {
- if (success) {
- _this._vivoNativeDate = VivoAd_1.default.Instance.getVivoNativeData();
- self.init();
- }
- });
- return;
- }
- var curContent = this.node.getChildByName("content");
- if (curContent) {
- var adId = curContent.getChildByName("adId");
- if (adId) {
- adId.active = false;
- adId.y = -50;
- adId.x = -10;
- adId.color = new cc.Color(255, 0, 0);
- var adIdLable = adId.getComponent(cc.Label);
- adIdLable.string = this._nativeCurrentAd.adId.toString();
- }
- if (this._type == NativeType.SPLASH) {
- var closeContinu = curContent.getChildByName("closeContinu");
- closeContinu.on(cc.Node.EventType.TOUCH_START, this.close, this);
- var label_1 = closeContinu.getChildByName("cLabel").getComponent(cc.Label);
- Utils_1.default.instance.log("----------splash label: " + label_1);
- if (label_1) {
- var count_1 = 3;
- self._labelCall = function () {
- count_1--;
- if (count_1 <= 0) {
- Utils_1.default.instance.log("----------开屏关闭: " + label_1);
- self.hide();
- }
- label_1.string = count_1 + "秒 跳过";
- Utils_1.default.instance.log("----------splash label: " + label_1.string);
- };
- self.schedule(self._labelCall, 3);
- }
- }
- }
- var url = this._nativeCurrentAd.imgUrlList[0];
- //加载插屏图片
- if (this._type != NativeType.ICON && this._type != NativeType.BANNER_BUTTON && this._type != NativeType.ICON_GAME) {
- if (curContent) {
- var title = curContent.getChildByName("title");
- if (title && title.active) {
- self._title = title.getComponent(cc.Label);
- self._title.string = self._nativeCurrentAd.title;
- }
- var info = curContent.getChildByName("info");
- if (info && info.active) {
- self._info = info.getComponent(cc.Label);
- self._info.string = self._nativeCurrentAd.desc;
- }
- url = this._nativeCurrentAd.icon;
- if (this._type != NativeType.BANNER && this._type != NativeType.BANNER_LITTLE_BUTTON) {
- var icon_ = curContent.getChildByName("icon");
- if (icon_ && icon_.active) {
- var icon_1 = icon_.getComponent(cc.Sprite);
- this.getImageSpriteFrame(url).then(function (frame) {
- icon_1.spriteFrame = frame;
- }).catch(function (err) {
- console.log(err);
- self.getImageSpriteFrame(url).then(function (frame) {
- icon_1.spriteFrame = frame;
- });
- });
- }
- }
- }
- }
- if (this._type == NativeType.ICON) {
- url = this._nativeCurrentAd.icon;
- }
- else {
- url = this._nativeCurrentAd.imgUrlList[0];
- }
- this.getImageSpriteFrame(url).then(function (frame) {
- self._content.spriteFrame = frame;
- }).catch(function (err) {
- console.log(err);
- url = _this._nativeCurrentAd.imgUrlList[0];
- self.getImageSpriteFrame(url).then(function (frame) {
- self._content.spriteFrame = frame;
- }).catch(function (err) {
- console.log(err);
- self.getImageSpriteFrame(url).then(function (frame) {
- self._content.spriteFrame = frame;
- });
- });
- });
- };
- /**广告状态监听 */
- NativeAdComponent.prototype.listionCall = function (showCallBack, clickCallBack, closeCallBack) {
- this._showCallBack = showCallBack;
- this._clickCallBack = clickCallBack;
- this._closeCallBack = closeCallBack;
- };
- NativeAdComponent.prototype.closeSize = function () {
- if (this._closeButton == null) {
- return;
- }
- if (this._config && this._closeButton) { //控制关闭按键大小
- var adNodeList = JSON.parse(this._config.insertAdNodeList);
- if (adNodeList) {
- var adNode = adNodeList[0];
- if (adNode) {
- var size = adNode.size;
- if (size) {
- if (size.enable) { //关闭按键大小开关
- var width = 20;
- var height = 20;
- if (size.width == null || size.width == 0) {
- width = 35;
- }
- else if (size.width < 20) {
- width = 20;
- }
- else {
- width = size.width;
- }
- if (size.height == null || size.height == 0) {
- height = 35;
- }
- else if (size.height < 20) {
- height = 20;
- }
- else {
- height = size.height;
- }
- this._closeButton.width = width;
- this._closeButton.height = height;
- }
- }
- }
- }
- }
- };
- /**展示广告
- * @param
- */
- NativeAdComponent.prototype.showAd = function (type, config, x, y, callBacks) {
- var _this = this;
- this._type = type;
- this._config = config;
- this.initButton();
- var curContent = this.node.getChildByName("content");
- if (curContent) {
- this._closeButton = curContent.getChildByName("close");
- this.closeSize();
- // this.content.node.on(cc.Node.EventType.TOUCH_START, this.adClick, this);
- this._closeButton.on(cc.Node.EventType.TOUCH_START, this.close, this);
- this.node.active = false;
- this._splashCallBacks = callBacks;
- this.show();
- var adFlushTime = this._config.iconAdFlush;
- var self_1 = this;
- if (type == NativeType.BANNER_BUTTON || this._type == NativeType.BANNER_LITTLE_BUTTON) {
- var bigBannerCloseEnable = this._config.bigBannerCloseEnable;
- if (bigBannerCloseEnable <= 0) {
- Utils_1.default.instance.log("-----------大banner----------");
- this._closeButton.active = false;
- }
- }
- //不是插屏时,要刷新广告
- if (type == NativeType.BANNER ||
- type == NativeType.ICON ||
- type == NativeType.BANNER_BUTTON ||
- type == NativeType.ICON_GAME ||
- type == NativeType.BANNER_LITTLE_BUTTON) {
- this.node.x = x;
- this.node.y = y;
- if (adFlushTime <= 0) {
- Utils_1.default.instance.log("-----------不刷新广告----------");
- return;
- }
- this._adCallBack = function () {
- Utils_1.default.instance.log("-----------广告刷新----------");
- var curContent = _this.node.getChildByName("content");
- if (curContent) {
- curContent.active = true;
- }
- self_1._vivoNativeDate = VivoAd_1.default.Instance.getVivoNativeData();
- self_1.show();
- };
- this.schedule(this._adCallBack, adFlushTime);
- }
- }
- };
- NativeAdComponent.prototype.show = function () {
- var self = this;
- this._isClick = false;
- // if(this.node.active == false){
- // this.node.active = true;
- // }
- if (self._vivoNativeDate) {
- self.init();
- self._vivoNativeDate.reportAdShow();
- if (this._showCallBack) {
- this._showCallBack();
- }
- }
- };
- NativeAdComponent.prototype.onDestroy = function () {
- Utils_1.default.instance.log("-------广告 destroy " + this._type);
- };
- /**
- * 隐藏广告
- */
- NativeAdComponent.prototype.hide = function (remove) {
- if (remove === void 0) { remove = true; }
- if (this.node) {
- if (remove) {
- this.unscheduleAllCallbacks();
- this.node.removeFromParent();
- }
- else {
- if (this._type != NativeType.ICON_GAME) {
- var curContent = this.node.getChildByName("content");
- if (curContent) {
- curContent.active = false;
- }
- }
- else {
- this.node.active = false;
- }
- }
- }
- if (this._closeCallBack) {
- this._closeCallBack();
- }
- if (this._type == NativeType.SPLASH) {
- if (this._splashCallBacks) {
- this._splashCallBacks();
- }
- this.unschedule(this._labelCall);
- }
- };
- //全屏点击
- NativeAdComponent.prototype.allSceen = function () {
- if (this._type == NativeType.INSET) {
- return;
- }
- this.adClick();
- //
- };
- //点击事件
- NativeAdComponent.prototype.adClick = function () {
- if (this._isClick) {
- return;
- }
- this._isClick = true;
- var self = this;
- if (self._vivoNativeDate) {
- self._vivoNativeDate.reportAdClick();
- if (this._clickCallBack) {
- this._clickCallBack();
- }
- }
- //如果是插屏或开屏,点击直接关闭
- if (this._type == NativeType.INSET || this._type == NativeType.SPLASH) {
- this.hide(true);
- }
- else { //banner和icon则刷新广告
- this._vivoNativeDate = VivoAd_1.default.Instance.getVivoNativeData();
- if (this._vivoNativeDate != null && this._vivoNativeDate.isReady()) {
- this.show();
- }
- else {
- this.hide(false);
- }
- }
- };
- /**
- *
- * @returns 关闭广告
- */
- NativeAdComponent.prototype.close = function () {
- var mistakeRate = this._config.insertAdMistakeRate;
- this._isClick = true;
- var random = Utils_1.default.instance.getRandomInt(1, 100);
- //误次数已用完,直接关闭
- if (SDK_1.default.Instance.limitClick >= this._config.maxClickCount) {
- console.log("=============数已用完,直接关闭");
- this.hide();
- return;
- }
- // mistakeRate = 0;
- //满足误点
- if (random < mistakeRate) { //关击按键是事能点击广告
- SDK_1.default.Instance.limitClick++;
- console.log("------------random: ", random < mistakeRate);
- console.log("。。。。。。原生广告close adClick。。。。。。");
- this.adClick();
- return;
- }
- if (this._type == NativeType.INSET || this._type == NativeType.SPLASH) {
- this.hide();
- }
- else {
- this.hide(false);
- }
- };
- /**
- * 获取内容图片
- * @returns
- */
- NativeAdComponent.prototype.getImageSpriteFrame = function (url) {
- var self = this;
- return new Promise(function (resolve, reject) {
- console.log("图片下载地址:", url);
- cc.loader.load(url, function (err, texture) {
- if (err) {
- console.log("图片下载失败", url, err);
- reject("图片下载失败: " + url);
- return;
- }
- var frame = new cc.SpriteFrame(texture);
- resolve(frame);
- });
- });
- };
- __decorate([
- property(cc.Boolean)
- ], NativeAdComponent.prototype, "iconShow", void 0);
- NativeAdComponent = __decorate([
- ccclass
- ], NativeAdComponent);
- return NativeAdComponent;
- }(cc.Component));
- exports.default = NativeAdComponent;
- cc._RF.pop();
|