4d6dac9c-7084-4c81-8f93-ddf2ae016987.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. "use strict";
  2. cc._RF.push(module, '4d6dayccIRMgY+T3fKuAWmH', 'YZ_NativeItem');
  3. // common-plugin/Scripts/YZ_NativeItem.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 PlatUtils_1 = require("./PlatUtils");
  26. var Utils_1 = require("./Utils");
  27. var YZ_Constant_1 = require("./YZ_Constant");
  28. var CompatibleTool_1 = require("./CompatibleTool");
  29. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  30. var YZ_NativeItem = /** @class */ (function (_super) {
  31. __extends(YZ_NativeItem, _super);
  32. function YZ_NativeItem() {
  33. var _this = _super !== null && _super.apply(this, arguments) || this;
  34. _this._nativeAdTiltle = null;
  35. _this._nativeAdIcon = null;
  36. _this._nativeAdDesc = null;
  37. _this._nativeAdImg = null;
  38. _this._closeBtn = null;
  39. _this._downBtn = null;
  40. _this._noImageView = null;
  41. _this._nativeAd = null;
  42. _this.isShow = false;
  43. _this.showType = 1;
  44. _this.params = null;
  45. _this.content = null;
  46. return _this;
  47. }
  48. YZ_NativeItem.prototype.onLoad = function () {
  49. var _this = this;
  50. this.content = this.node.children[0];
  51. this._noImageView = this.content.getChildByName("NoImageView");
  52. this._nativeAdTiltle = this._noImageView.getChildByName("title").getComponent(cc.Label);
  53. this._nativeAdIcon = this._noImageView.getChildByName("icon").getComponent(cc.Sprite);
  54. this._nativeAdDesc = this._noImageView.getChildByName("desc").getComponent(cc.Label);
  55. this._nativeAdImg = this.content.getChildByName("image").getComponent(cc.Sprite);
  56. // this._downBtn = this.content.getChildByName("Btn_Download");
  57. this._closeBtn = this.content.getChildByName("closeBtn");
  58. if (this.params) {
  59. if (this.params.parent) {
  60. this.node.width = this.node.parent.width;
  61. this.node.height = this.node.parent.height;
  62. }
  63. }
  64. else {
  65. if (Utils_1.utils.ServerConfig.st_native_ad_height) {
  66. this.node.height = Utils_1.utils.ServerConfig.st_native_ad_height;
  67. }
  68. }
  69. this.content.active = false;
  70. cc.game.on(YZ_Constant_1.default.YZ_NativeAdClick, function () {
  71. _this.reportAdClick();
  72. }, this);
  73. // this._closeBtn.active = utils.ServerConfig.st_banner_close_but_show ? (utils.ServerConfig.st_banner_close_but_show == "true") : false;
  74. // this._downBtn.active = utils.ServerConfig.show_statement_nativeAd_closeBtn ? (utils.ServerConfig.show_statement_nativeAd_closeBtn == "true") : false;
  75. };
  76. YZ_NativeItem.prototype.onDisable = function () {
  77. cc.game.targetOff(this);
  78. this.node.destroy();
  79. };
  80. YZ_NativeItem.prototype.update = function () {
  81. if (this._nativeAd && !this.isShow) {
  82. this.isShow = true;
  83. this.showNativeAd();
  84. }
  85. };
  86. YZ_NativeItem.prototype.init = function (nativeObj) {
  87. Utils_1.utils.showLog("初始化单个原生广告>>>");
  88. this._nativeAd = nativeObj;
  89. };
  90. YZ_NativeItem.prototype.showNativeAd = function () {
  91. var _this = this;
  92. if (Utils_1.utils.ServerConfig.st_native_ad_is_hide_banner && Utils_1.utils.ServerConfig.st_native_ad_is_hide_banner == "true") {
  93. Utils_1.utils.showLog("服务器配置显示结算原生广告后隐藏banner >>>");
  94. Utils_1.utils.adManager.HideBanner(YZ_Constant_1.BannerLocation.Game);
  95. }
  96. if (Utils_1.utils.ServerConfig.st_native_ad_show_rec_banner && Utils_1.utils.ServerConfig.st_native_ad_show_rec_banner == "true") {
  97. Utils_1.utils.showRecBanner();
  98. }
  99. var nativeData = this._nativeAd.data;
  100. var title = nativeData.title;
  101. var desc = nativeData.desc;
  102. if (title.length > 6) {
  103. title = title.slice(0, 6);
  104. title += "...";
  105. }
  106. if (desc.length > 18) {
  107. desc = desc.slice(0, 17);
  108. desc += "...";
  109. }
  110. this._nativeAdTiltle.string = title;
  111. this._nativeAdDesc.string = desc;
  112. if (nativeData.imgUrlList && nativeData.imgUrlList.length > 0) {
  113. // 有图片,优先显示图片
  114. // this._titleLabel.node.active = true;
  115. // this._icon.node.active = false;
  116. // this._img.node.active = true;
  117. // this._desLabel.node.active = true;
  118. this._noImageView.active = false;
  119. this._nativeAdImg.node.active = true;
  120. CompatibleTool_1.default.LoadRes(nativeData.imgUrlList[0], function (err, res) {
  121. if (!err && cc.isValid(_this) && _this._nativeAdImg) {
  122. _this._nativeAdImg.spriteFrame = new cc.SpriteFrame(res);
  123. _this._nativeAdImg.node.active = true;
  124. _this.content.active = true;
  125. }
  126. });
  127. }
  128. else if (PlatUtils_1.default.IsOPPO && nativeData.iconUrlList && nativeData.iconUrlList.length > 0) {
  129. // 有icon
  130. this._nativeAdImg.node.active = false;
  131. this._noImageView.active = true;
  132. CompatibleTool_1.default.LoadRes(nativeData.iconUrlList[0], function (err, res) {
  133. if (!err && cc.isValid(_this) && _this._nativeAdIcon) {
  134. _this._nativeAdIcon.spriteFrame = new cc.SpriteFrame(res);
  135. _this.content.active = true;
  136. }
  137. });
  138. }
  139. else if (PlatUtils_1.default.IsVIVO && nativeData.icon) {
  140. // 有icon
  141. this._nativeAdImg.node.active = false;
  142. this._noImageView.active = true;
  143. CompatibleTool_1.default.LoadRes(nativeData.icon, function (err, res) {
  144. if (!err && cc.isValid(_this) && _this._nativeAdIcon) {
  145. _this._nativeAdIcon.spriteFrame = new cc.SpriteFrame(res);
  146. _this.content.active = true;
  147. }
  148. });
  149. }
  150. this.node.active = true;
  151. this.reportAdShow();
  152. if (this.params) {
  153. this.params.callBack && this.params.callBack();
  154. }
  155. };
  156. // onEnable() {
  157. // // if (PlatUtils.IsOPPO || PlatUtils.IsVIVO) {
  158. // // if (!this._closeBtn.active) {
  159. // // this.node.on(cc.Node.EventType.TOUCH_START, (event: cc.Event) => {
  160. // // this._reportAdClick();
  161. // // }, this);
  162. // // }
  163. // // }
  164. // }
  165. // onDisable() {
  166. // if (PlatUtils.IsOPPO || PlatUtils.IsVIVO) {
  167. // this.node.targetOff(this);
  168. // }
  169. // }
  170. YZ_NativeItem.prototype.onBtnClickHandler = function (event, data) {
  171. switch (event.target.name) {
  172. case "closeBtn": {
  173. this.node.active = false;
  174. break;
  175. }
  176. case "Btn_Download": {
  177. this.reportAdClick();
  178. break;
  179. }
  180. }
  181. };
  182. YZ_NativeItem.prototype.reportAdShow = function () {
  183. Utils_1.utils.showLog("reportAdShow");
  184. if (this._nativeAd) {
  185. this._nativeAd.reportAdShow();
  186. }
  187. };
  188. YZ_NativeItem.prototype.reportAdClick = function () {
  189. if (this._nativeAd) {
  190. this._nativeAd.reportAdClick();
  191. }
  192. else {
  193. Utils_1.utils.showLog("广告加载失败!");
  194. }
  195. };
  196. YZ_NativeItem = __decorate([
  197. ccclass
  198. ], YZ_NativeItem);
  199. return YZ_NativeItem;
  200. }(cc.Component));
  201. exports.default = YZ_NativeItem;
  202. cc._RF.pop();