ADSDK.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { GameMng } from "../../GameMng";
  2. import AudioMng from "../AudioMng";
  3. import GameData from "../GameData";
  4. import { Singleton } from "../Singleton";
  5. import PlatformMng from "./PlatformMng";
  6. export default class ADSDK extends Singleton<ADSDK>(){
  7. //插屏
  8. // public static pageDisTime:number=0;
  9. // public static pageLimitTime:number=15000;
  10. // public static ishowPageAd:boolean=false;
  11. public static ShowPageAD(onSucc?: Function, onFail?: Function, thisObj?: any,arg?:any){
  12. // this.ishowPageAd=true;
  13. // ADSDK.pageDisTime = new Date().getTime();
  14. PlatformMng.platform.showPageAd(onSucc,onFail,thisObj);
  15. }
  16. public static ClosePageAD(){
  17. // if(this.ishowPageAd)
  18. PlatformMng.platform.closePageAd();
  19. }
  20. //视频
  21. private static onvideo:boolean=false;
  22. public static ShowVideoAD(onSucc?: Function, onFail?: Function, thisObj?: any,arg?:any) {
  23. if(ADSDK.onvideo)return;
  24. this.ToShowAD(onSucc,onFail,thisObj);
  25. ADSDK.onvideo=true;
  26. let timer=setTimeout(()=> {
  27. ADSDK.onvideo=false;
  28. clearTimeout(timer);
  29. }, 1000);
  30. }
  31. static _ADVideo_onSucc: Function = null;
  32. static _ADVideo_onFail: Function = null;
  33. static _ADVideo_thisObj: any = null;
  34. private static ToShowAD(onSucc: Function, onFail: Function, thisObj: any)
  35. {
  36. AudioMng.Instance.StopBGM();
  37. ADSDK._ADVideo_onSucc = onSucc;
  38. ADSDK._ADVideo_onFail = onFail;
  39. ADSDK._ADVideo_thisObj = thisObj;
  40. PlatformMng.platform.showVideoAd(ADSDK.OnADVideoClose,onFail);
  41. }
  42. private static OnADVideoClose(res: any) {
  43. console.log("视频关闭");
  44. AudioMng.Instance.PlayBGM(GameMng.Instance.gamebgm);
  45. if (res && res.isEnded || res === undefined) {
  46. console.log("视频播放成功");
  47. if (ADSDK._ADVideo_onSucc) ADSDK._ADVideo_onSucc.call(ADSDK._ADVideo_thisObj);
  48. } else {
  49. console.log("视频播放未结束");
  50. if (ADSDK._ADVideo_onFail) ADSDK._ADVideo_onFail.call(ADSDK._ADVideo_thisObj, false);
  51. }
  52. }
  53. //分享
  54. static shareOnSucc: Function = null;
  55. static shareThisObj: any = null;
  56. static shareTimeTick: number = 0;
  57. public static Share(shareobj:any,onSucc: Function, thisObj: any) {
  58. AudioMng.Instance.StopBGM();
  59. ADSDK.shareOnSucc = null;
  60. ADSDK.shareThisObj = null;
  61. ADSDK.shareOnSucc = onSucc;
  62. ADSDK.shareThisObj = thisObj;
  63. var date = new Date();
  64. ADSDK.shareTimeTick = date.getTime();
  65. PlatformMng.platform.share(shareobj, onSucc, thisObj);
  66. }
  67. public static ShareCallBack() {
  68. AudioMng.Instance.PlayBGM(GameMng.Instance.gamebgm);
  69. if (ADSDK.shareOnSucc == null) return;
  70. var func = ADSDK.shareOnSucc;
  71. var thisObj = ADSDK.shareThisObj;
  72. var timetick = ADSDK.shareTimeTick;
  73. ADSDK.shareOnSucc = null;
  74. ADSDK.shareThisObj = null;
  75. ADSDK.shareTimeTick = 0;
  76. var date = new Date();
  77. let distime=date.getTime() - timetick;
  78. console.log(distime);
  79. if ( distime>= 3000) {
  80. // if (!ADSDK.isCurday()) {
  81. // ADSDK.shareOnSucc=func;
  82. // ADSDK.shareThisObj=thisObj;
  83. // var date = new Date();
  84. // ADSDK.shareTimeTick = date.getTime();
  85. // PlatformMng.platform.showPlatformMsg();
  86. // }
  87. // else
  88. {
  89. func.call(thisObj);
  90. }
  91. } else {
  92. PlatformMng.platform.showModal({
  93. title: '提示',
  94. content: '分享失败,请重试!'
  95. })
  96. //UIPopDialog.OkOnly(Lng.Text("提示"), Lng.Text("分享失败,请重试!"));
  97. }
  98. }
  99. public static isCurday()
  100. {
  101. let prevDay: number = GameData.GetCustomData("gameday");
  102. var date = new Date();
  103. let currDay: number =date.getDay();
  104. if( prevDay != currDay)
  105. {
  106. GameData.SetCustomData("gameday",currDay);
  107. return false;
  108. }
  109. return true;
  110. }
  111. }