games/ChaoJiJieYaGuan_LiuBianXing/assets/Script/Tools/Sdk/ads/AdsApiMgr.ts

394 lines
10 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 广告接口
* 包含 广告 录屏 分享等功能
*/
import douyinAdsApi from "./douyinAdsApi"
import weixinAdsApi from "./weixinAdsApi";
export enum plaformName {
wx = 'wx', //微信
tt = 'tt', //字节跳动
}
export default class AdsApiMgr{
public static _instance:AdsApiMgr = null
isdebug = false //是测试模式 该模式 无广告 无 网络
public static get Instance(){
if (null == this._instance) {
this._instance = new AdsApiMgr();
}
return this._instance
}
private _platform:string
get platform():string {
if(cc.sys.platform == cc.sys.BYTEDANCE_GAME){
this._platform = 'tt'
return this._platform
}else if(cc.sys.platform == cc.sys.WECHAT_GAME){
this._platform = 'wx'
return this._platform
}
}
set platform(str){
this._platform = str
}
/**
* 游戏登录
* @param _force 是否静默登录 false
*/
gameLogin(_force){
console.log('游戏登录')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.gameLogin(_force)
}else if(this.platform == plaformName.wx){
weixinAdsApi.Instance.gameLogin(_force)
}
}
/**
* 开启分享菜单
*/
showShareMenu(){
console.log('开启分享菜单')
if(this.platform == plaformName.wx){
weixinAdsApi.Instance.showShareMenu()
}
}
/**
* 游戏分享
* @ sharetype 0
*/
game_share(callBack, sharetype){
console.log('游戏分享game_share')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.game_share(callBack, sharetype)
}else if(this.platform == plaformName.wx){
weixinAdsApi.Instance.game_share(callBack)
}
else{
callBack()
}
}
/**
* 分享到好友
* @param callback
*/
shareGameToFriend(callback, note?:string){
console.log('分享到好友shareGameToFriend')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.shareGameToFriend(callback, note)
}else if(this.platform == plaformName.wx){
weixinAdsApi.Instance.shareGameToFriend(callback, note)
}
else{
callback()
}
}
/**
* banner 广告显示
*/
bannerAds_Show(){
console.log('banner广告显示')
if(this.isdebug) return
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.bannerAds_Show()
}else if(this.platform == plaformName.wx){
weixinAdsApi.Instance.bannerAds_Show()
}
}
/**
* banner 广告隐藏
*/
bannerAds_Hide(){
console.log('banner广告隐藏')
if(this.isdebug) return
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.bannerAds_Hide()
}else if(this.platform == plaformName.wx){
weixinAdsApi.Instance.bannerAds_Hide()
}
}
/**
* 加载插屏广告
*/
chaPingAds_Load(){
console.log('插屏广告加载')
if(this.isdebug) return
if(this.platform == plaformName.wx){
weixinAdsApi.Instance.chaPingAds_Load()
}
}
/**
* 插屏广告显示
*/
chaPingAds_Show(){
console.log('插屏广告显示')
if(this.isdebug) return
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.chaPingAds_Show()
}else if(this.platform == plaformName.wx){
weixinAdsApi.Instance.chaPingAds_Show()
}
}
/**
* 激励广告加载
*/
motivational_Video_Load(){
console.log('插屏广告显示')
if(this.isdebug) return
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.motivational_Video_Load()
}else if(this.platform == plaformName.wx){
weixinAdsApi.Instance.motivational_Video_Load()
}
}
/**
* 展示激励视频
* 参数1 成功回调
* 参数2 失败回调
*/
motivational_Video_Show(success, faile, type?){
console.log('展示激励视频')
if(this.isdebug) return success()
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.motivational_Video_Show(success, faile, type)
}else if(this.platform == plaformName.wx){
weixinAdsApi.Instance.motivational_Video_Show(success, faile, type)
}
else{
success()
}
}
/**
* 再得 展示激励视频
* 参数1 成功回调
* 参数2 失败回调 可以省略
*/
motivational_Other_Video_Show(success, faile, param){
console.log('再得 展示激励视频 ')
if(this.isdebug) return success()
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.motivational_Other_Video_Show(success, faile, param)
}else if(this.platform == plaformName.wx){
weixinAdsApi.Instance.motivational_Video_Show(success, faile)
}
else{
success()
}
}
/**
* 创建原生广告模板
* @param {0:单个,1:横向多个,2:竖向多个,3:矩阵} type
*/
createCustomAd(type){
console.log('创建原生广告type=', type)
if(this.isdebug) return
if(this.platform == plaformName.wx){
weixinAdsApi.Instance.createCustomAd(type)
}
}
/**
* 展示
* @param {*} type
*/
showCustomAd(type){
console.log('展示原生广告type=', type)
if(this.isdebug) return
if(this.platform == plaformName.wx){
weixinAdsApi.Instance.showCustomAd(type)
}
}
/**
* 隐藏, 销毁原生广告模板
*/
hideCustomAd(type){
console.log('隐藏, 销毁原生广告模板', type)
if(this.isdebug) return
if(this.platform == plaformName.wx){
weixinAdsApi.Instance.hideCustomAd(type)
}
}
/**
* 录制视频开始
*/
recording_Video_Start(){
console.log('录制视频开始')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.recording_Video_Start()
}
}
/**
* 录制视频结束
*/
recording_Video_End(){
console.log('录制视频结束')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.recording_Video_End()
}
}
/**
* 录制视频分享
* 参数1 成功回调方法
* 参数2 失败回调方法
*/
recording_Video_Share(callBack, failCallBack){
console.log('录制视频分享')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.recording_Video_Share(callBack, failCallBack)
}else if(this.platform == plaformName.wx){
weixinAdsApi.Instance.game_share(callBack)
}
else{
callBack()
}
}
//录屏是否存在
getVideoIsExist(){
console.log('录屏是否存在')
if(this.platform == plaformName.tt){
return douyinAdsApi.Instance.getVideoIsExist()
}else{
return 0
}
}
/**
* 添加桌面
* @param scb
* @param fcb
*/
addShortcut(scb:Function, fcb:Function){
console.log('添加桌面')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.addShortcut(scb, fcb)
}else{
scb()
}
}
/**
* 检测是否添加到桌面
* @returns true 不支持 或者 已添加
*/
checkShortcut(){
console.log('检测是否添加到桌面')
if(this.platform == plaformName.tt){
return douyinAdsApi.Instance.checkShortcut()
}else{
return true
}
}
/**
* 添加收藏
* @param {*} _typestring = bar customize
*/
addToMyFavorite(_type){
console.log('添加收藏')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.addToMyFavorite(_type)
}
}
/**
* 提示框
*/
showToast(str){
console.log('提示框')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.showToast(str)
}else if(this.platform == plaformName.wx){
weixinAdsApi.Instance.showToast(str)
}
else{
console.log('提示信息=', str)
}
}
/**
* 手机震动
*/
vibrateShort(){
console.log('手机震动')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.vibrateShort()
}else if(this.platform == plaformName.wx){
weixinAdsApi.Instance.vibrateShort()
}
}
/**
* 设置 抖音排行榜 数字类型排行榜
* @param value 数值
*/
setImRankData_Num(value:string){
console.log('设置 抖音排行榜 数字类型排行榜')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.setImRankData_Num(value)
}
}
/**
* 获取数字类型原生排行榜
*/
getImRankList_Num(){
console.log('获取数字类型原生排行榜')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.getImRankList_Num()
}
}
/**
* 设置 抖音排行榜 枚举类型排行榜
* @param value 数值
* @param priority 权重
*/
setImRankData_Enum(value:string,priority:number){
console.log('设置 抖音排行榜 枚举类型排行榜')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.setImRankData_Enum(value, priority)
}
}
/**
* 获取枚举类型原生排行榜
*/
getImRankList_Enum(){
console.log('获取枚举类型原生排行榜')
if(this.platform == plaformName.tt){
douyinAdsApi.Instance.getImRankList_Enum()
}
}
/**
* 上传微信 游戏得分
*/
upWxHighScore(score, callBack){
console.log('上传微信 游戏得分')
if(this.platform == plaformName.wx){
weixinAdsApi.Instance.upWxHighScore(score, callBack)
}
}
}