UIADPanel.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { utils } from "../../common-plugin/Scripts/Utils";
  2. import { cocosz } from "../Framework/CocosZ";
  3. import Msg from "../Framework/Msg";
  4. import AESUtil from "../AESUtil"
  5. import ATSDK from "../AnyThinkAds/ATJSSDK";
  6. import ATRewardedVideoSDK from "../AnyThinkAds/ATRewardedVideoJSSDK";
  7. import AAJS2 from "../ATAndroidJS2";
  8. import GlobalManager from '../GlobalManager';
  9. // @ts-ignore
  10. const i18n = require('LanguageData');
  11. const { ccclass, property } = cc._decorator;
  12. @ccclass
  13. export default class NewClass extends cc.Component {
  14. @property(cc.Node)
  15. btnAD: cc.Node = null;
  16. @property(cc.Node)
  17. btnSkip: cc.Node = null;
  18. adKey: string = "zh_ad_type";
  19. start() {
  20. console.log('zh:uiadpanel start ')
  21. if (cocosz.isADON) {
  22. this.node.scale = 0;
  23. cc.tween(this.node).to(0.3, { scale: 1 }, { easing: "backOut" }).start();
  24. utils.SendEvent("页面-" + (this.isDiamond ? "钻石" : "金币"));
  25. } else {
  26. this.node.destroy();
  27. }
  28. this.initAdForPage();
  29. }
  30. initAdForPage() {
  31. if (cc.sys.os === cc.sys.OS_ANDROID) {
  32. let deviceId = AAJS2.getDeviceUserId();
  33. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  34. var setting = {};
  35. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  36. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  37. }
  38. }
  39. isDiamond: boolean = false;
  40. setDiamond() {
  41. this.isDiamond = true;
  42. this.node.getChildByName("bg").active = false;
  43. this.node.getChildByName("bg1").active = true;
  44. }
  45. watchAD() {
  46. utils.SendEvent(`视频-${this.isDiamond ? "钻石购买" : "金币购买"}-播放`)
  47. // 注册方法 , this.ClickClose.bind(this));
  48. GlobalManager.getInstance().registerMethod('event_UIADPanel_forAd', this.event_UIADPanel_forAd.bind(this));
  49. // cc.sys.localStorage.setItem(this.adKey, 'qianDao_dblq');//
  50. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  51. console.log('zh:AD ready for idx2')
  52. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  53. } else {
  54. console.log('zh:AD not ready for idx2')
  55. this.event_UIADPanel_forAd();
  56. }
  57. if (2 > 1) {
  58. return;//下面是原始的代码
  59. }
  60. cocosz.watchAD(() => {
  61. utils.SendEvent(`视频-${this.isDiamond ? "钻石购买" : "金币购买"}-成功`)
  62. if (this.isDiamond) {
  63. let num = cocosz.isDeBug ? 10000 : 200;
  64. cocosz.dataMgr.DiamondCount += num;
  65. Msg.Show(i18n.t("msg.gxhdzs") + num);//恭喜获得钻石
  66. }
  67. else {
  68. let num = cocosz.isDeBug ? 10000 : 500;
  69. cocosz.dataMgr.CoinCount += num;
  70. Msg.Show(i18n.t("msg.gxhdjb") + num);//恭喜获得金币
  71. }
  72. this.node.destroy();
  73. }, () => {
  74. utils.SendEvent(`视频-${this.isDiamond ? "钻石购买" : "金币购买"}-失败`)
  75. })
  76. }
  77. //zh:
  78. event_UIADPanel_forAd(){
  79. console.log('zh:event_UIADPanel_forAd 被触发')
  80. if (this.isDiamond) {
  81. let num = cocosz.isDeBug ? 10000 : 200;
  82. cocosz.dataMgr.DiamondCount += num;
  83. Msg.Show(i18n.t("msg.gxhdzs") + num);//恭喜获得钻石
  84. }
  85. else {
  86. let num = cocosz.isDeBug ? 10000 : 500;
  87. cocosz.dataMgr.CoinCount += num;
  88. Msg.Show(i18n.t("msg.gxhdjb") + num);//恭喜获得金币
  89. }
  90. this.node.destroy();
  91. }
  92. exit() {
  93. cocosz.audioMgr.playBtnEffect();
  94. this.node.destroy();
  95. }
  96. }