eddc6ff7-926c-4fb0-b0ec-cd0228fd3a07.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. "use strict";
  2. cc._RF.push(module, 'eddc6/3kmxPsLDszQIo/ToH', 'Banner');
  3. // Script/sdk/vivo/Banner.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. var SDK_1 = require("../SDK");
  32. var Utils_1 = require("../tools/Utils");
  33. var VivoAd_1 = require("./VivoAd");
  34. var NativeAdComponent_1 = require("./NativeAdComponent");
  35. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  36. var Banner = /** @class */ (function (_super) {
  37. __extends(Banner, _super);
  38. function Banner() {
  39. var _this = _super !== null && _super.apply(this, arguments) || this;
  40. _this._bannerTemplate = null; //模板banner
  41. _this._bannerList = [];
  42. return _this;
  43. }
  44. //初始化
  45. Banner.prototype.init = function (config) {
  46. this._config = config;
  47. this._isBanner = config.bannerAdEnable > 0;
  48. this._bannerCode = config.bannerAdCode;
  49. Utils_1.default.instance.log('创建banner广告');
  50. this.initBannerTemplate();
  51. };
  52. //初始化模板banner
  53. Banner.prototype.initBannerTemplate = function () {
  54. var self = this;
  55. var info = qg.getSystemInfoSync();
  56. Utils_1.default.instance.log(info);
  57. var targetBannerAdWidth = info.screenWidth > info.screenHeight ? (info.screenWidth <= 720 ? info.screenWidth / 2 : info.screenWidth / 2 - 30) : info.screenWidth;
  58. Utils_1.default.instance.log("bannertargetBannerAdWidth : " + targetBannerAdWidth);
  59. this._bannerTemplate = qg.createBannerAd({
  60. posId: self._bannerCode,
  61. style: {
  62. top: info.screenHeight - 170,
  63. left: (info.screenWidth - targetBannerAdWidth) / 2,
  64. }
  65. });
  66. this._bannerTemplate.onSize(function (size) {
  67. Utils_1.default.instance.log('banner 宽度:' + size.width + ', banner 高度:' + size.height);
  68. });
  69. this._bannerTemplate.onLoad(function () {
  70. Utils_1.default.instance.log('banner 广告加载成功');
  71. });
  72. this._bannerTemplate.onError(function (err) {
  73. Utils_1.default.instance.log("banner 广告加载错误:" + JSON.stringify(err));
  74. });
  75. };
  76. //展示模板banner
  77. Banner.prototype.showBannerTemplate = function () {
  78. if (this._isBanner) {
  79. if (this._bannerTemplate) {
  80. this._bannerTemplate.show();
  81. }
  82. else {
  83. this.initBannerTemplate();
  84. }
  85. }
  86. };
  87. //隐藏模板banner
  88. Banner.prototype.hideBannerTemplate = function () {
  89. if (this._bannerTemplate) {
  90. this._bannerTemplate.hide();
  91. }
  92. };
  93. /**
  94. * 展示原生banner
  95. * @param type 默认原生普通banner
  96. */
  97. Banner.prototype.showBanner = function (type, top, y, x) {
  98. if (type === void 0) { type = NativeAdComponent_1.NativeType.BANNER; }
  99. if (top === void 0) { top = false; }
  100. if (y === void 0) { y = 0; }
  101. if (x === void 0) { x = 0; }
  102. this._bannerType = type;
  103. Utils_1.default.instance.log("***********showNativeBanner type :" + type);
  104. if (type == NativeAdComponent_1.NativeType.BANNER_NO_NATIVE) {
  105. this.showBannerTemplate();
  106. return;
  107. }
  108. // this.showToast("banner显示了");
  109. var self = this;
  110. if (this._config == null) {
  111. return;
  112. }
  113. if (this._config.masterEnable != 1) { //插屏是否打开
  114. return;
  115. }
  116. if (this._config.bannerAdEnable != 1) {
  117. return;
  118. }
  119. var nativeData = VivoAd_1.default.Instance.getVivoNativeData();
  120. if (nativeData == null || !nativeData.isReady()) {
  121. Utils_1.default.instance.log("************showNativeBanner 广告数据不存在");
  122. return;
  123. }
  124. var clickCallBack = function () {
  125. VivoAd_1.default.Instance.creatorNativeData();
  126. SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_CLICK, "原生Banner点击");
  127. };
  128. var showCallBack = function () {
  129. VivoAd_1.default.Instance.creatorNativeData();
  130. //缓存下一条广告
  131. SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_SHOW, "原生Banner展示");
  132. };
  133. var closeCallBack = function () {
  134. // this.getVivoNativeData();
  135. self.cleanBanner();
  136. SDK_1.default.Instance.reportLog(SDK_1.NodeAction.NATIVE_CLOSE, "原生Banner关闭");
  137. };
  138. var node = cc.director.getScene().children[0];
  139. var banner = node.getChildByName("banner");
  140. if (banner) {
  141. banner.removeFromParent();
  142. banner.destroy();
  143. }
  144. var winSize = cc.view.getVisibleSize();
  145. if (y == 0) {
  146. if (top) {
  147. y = winSize.height / 2 - 150 / 2;
  148. }
  149. else {
  150. y = -winSize.height / 2 + 150 / 2;
  151. }
  152. }
  153. Utils_1.default.instance.log("-------bannerType: " + this._bannerType);
  154. var prefabsRes = "sdk/res/prefabs/NativeBannerAd";
  155. if (type == NativeAdComponent_1.NativeType.BANNER_BUTTON) {
  156. prefabsRes = "sdk/res/prefabs/NativeBannerAddButtonAd";
  157. if (top) {
  158. y = winSize.height / 2 - 400 / 2;
  159. }
  160. else {
  161. y = -winSize.height / 2 + 400 / 2;
  162. }
  163. }
  164. else if (type == NativeAdComponent_1.NativeType.BANNER_LITTLE_BUTTON) {
  165. if (top) {
  166. y = winSize.height / 2 - 150 / 2;
  167. }
  168. else {
  169. y = -winSize.height / 2 + 150 / 2;
  170. }
  171. prefabsRes = "sdk/res/prefabs/NativeBannerLittleBUttonAd";
  172. }
  173. Utils_1.default.instance.loadPrefabs(prefabsRes, function (prefabs) {
  174. var adNode = cc.instantiate(prefabs);
  175. self._nativeBanner = adNode.addComponent(NativeAdComponent_1.default);
  176. self._nativeBanner.initData(nativeData);
  177. self._nativeBanner.listionCall(showCallBack, clickCallBack, closeCallBack);
  178. adNode.width = winSize.width;
  179. self._nativeBanner.showAd(type, self._config, x, y);
  180. node.addChild(adNode, 1000, "banner");
  181. self.cacheBanner(adNode);
  182. });
  183. };
  184. Banner.prototype.cacheBanner = function (node) {
  185. var self = this;
  186. self.cleanBanner();
  187. if (self._bannerList) {
  188. self._bannerList.push(node);
  189. }
  190. };
  191. Banner.prototype.cleanBanner = function () {
  192. if (this._bannerList) {
  193. if (this._bannerList.length > 0) {
  194. this._bannerList.forEach(function (node) {
  195. node.removeFromParent();
  196. node.destroy();
  197. });
  198. this._bannerList = [];
  199. }
  200. }
  201. };
  202. /**
  203. * 隐藏b原生banner
  204. */
  205. Banner.prototype.hideBanner = function (hide) {
  206. if (hide === void 0) { hide = true; }
  207. Utils_1.default.instance.log("------hideNativeBanner: " + hide);
  208. if (hide) {
  209. this._bannerType = null;
  210. }
  211. if (this._bannerType == NativeAdComponent_1.NativeType.BANNER_NO_NATIVE) {
  212. this.hideBannerTemplate();
  213. return;
  214. }
  215. if (this._nativeBanner) {
  216. this._nativeBanner.hide(true);
  217. this._nativeBanner = null;
  218. }
  219. };
  220. Banner = __decorate([
  221. ccclass
  222. ], Banner);
  223. return Banner;
  224. }(cc.Component));
  225. exports.default = Banner;
  226. cc._RF.pop();