You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
6.7 KiB
180 lines
6.7 KiB
import { sys } from "cc";
|
|
import PlatformData from "./Data/PlatformData";
|
|
import TTData from "./Data/TTData";
|
|
import WXData from "./Data/WXData";
|
|
import KSData from "./Data/KSData";
|
|
import DefaultPlatform from "./PlatformClass/DefaultPlatform";
|
|
import TTPlatform from "./PlatformClass/TTPlatform";
|
|
import WXPlatform from "./PlatformClass/WXPlatform";
|
|
import KSPlatform from "./PlatformClass/KSPlatform";
|
|
import PlatformManagerProxy from "./PlatformManagerProxy";
|
|
import IPlatform from "./T/IPlatform";
|
|
import { TDAnalyticsMgr } from "../Mgr_Ge/TDAnalyticsMgr";
|
|
import { GEData, GEType } from "../Mgr_Ge/GeDifine";
|
|
import { PlatformEnum_KS, PlatformEnum_TT, PlatformEnum_WX } from "./Data/PlatformEnum";
|
|
import CsvMgr from "../Mgr_CSV/CsvMgr";
|
|
import { ShareInfo } from "./T/ShareInfo";
|
|
import { GEAnalyticsMgr } from "../Mgr_Ge/GEAnalyticsMgr";
|
|
import CySDK from "../Mgr_Ge/CySDK";
|
|
|
|
/**
|
|
* 平台管理器
|
|
*/
|
|
export default class PlatformManager {
|
|
/** 平台实例 */
|
|
private static _instance: PlatformManager;
|
|
public static get instance(): PlatformManager {
|
|
if (this._instance == null) {
|
|
this._instance = new PlatformManager();
|
|
}
|
|
return this._instance;
|
|
}
|
|
|
|
/** 平台实例 */
|
|
private m_platformInstance: IPlatform;
|
|
|
|
/** 平台数据 */
|
|
private m_platformData: PlatformData;
|
|
|
|
get platData(){
|
|
return this.m_platformData;
|
|
}
|
|
|
|
/** 获取平台实例 */
|
|
public static get PlatformInstance(): IPlatform {
|
|
if (!this.instance.m_platformInstance) {
|
|
console.log('还没有设置过平台实例代理!');
|
|
}
|
|
return this.instance.m_platformInstance;
|
|
}
|
|
|
|
MyPlatform: string = "";//"QQ" "TT" 微信与QQ 头条 已经兼容 所以需要手动修改平台判定
|
|
|
|
showSideBar: boolean = false; // 根据平台,判断是否显示侧边栏
|
|
|
|
/**平台管理类开始初始化时间 */
|
|
PlatformInitTime: number = 0;
|
|
|
|
/**
|
|
* 初始化平台
|
|
* @param appId
|
|
*/
|
|
public init() {
|
|
if (this.m_platformInstance != null) {
|
|
console.warn("已调用过平台创建为", PlatformManagerProxy.GetPlatformStr(this.m_platformInstance.platform), "不能重复创建");
|
|
return this.m_platformInstance;
|
|
}
|
|
this.PlatformInitTime = Date.now();
|
|
//获取平台实例
|
|
let result: IPlatform;
|
|
if (sys.isNative) {
|
|
console.log("未识别平台,默认创建为web", sys.platform);
|
|
result = new DefaultPlatform();
|
|
} else {
|
|
if (window["ks"]) {
|
|
result = new KSPlatform();
|
|
this.m_platformData = new KSData(PlatformEnum_KS.ks681169446177010988);
|
|
this.showSideBar = true;
|
|
}else{
|
|
switch (sys.platform) {
|
|
case sys.Platform.WECHAT_GAME:
|
|
result = new WXPlatform();
|
|
this.m_platformData = new WXData(PlatformEnum_WX.wx275346926efea5f1);
|
|
break;
|
|
case sys.Platform.BYTEDANCE_MINI_GAME:
|
|
result = new TTPlatform();
|
|
this.m_platformData = new TTData(PlatformEnum_TT.tt9eace81101ae13bc02);
|
|
this.showSideBar = true;
|
|
break;
|
|
default:
|
|
console.log("未识别平台,默认创建为web", sys.platform);
|
|
result = new DefaultPlatform();
|
|
this.m_platformData = new PlatformData();
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
this.m_platformInstance = result;
|
|
//设置代理
|
|
PlatformManagerProxy.instance.PlatformInstance = result;
|
|
//设置到全局
|
|
window['$Platform'] = this.m_platformInstance;
|
|
//
|
|
console.log("平台实例创建完成", PlatformManagerProxy.GetPlatformStr(this.m_platformInstance.platform));
|
|
}
|
|
|
|
public InitAdParam() {
|
|
// 合并后台广告参数
|
|
const vedioAd = CsvMgr.getRewardVideoId();
|
|
if(vedioAd && vedioAd.length > 0){
|
|
this.m_platformData.rewardVideoId = vedioAd;
|
|
}
|
|
const interstitialAd = CsvMgr.getInterstitialId();
|
|
if(interstitialAd && interstitialAd.length > 0){
|
|
this.m_platformData.interstitialId = [];
|
|
for(let i = 0; i < interstitialAd.length; i++){
|
|
this.m_platformData.interstitialId.push(interstitialAd[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 初始化分享信息
|
|
*/
|
|
public InitShareInfo() {
|
|
if (CsvMgr.OpenHot) {
|
|
ConsoleEx.Com("开始获取分享信息")
|
|
const tConfig = CsvMgr.getShareId();
|
|
this.m_platformData.shareId = [];
|
|
for (let i = 0; i < tConfig.length; i++) {
|
|
const value = tConfig[i];
|
|
if (!value.shareId) { ConsoleEx.Log("分享ID错误"); continue;}
|
|
let tData = new ShareInfo()
|
|
tData.shareID = value.shareId;
|
|
tData.shareImg = value.shareImg;
|
|
tData.shareTitle = value.shareTitle;
|
|
this.m_platformData.shareId.push(tData);
|
|
}
|
|
ConsoleEx.Com("覆盖分享信息", this.m_platformData.shareId)
|
|
this.m_platformInstance._InitShareList();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 初始化平台
|
|
*/
|
|
public initPlatform(callBack:Function) {
|
|
//
|
|
this.m_platformInstance.Init(this.m_platformData,callBack);
|
|
//
|
|
console.log('平台初始化完成');
|
|
}
|
|
|
|
showvideo(data: {name: string,gamelv:number},callback?: Function,shibai?:Function){
|
|
if (sys.isBrowser) {
|
|
callback(true);
|
|
return;
|
|
}
|
|
TDAnalyticsMgr.ins.TrySendtrack(GEData.GEeventName.video_show,{source:data.name, enter_level_id:data.gamelv});
|
|
const adstart = Date.now();
|
|
this.m_platformInstance.ShowRewardVideoAd(()=>{
|
|
// 免广不统计
|
|
if(Date.now() - adstart > 7000){
|
|
TDAnalyticsMgr.ins.recordAdTime();
|
|
TDAnalyticsMgr.ins.addADcnt();
|
|
TDAnalyticsMgr.ins.allAdCount();
|
|
TDAnalyticsMgr.ins.TrySendtrack(GEData.GEeventName.video_finish,{source:data.name, enter_level_id:data.gamelv});
|
|
GEAnalyticsMgr.ins.TrySendtrack(GEType.video_finish,{ad_name:data.name, level_id:data.gamelv, n_time:1});
|
|
CySDK.onAdFinish("level","normal",data.gamelv,data.name);
|
|
}
|
|
callback && callback(true);
|
|
},()=>{
|
|
callback && callback(false);
|
|
CySDK.onAdCancel("level","normal",data.gamelv,data.name);
|
|
},()=>{
|
|
shibai && shibai();
|
|
});
|
|
}
|
|
}
|