AdAgentHago.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import AdAgent from "./AdAgent";
  2. import { BannerLocation } from "./YZ_Constant";
  3. import PlatUtils from "./PlatUtils";
  4. import { utils } from "./Utils";
  5. // const i18n = require('LanguageData');
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class AdAgentHago extends AdAgent {
  9. _sysData: any = null;
  10. _bannerAd: any = null;
  11. _videoAd: any = null;
  12. _videoCallback: Function = null;
  13. _isVideoShow: boolean = false;
  14. _isVideoLoaded: boolean = false;
  15. //@ts-ignore
  16. hg: any = window.hg;
  17. canShowVideo: boolean = false;
  18. public Init() {
  19. if (PlatUtils.IsHago) {
  20. this.initVideoAd();
  21. utils.showLog("hago 平台广告初始化成功!");
  22. }
  23. }
  24. public ShowBanner(location: BannerLocation = BannerLocation.Home, args: any = null) {
  25. utils.showLog("Hago平台没有banner广告!");
  26. }
  27. /**
  28. * 显示结算广告
  29. * @param data 参数: closeBtn:
  30. * statement_type
  31. * 1:只显示小游戏插屏广告
  32. * 2:只显示6个互推广告
  33. * 3:显示插屏广告+6个互推
  34. */
  35. showStatementAds(): any {
  36. let result: any = { "type": 0, "node": null };
  37. let node: cc.Node = null;
  38. let resType: number = 0;
  39. utils.showLog("结算广告 >> 显示插屏广告+6个互推");
  40. this.ShowInterstitial();
  41. node = utils.showCrossWidget6();
  42. resType = 1;
  43. result.type = resType;
  44. result.node = node;
  45. return result;
  46. }
  47. initVideoAd() {
  48. this._videoAd = this.hg.createRewardedVideoAd({
  49. adUnitId: parseInt(utils.config.hagoConfig.videoId) //测试使用9999,上线前必须申请独立的,否则无法分成! 注意:要下载最新的app测试版本9999才能生效。
  50. });
  51. this._videoAd.onClose = (res) => {
  52. if (res.isEnded) {
  53. this._videoCallback(true);
  54. this._videoCallback = null;
  55. } else {
  56. if (this._videoCallback) {
  57. this._videoCallback(false, i18n.t('ad.video_not_played_complete'));
  58. this._videoCallback = null;
  59. }
  60. }
  61. }
  62. //中途关闭广告或者拉去广告失败。
  63. this._videoAd.onError = () => {
  64. if (this._videoCallback) {
  65. this._videoCallback(false, i18n.t('ad.video_load_fail'));
  66. this._videoCallback = null;
  67. }
  68. }
  69. }
  70. public HideBanner(location: BannerLocation = BannerLocation.Home) {
  71. }
  72. public ShowInterstitial(location: BannerLocation = BannerLocation.Home) {
  73. console.warn("Hago没有插屏");
  74. }
  75. public ShowVideo(callback: Function) {
  76. if (PlatUtils.IsHago) {
  77. // 视频广告
  78. if (this._videoCallback) {
  79. return;
  80. }
  81. this._videoCallback = callback;
  82. if (!this._videoAd) {
  83. this.initVideoAd();
  84. }
  85. this._videoAd.show().then(() => {
  86. utils.showLog("video show success");
  87. })
  88. }
  89. }
  90. }