123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- "use strict";
- cc._RF.push(module, 'eddc6/3kmxPsLDszQIo/ToH', 'Banner');
- // Script/sdk/vivo/Banner.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 });
- var SDK_1 = require("../SDK");
- var Utils_1 = require("../tools/Utils");
- var VivoAd_1 = require("./VivoAd");
- var NativeAdComponent_1 = require("./NativeAdComponent");
- var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
- var Banner = /** @class */ (function (_super) {
- __extends(Banner, _super);
- function Banner() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this._bannerTemplate = null; //模板banner
- _this._bannerList = [];
- return _this;
- }
- //初始化
- Banner.prototype.init = function (config) {
- this._config = config;
- this._isBanner = config.bannerAdEnable > 0;
- this._bannerCode = config.bannerAdCode;
- Utils_1.default.instance.log('创建banner广告');
- this.initBannerTemplate();
- };
- //初始化模板banner
- Banner.prototype.initBannerTemplate = function () {
- var self = this;
- var info = qg.getSystemInfoSync();
- Utils_1.default.instance.log(info);
- var targetBannerAdWidth = info.screenWidth > info.screenHeight ? (info.screenWidth <= 720 ? info.screenWidth / 2 : info.screenWidth / 2 - 30) : info.screenWidth;
- Utils_1.default.instance.log("bannertargetBannerAdWidth : " + targetBannerAdWidth);
- this._bannerTemplate = qg.createBannerAd({
- posId: self._bannerCode,
- style: {
- top: info.screenHeight - 170,
- left: (info.screenWidth - targetBannerAdWidth) / 2,
- }
- });
- this._bannerTemplate.onSize(function (size) {
- Utils_1.default.instance.log('banner 宽度:' + size.width + ', banner 高度:' + size.height);
- });
- this._bannerTemplate.onLoad(function () {
- Utils_1.default.instance.log('banner 广告加载成功');
- });
- this._bannerTemplate.onError(function (err) {
- Utils_1.default.instance.log("banner 广告加载错误:" + JSON.stringify(err));
- });
- };
- //展示模板banner
- Banner.prototype.showBannerTemplate = function () {
- if (this._isBanner) {
- if (this._bannerTemplate) {
- this._bannerTemplate.show();
- }
- else {
- this.initBannerTemplate();
- }
- }
- };
- //隐藏模板banner
- Banner.prototype.hideBannerTemplate = function () {
- if (this._bannerTemplate) {
- this._bannerTemplate.hide();
- }
- };
- /**
- * 展示原生banner
- * @param type 默认原生普通banner
- */
- Banner.prototype.showBanner = function (type, top, y, x) {
- if (type === void 0) { type = NativeAdComponent_1.NativeType.BANNER; }
- if (top === void 0) { top = false; }
- if (y === void 0) { y = 0; }
- if (x === void 0) { x = 0; }
- this._bannerType = type;
- Utils_1.default.instance.log("***********showNativeBanner type :" + type);
- if (type == NativeAdComponent_1.NativeType.BANNER_NO_NATIVE) {
- this.showBannerTemplate();
- return;
- }
- // this.showToast("banner显示了");
- var self = this;
- if (this._config == null) {
- return;
- }
- if (this._config.masterEnable != 1) { //插屏是否打开
- return;
- }
- if (this._config.bannerAdEnable != 1) {
- return;
- }
- var nativeData = VivoAd_1.default.Instance.getVivoNativeData();
- if (nativeData == null || !nativeData.isReady()) {
- Utils_1.default.instance.log("************showNativeBanner 广告数据不存在");
- return;
- }
- var clickCallBack = function () {
- VivoAd_1.default.Instance.creatorNativeData();
- SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_CLICK, "原生Banner点击");
- };
- var showCallBack = function () {
- VivoAd_1.default.Instance.creatorNativeData();
- //缓存下一条广告
- SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_SHOW, "原生Banner展示");
- };
- var closeCallBack = function () {
- // this.getVivoNativeData();
- self.cleanBanner();
- SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_CLOSE, "原生Banner关闭");
- };
- var node = cc.director.getScene().children[0];
- var banner = node.getChildByName("banner");
- if (banner) {
- banner.removeFromParent();
- banner.destroy();
- }
- var winSize = cc.view.getVisibleSize();
- if (y == 0) {
- if (top) {
- y = winSize.height / 2 - 150 / 2;
- }
- else {
- y = -winSize.height / 2 + 150 / 2;
- }
- }
- Utils_1.default.instance.log("-------bannerType: " + this._bannerType);
- var prefabsRes = "sdk/res/prefabs/NativeBannerAd";
- if (type == NativeAdComponent_1.NativeType.BANNER_BUTTON) {
- prefabsRes = "sdk/res/prefabs/NativeBannerAddButtonAd";
- if (top) {
- y = winSize.height / 2 - 400 / 2;
- }
- else {
- y = -winSize.height / 2 + 400 / 2;
- }
- }
- else if (type == NativeAdComponent_1.NativeType.BANNER_LITTLE_BUTTON) {
- if (top) {
- y = winSize.height / 2 - 150 / 2;
- }
- else {
- y = -winSize.height / 2 + 150 / 2;
- }
- prefabsRes = "sdk/res/prefabs/NativeBannerLittleBUttonAd";
- }
- Utils_1.default.instance.loadPrefabs(prefabsRes, function (prefabs) {
- var adNode = cc.instantiate(prefabs);
- self._nativeBanner = adNode.addComponent(NativeAdComponent_1.default);
- self._nativeBanner.initData(nativeData);
- self._nativeBanner.listionCall(showCallBack, clickCallBack, closeCallBack);
- adNode.width = winSize.width;
- self._nativeBanner.showAd(type, self._config, x, y);
- node.addChild(adNode, 1000, "banner");
- self.cacheBanner(adNode);
- });
- };
- Banner.prototype.cacheBanner = function (node) {
- var self = this;
- self.cleanBanner();
- if (self._bannerList) {
- self._bannerList.push(node);
- }
- };
- Banner.prototype.cleanBanner = function () {
- if (this._bannerList) {
- if (this._bannerList.length > 0) {
- this._bannerList.forEach(function (node) {
- node.removeFromParent();
- node.destroy();
- });
- this._bannerList = [];
- }
- }
- };
- /**
- * 隐藏b原生banner
- */
- Banner.prototype.hideBanner = function (hide) {
- if (hide === void 0) { hide = true; }
- Utils_1.default.instance.log("------hideNativeBanner: " + hide);
- if (hide) {
- this._bannerType = null;
- }
- if (this._bannerType == NativeAdComponent_1.NativeType.BANNER_NO_NATIVE) {
- this.hideBannerTemplate();
- return;
- }
- if (this._nativeBanner) {
- this._nativeBanner.hide(true);
- this._nativeBanner = null;
- }
- };
- Banner = __decorate([
- ccclass
- ], Banner);
- return Banner;
- }(cc.Component));
- exports.default = Banner;
- cc._RF.pop();
|