AdvertisingMediator.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { _decorator, Component, Node } from 'cc';
  2. import { GUIManager } from '../../../engines/gui/GUIManager';
  3. import { GUIMediator } from '../../../engines/gui/GUIMediator';
  4. import { SceneManager } from '../../../engines/scenes/SceneManager';
  5. import { LiangLiangSDK } from '../../../libs/liangliangSDK';
  6. import { PlatformManager } from '../../../Platform/PlatformManager';
  7. import { UIConst } from '../UIConst';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('AdvertisingMediator')
  10. export class AdvertisingMediator extends GUIMediator {
  11. @property({
  12. type: Node
  13. })
  14. BackButton: Node = null;
  15. start() {
  16. }
  17. OnShow(data?: any): void {
  18. this.BackButton.active = false;
  19. PlatformManager.hideBanner();
  20. this.scheduleOnce(this.showBackButton.bind(this), 3);
  21. }
  22. OnHide(): void {
  23. this.BackButton.active = false;
  24. }
  25. get LayerIndex() {
  26. return 4;
  27. }
  28. showBackButton(): void {
  29. this.BackButton.active = true;
  30. }
  31. randomCpa(): void {
  32. if (this.wx != null) {
  33. let adList: any[] = LiangLiangSDK.GetList();
  34. let data = adList[Math.floor(Math.random() * adList.length)]
  35. this.wx.navigateToMiniProgram({
  36. appId: data.app_id,
  37. path: data.app_path,
  38. success: (res) => {
  39. LiangLiangSDK.CpaReport(self.data);
  40. },
  41. fail: (res) => {
  42. // GUIManager.single.Show(UIConst.FULL_OUTPUT_UI);
  43. console.log("跳转失败!");
  44. },
  45. complete: (res) => { },
  46. });
  47. }
  48. }
  49. onClickBack(): void {
  50. let random: number = Math.random();
  51. if (random < 0.5) {
  52. this.HideSelf();
  53. if (LiangLiangSDK.CanWuChu() == true) {
  54. this.randomCpa();
  55. PlatformManager.showRewardedVideo(() => {
  56. PlatformManager.showBanner();
  57. GUIManager.single.Show(UIConst.FULL_OUTPUT_UI);
  58. }, () => {
  59. PlatformManager.showBanner();
  60. GUIManager.single.Show(UIConst.FULL_OUTPUT_UI);
  61. })
  62. }
  63. } else {
  64. this.HideSelf();
  65. }
  66. }
  67. private get wx(): any {
  68. return window["wx"];
  69. }
  70. }