import { GameMng } from "../../GameMng"; import AudioMng from "../AudioMng"; import GameData from "../GameData"; import { Singleton } from "../Singleton"; import PlatformMng from "./PlatformMng"; export default class ADSDK extends Singleton(){ //插屏 // public static pageDisTime:number=0; // public static pageLimitTime:number=15000; // public static ishowPageAd:boolean=false; public static ShowPageAD(onSucc?: Function, onFail?: Function, thisObj?: any,arg?:any){ // this.ishowPageAd=true; // ADSDK.pageDisTime = new Date().getTime(); PlatformMng.platform.showPageAd(onSucc,onFail,thisObj); } public static ClosePageAD(){ // if(this.ishowPageAd) PlatformMng.platform.closePageAd(); } //视频 private static onvideo:boolean=false; public static ShowVideoAD(onSucc?: Function, onFail?: Function, thisObj?: any,arg?:any) { if(ADSDK.onvideo)return; this.ToShowAD(onSucc,onFail,thisObj); ADSDK.onvideo=true; let timer=setTimeout(()=> { ADSDK.onvideo=false; clearTimeout(timer); }, 1000); } static _ADVideo_onSucc: Function = null; static _ADVideo_onFail: Function = null; static _ADVideo_thisObj: any = null; private static ToShowAD(onSucc: Function, onFail: Function, thisObj: any) { AudioMng.Instance.StopBGM(); ADSDK._ADVideo_onSucc = onSucc; ADSDK._ADVideo_onFail = onFail; ADSDK._ADVideo_thisObj = thisObj; PlatformMng.platform.showVideoAd(ADSDK.OnADVideoClose,onFail); } private static OnADVideoClose(res: any) { console.log("视频关闭"); AudioMng.Instance.PlayBGM(GameMng.Instance.gamebgm); if (res && res.isEnded || res === undefined) { console.log("视频播放成功"); if (ADSDK._ADVideo_onSucc) ADSDK._ADVideo_onSucc.call(ADSDK._ADVideo_thisObj); } else { console.log("视频播放未结束"); if (ADSDK._ADVideo_onFail) ADSDK._ADVideo_onFail.call(ADSDK._ADVideo_thisObj, false); } } //分享 static shareOnSucc: Function = null; static shareThisObj: any = null; static shareTimeTick: number = 0; public static Share(shareobj:any,onSucc: Function, thisObj: any) { AudioMng.Instance.StopBGM(); ADSDK.shareOnSucc = null; ADSDK.shareThisObj = null; ADSDK.shareOnSucc = onSucc; ADSDK.shareThisObj = thisObj; var date = new Date(); ADSDK.shareTimeTick = date.getTime(); PlatformMng.platform.share(shareobj, onSucc, thisObj); } public static ShareCallBack() { AudioMng.Instance.PlayBGM(GameMng.Instance.gamebgm); if (ADSDK.shareOnSucc == null) return; var func = ADSDK.shareOnSucc; var thisObj = ADSDK.shareThisObj; var timetick = ADSDK.shareTimeTick; ADSDK.shareOnSucc = null; ADSDK.shareThisObj = null; ADSDK.shareTimeTick = 0; var date = new Date(); let distime=date.getTime() - timetick; console.log(distime); if ( distime>= 3000) { // if (!ADSDK.isCurday()) { // ADSDK.shareOnSucc=func; // ADSDK.shareThisObj=thisObj; // var date = new Date(); // ADSDK.shareTimeTick = date.getTime(); // PlatformMng.platform.showPlatformMsg(); // } // else { func.call(thisObj); } } else { PlatformMng.platform.showModal({ title: '提示', content: '分享失败,请重试!' }) //UIPopDialog.OkOnly(Lng.Text("提示"), Lng.Text("分享失败,请重试!")); } } public static isCurday() { let prevDay: number = GameData.GetCustomData("gameday"); var date = new Date(); let currDay: number =date.getDay(); if( prevDay != currDay) { GameData.SetCustomData("gameday",currDay); return false; } return true; } }