pause.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { _decorator, Component, Node, sys } from 'cc';
  2. import { tools } from '../tools';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('pause')
  5. export class pause extends Component {
  6. @property(Node) btn_back:Node;
  7. private m_cancel_back = null;
  8. private InterstitialAd:any = null;
  9. start() {
  10. let self = this;
  11. this.btn_back.on(Node.EventType.TOUCH_START,()=>{
  12. if(this.m_cancel_back!=null){
  13. this.m_cancel_back()
  14. }
  15. self.close();
  16. },this);
  17. }
  18. close(){
  19. this.node.removeFromParent();
  20. if(this.InterstitialAd ){
  21. this.InterstitialAd.destroy()
  22. this.InterstitialAd =null;
  23. }
  24. }
  25. public show(cancel_back){
  26. if(sys.platform==sys.Platform.BYTEDANCE_MINI_GAME){
  27. // this.InterstitialAd = tt.createInterstitialAd({
  28. // adUnitId: "3d0ecl882ic9ed7apr",
  29. // });
  30. // this.InterstitialAd.load()
  31. // .then(() => {
  32. // this.InterstitialAd.show().then(() => {
  33. // tools.showToast("插屏广告展示成功");
  34. // });
  35. // })
  36. // .catch((err) => {
  37. // tools.showToast(err)
  38. // console.log(err);
  39. // });
  40. //最佳实践
  41. const videoAd = tt.createRewardedVideoAd({adUnitId: "8d19519ih5ab5msq6n"});
  42. videoAd.onLoad(() => {
  43. videoAd.show();
  44. console.log("广告加载完成");
  45. });
  46. videoAd.load()
  47. }
  48. this.m_cancel_back = cancel_back;
  49. }
  50. }