5598002c-6620-460a-8a1a-62f09538c541.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. "use strict";
  2. cc._RF.push(module, '55980AsZiBGCooaYvCVOMVB', 'AdAgentUC');
  3. // common-plugin/Scripts/AdAgentUC.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. 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;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var AdAgent_1 = require("./AdAgent");
  26. var PlatUtils_1 = require("./PlatUtils");
  27. var Utils_1 = require("./Utils");
  28. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  29. /**
  30. * uc广告组件
  31. */
  32. var AdAgentUC = /** @class */ (function (_super) {
  33. __extends(AdAgentUC, _super);
  34. function AdAgentUC() {
  35. var _this = _super !== null && _super.apply(this, arguments) || this;
  36. _this._videoCallback = null;
  37. _this._isVideoLoaded = false;
  38. _this._videoAd = null;
  39. _this._bannerAd = null;
  40. //@ts-ignore
  41. _this.uc = window.uc;
  42. _this._sysInfo = {};
  43. return _this;
  44. }
  45. AdAgentUC.prototype.Init = function () {
  46. Utils_1.utils.showLog("UC 广告初始化");
  47. this.initVideo();
  48. if (!this._sysInfo) {
  49. this._sysInfo = this.uc.getSystemInfoSync();
  50. if (typeof this._sysInfo === 'string') {
  51. try {
  52. this._sysInfo = JSON.parse(this._sysInfo);
  53. }
  54. catch (e) { }
  55. }
  56. }
  57. };
  58. AdAgentUC.prototype.ShowBanner = function () {
  59. if (this._bannerAd) {
  60. this._bannerAd.destroy();
  61. this._bannerAd = null;
  62. }
  63. // 0:左上 1:顶部居中 2:右上
  64. // 3:左边垂直居中 4:居中 5:右边垂直居中
  65. // 6:左下 7:底部居中 8:右下 (默认为0)
  66. Utils_1.utils.showLog("uc banner width>>", this._sysInfo.screenWidth, " #height>>", this._sysInfo.screenWidth * 194 / 345);
  67. this._bannerAd = this.uc.createBannerAd({
  68. style: {
  69. gravity: 7,
  70. bottom: 0,
  71. width: cc.winSize.height < cc.winSize.width ? 250 : this._sysInfo.screenWidth,
  72. height: this._sysInfo.screenWidth / 4,
  73. }
  74. });
  75. if (this._bannerAd) {
  76. this._bannerAd.show();
  77. this._bannerAd.onError(function (err) {
  78. Utils_1.utils.showLog("UC平台banner出错" + err);
  79. });
  80. }
  81. };
  82. AdAgentUC.prototype.ShowInterstitial = function () {
  83. // if(this.)
  84. Utils_1.utils.showLog("展示插屏广告");
  85. var interstitialAd = this.uc.createInterstitialAd();
  86. interstitialAd.load()
  87. .then()
  88. .catch(function (err) { return Utils_1.utils.showLog("\u63D2\u5C4F\u52A0\u8F7D\u5F02\u5E38\uFF1A" + err); });
  89. interstitialAd.onLoad(function () {
  90. interstitialAd.offLoad(); // 取消 load 事件的监听,不传 callback 的话会取消所有的监听
  91. interstitialAd
  92. .show()
  93. .then()
  94. .catch(function (err) { return Utils_1.utils.showLog("\u63D2\u5C4F\u5C55\u793A\u5F02\u5E38\uFF1A" + err); });
  95. Utils_1.utils.showLog('UC插屏广告加载成功');
  96. });
  97. interstitialAd.onError(function (err) {
  98. Utils_1.utils.showLog(err);
  99. });
  100. };
  101. AdAgentUC.prototype.initVideo = function () {
  102. var _this = this;
  103. this._videoAd = this.uc.createRewardVideoAd();
  104. this._videoAd.onLoad(function () {
  105. Utils_1.utils.showLog('激励视频 广告加载成功');
  106. });
  107. this._videoAd.onError(function (err) {
  108. Utils_1.utils.showLog("出错了:" + err);
  109. if (_this._videoCallback) {
  110. _this._videoCallback(false, "暂无视频广告");
  111. _this._videoCallback = null;
  112. }
  113. });
  114. this._videoAd.onClose(function (res) {
  115. Utils_1.utils.showLog("用户关闭视频" + res);
  116. if (res && res.isEnded) {
  117. if (_this._videoCallback) {
  118. _this._videoCallback(true, "");
  119. _this._videoCallback = null;
  120. }
  121. }
  122. else {
  123. if (_this._videoCallback) {
  124. _this._videoCallback(false, "视频播放完毕才能够获取奖励!");
  125. _this._videoCallback = null;
  126. }
  127. }
  128. });
  129. };
  130. AdAgentUC.prototype.ShowVideo = function (callback) {
  131. if (PlatUtils_1.default.ISUC) {
  132. this._videoCallback = callback;
  133. if (!this._videoAd) {
  134. this.initVideo();
  135. }
  136. else {
  137. this._videoAd.show();
  138. }
  139. }
  140. };
  141. AdAgentUC = __decorate([
  142. ccclass
  143. ], AdAgentUC);
  144. return AdAgentUC;
  145. }(AdAgent_1.default));
  146. exports.default = AdAgentUC;
  147. cc._RF.pop();