5acc1ec1-80be-4111-9100-0bcaea56392c.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. "use strict";
  2. cc._RF.push(module, '5acc17BgL5BEZEAC8rqVjks', 'NavtiveData');
  3. // Script/sdk/vivo/NavtiveData.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 Utils_1 = require("../tools/Utils");
  32. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  33. var NavtiveData = /** @class */ (function (_super) {
  34. __extends(NavtiveData, _super);
  35. function NavtiveData() {
  36. var _this = _super.call(this) || this;
  37. _this._nativeCurrentAd = null;
  38. _this._nativeAd = null;
  39. _this._ready = false;
  40. _this.enterGmae = false;
  41. _this._utils = Utils_1.default.instance;
  42. return _this;
  43. }
  44. NavtiveData.prototype.start = function () {
  45. };
  46. /**
  47. * 创建广告
  48. */
  49. NavtiveData.prototype.initAd = function (config, callbacks) {
  50. this._utils.log("------创建native广告-----");
  51. var posId = config.insertAdCode;
  52. this._nativeAd = qg.createNativeAd({
  53. posId: posId,
  54. });
  55. this.enterGmae = false;
  56. var self = this;
  57. if (this._nativeAd) {
  58. this._nativeAd.load();
  59. this._utils.log("------创建native广告-this.nativeAd.load(): " + this._nativeAd);
  60. this._nativeAd.onLoad(function (res) {
  61. self.enterGmae = true;
  62. self._utils.log('原生广告加载完成-onload触发 ' + JSON.stringify(res));
  63. if (res && res.adList) {
  64. self._nativeCurrentAd = res.adList.pop();
  65. self._ready = true;
  66. if (callbacks) {
  67. callbacks(true);
  68. }
  69. }
  70. });
  71. this._nativeAd.onError(function (err) {
  72. self._utils.log("原生广告加载异常" + JSON.stringify(err));
  73. self.enterGmae = true;
  74. if (err) {
  75. if (err.errCode == 30009) {
  76. if (callbacks) {
  77. callbacks(false);
  78. }
  79. }
  80. else {
  81. if (callbacks) {
  82. callbacks(false);
  83. }
  84. }
  85. }
  86. });
  87. }
  88. else {
  89. self.enterGmae = true;
  90. if (callbacks) {
  91. callbacks(false);
  92. }
  93. }
  94. //5秒没反应,直接进入游戏
  95. this.scheduleOnce(function () {
  96. if (self.enterGmae) {
  97. return;
  98. }
  99. if (callbacks) {
  100. callbacks(false);
  101. }
  102. }, 5);
  103. };
  104. /**
  105. * 广告展示上报
  106. */
  107. NavtiveData.prototype.reportAdShow = function () {
  108. if (this._nativeAd && this._nativeCurrentAd) {
  109. this._nativeAd.reportAdShow({ adId: this._nativeCurrentAd.adId.toString() });
  110. }
  111. };
  112. /**
  113. * 广告点击上报
  114. */
  115. NavtiveData.prototype.reportAdClick = function () {
  116. if (this._nativeAd && this._nativeCurrentAd) {
  117. this._nativeAd.reportAdClick({ adId: this._nativeCurrentAd.adId.toString() });
  118. }
  119. };
  120. /**
  121. * 获取广告数据
  122. * @returns
  123. */
  124. NavtiveData.prototype.getNativeDate = function () {
  125. return this._nativeCurrentAd;
  126. };
  127. NavtiveData.prototype.isReady = function () {
  128. return this._ready;
  129. };
  130. NavtiveData = __decorate([
  131. ccclass
  132. ], NavtiveData);
  133. return NavtiveData;
  134. }(cc.Component));
  135. exports.default = NavtiveData;
  136. cc._RF.pop();