chore:剔除无关内容
This commit is contained in:
@@ -1,213 +0,0 @@
|
||||
import { _decorator, Component, director, game, Node, sys } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('DYSdk')
|
||||
export class DYSdk extends Component {
|
||||
|
||||
@property({ displayName: "bannner广告uid" })
|
||||
bannerId: string = "test";
|
||||
|
||||
@property({ displayName: "视频奖励广告uid" })
|
||||
videoUid: string = "test";
|
||||
|
||||
@property({ displayName: "插屏广告uid" })
|
||||
interstitialUid: string = "test";
|
||||
|
||||
@property({ displayName: "分享图url" })
|
||||
shareImageUrl: string = "https://mmocgame.qpic.cn/wechatgame/fNvVoACuBEOmNhzE802RLqnUuQyZ4rXTicDqz7OlVKypjYcHHo7nyfoYe7Urvdk6T/0";
|
||||
|
||||
@property({ displayName: "分享tile文本" })
|
||||
shareTilt: string = "分享文本";
|
||||
|
||||
bannerAdv = null
|
||||
videoAdv = null
|
||||
interstitialAd = null
|
||||
|
||||
|
||||
static instance: DYSdk;
|
||||
|
||||
protected onLoad(): void {
|
||||
DYSdk.instance = this
|
||||
}
|
||||
successCallback = null
|
||||
failedCallback = null
|
||||
|
||||
initBanner() {
|
||||
let winSize = window["tt"].getSystemInfoSync();//获取像素size
|
||||
// 创建 Banner 广告实例,提前初始化
|
||||
let bannerWidth = 300
|
||||
let bannerHeight = 80
|
||||
console.error("bannerId:", this.bannerId)
|
||||
this.bannerAdv = window["tt"].createBannerAd({
|
||||
adUnitId: this.bannerId,//传入自己的id,此处为banner广告位ID
|
||||
adIntervals: 30,//定时刷新,最低30S
|
||||
style: {
|
||||
left: (winSize.windowWidth - bannerWidth) / 2,
|
||||
top: winSize.windowHeight - bannerHeight,
|
||||
width: bannerWidth,
|
||||
},
|
||||
})
|
||||
//重新定banner位置
|
||||
this.bannerAdv.onResize((res) => {
|
||||
this.bannerAdv.style.top = winSize.windowHeight - this.bannerAdv.style.realHeight - 1;
|
||||
})
|
||||
|
||||
this.bannerAdv.onError((err) => {
|
||||
console.log("banner", err);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
navigateToScene() {
|
||||
window["tt"].navigateToScene({
|
||||
scene: 'sidebar',
|
||||
fail: console.log,
|
||||
success: console.log
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
initVideo() {
|
||||
let self = this
|
||||
// 创建激励视频广告实例,提前初始化
|
||||
console.log("激励视频广告id:", this.videoUid)
|
||||
this.videoAdv = window["tt"].createRewardedVideoAd({
|
||||
adUnitId: this.videoUid//传入自己的id,此处为视频广告位ID
|
||||
})
|
||||
|
||||
this.videoAdv.onLoad(() => {
|
||||
console.log("广告加载完成");
|
||||
});
|
||||
|
||||
this.videoAdv.onError(() => {
|
||||
console.log("广告错误");
|
||||
if (self.failedCallback) {
|
||||
self.failedCallback();
|
||||
}
|
||||
});
|
||||
|
||||
function listener(res) {
|
||||
if (res && res.isEnded) {
|
||||
if (self.successCallback) {
|
||||
self.successCallback();
|
||||
self.successCallback = null
|
||||
}
|
||||
} else {
|
||||
if (self.failedCallback) {
|
||||
self.failedCallback();
|
||||
self.failedCallback = null
|
||||
}
|
||||
}
|
||||
}
|
||||
this.videoAdv.onClose(listener); //这里监听广告的close 事件
|
||||
}
|
||||
|
||||
initInterstitial() {
|
||||
if (window["tt"].createInterstitialAd) {
|
||||
console.error("插屏广告id:", this.interstitialUid)
|
||||
this.interstitialAd = window["tt"].createInterstitialAd({
|
||||
adUnitId: this.interstitialUid//传入自己的id,此处为插屏广告位ID
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
||||
|
||||
this.initBanner()
|
||||
this.initVideo()
|
||||
// 创建插屏广告实例,提前初始化
|
||||
this.initInterstitial()
|
||||
this.passivityShare()
|
||||
|
||||
|
||||
window["tt"].onShow(op => {
|
||||
if (op.location == "sidebar_card") {
|
||||
console.log("应用侧边栏启动");
|
||||
}
|
||||
console.log("监听应用启动", op);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 主动分享
|
||||
public initativeShare(callBack?: any) {
|
||||
let shareTitle = this.shareTilt
|
||||
let imageUrl = this.shareImageUrl
|
||||
// 主动拉起转发,进入选择通讯录界面
|
||||
window["tt"].shareAppMessage({
|
||||
// 转发标题, 没有则默认使用小游戏的昵称
|
||||
title: shareTitle,
|
||||
// 图片链接,
|
||||
imageUrl: imageUrl
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
passivityShare(callBack?: any) {
|
||||
// 授权显示菜单
|
||||
window["tt"].showShareMenu({
|
||||
withShareTicket: false,
|
||||
// 显示菜单
|
||||
menus: ['shareAppMessage', 'shareTimeline'],
|
||||
success: (res) => {
|
||||
console.log("开始被动转发shareMenu成功");
|
||||
},
|
||||
fail: () => {
|
||||
console.log("开始被动转发shareMenu失败");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
showBanner() {
|
||||
this.bannerAdv.show()
|
||||
}
|
||||
|
||||
hideBanner() {
|
||||
this.bannerAdv.hide()
|
||||
}
|
||||
|
||||
showInterstitial() {
|
||||
// 在适合的场景显示插屏广告
|
||||
if (this.interstitialAd) {
|
||||
this.interstitialAd.show().catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
showVideo(successCallback, failCallback) {
|
||||
// 用户触发广告后,显示激励视频广告
|
||||
let self = this
|
||||
|
||||
this.successCallback = successCallback
|
||||
this.failedCallback = failCallback
|
||||
|
||||
self.videoAdv.onError((res) => {
|
||||
console.log('广告出错监听', res)
|
||||
})
|
||||
// /**展示 */
|
||||
self.videoAdv
|
||||
.show()
|
||||
.then(() => {
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('打印激励视频错误', err)
|
||||
// 可以手动加载一次
|
||||
self.videoAdv.load().then(() => {
|
||||
// 加载成功后需要再显示广告
|
||||
return self.videoAdv.show();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e50a24d5-8754-4829-87a9-f39e0213fe5e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,87 +1,28 @@
|
||||
import { _decorator, Button, Component, director, game, Label, Node, sys, Tween } from 'cc';
|
||||
import { WXSdk } from './WXSdk';
|
||||
import { DYSdk } from './DYSdk';
|
||||
import { AudioMgr } from '../audio/AudioMgr';
|
||||
const { ccclass, property } = _decorator;
|
||||
import { _decorator, Component } from 'cc';
|
||||
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
/**
|
||||
* Integration seam for a future rewarded-placement provider.
|
||||
* The project currently ships without any advertising or platform SDK.
|
||||
*/
|
||||
export interface RewardProvider {
|
||||
requestReward(onGranted: () => void): void;
|
||||
}
|
||||
|
||||
@ccclass('SdkMgr')
|
||||
export class SdkMgr extends Component {
|
||||
|
||||
export class SdkMgr extends Component implements RewardProvider {
|
||||
static instance: SdkMgr;
|
||||
|
||||
protected onLoad(): void {
|
||||
SdkMgr.instance = this
|
||||
|
||||
}
|
||||
protected start(): void {
|
||||
this.init()
|
||||
SdkMgr.instance = this;
|
||||
}
|
||||
|
||||
init() {
|
||||
if (sys.platform == sys.Platform.WECHAT_GAME) {
|
||||
WXSdk.instance.init()
|
||||
} else if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
||||
DYSdk.instance.init()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
playerRewardAds(successCallBack) {
|
||||
AudioMgr.inst.pause()
|
||||
director.pause()
|
||||
console.log("广告开启", "pause")
|
||||
let callBack = () => {
|
||||
console.log("广告开启", "resume")
|
||||
if (successCallBack != null)
|
||||
successCallBack()
|
||||
director.resume()
|
||||
AudioMgr.inst.resume()
|
||||
}
|
||||
let failCallback = () => {
|
||||
director.resume()
|
||||
AudioMgr.inst.resume()
|
||||
}
|
||||
|
||||
if (sys.platform == sys.Platform.WECHAT_GAME) {
|
||||
WXSdk.instance.showVideo(callBack, failCallback)
|
||||
} else if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
||||
DYSdk.instance.showVideo(callBack, failCallback)
|
||||
} else {
|
||||
callBack()
|
||||
}
|
||||
}
|
||||
|
||||
initativeShare() {
|
||||
if (sys.platform == sys.Platform.WECHAT_GAME) {
|
||||
WXSdk.instance.initativeShare()
|
||||
} else if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
||||
DYSdk.instance.initativeShare()
|
||||
}
|
||||
}
|
||||
|
||||
showBanner() {
|
||||
if (sys.platform == sys.Platform.WECHAT_GAME) {
|
||||
WXSdk.instance.showBanner()
|
||||
} else if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
||||
DYSdk.instance.showBanner()
|
||||
}
|
||||
}
|
||||
|
||||
hideBanner() {
|
||||
if (sys.platform == sys.Platform.WECHAT_GAME) {
|
||||
WXSdk.instance.hideBanner()
|
||||
} else if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
||||
DYSdk.instance.hideBanner()
|
||||
}
|
||||
}
|
||||
|
||||
showInterstitial() {
|
||||
if (sys.platform == sys.Platform.WECHAT_GAME) {
|
||||
WXSdk.instance.showInterstitial()
|
||||
} else if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
||||
DYSdk.instance.showInterstitial()
|
||||
}
|
||||
/**
|
||||
* SDK-free default: grant the gameplay reward immediately.
|
||||
* Replace this method body with a provider call when an SDK is added later.
|
||||
*/
|
||||
public requestReward(onGranted?: () => void): void {
|
||||
onGranted?.();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,193 +0,0 @@
|
||||
import { _decorator, Component, director, game, Node, sys } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('WXSdk')
|
||||
export class WXSdk extends Component {
|
||||
|
||||
@property({ displayName: "原生广告uid" })
|
||||
bannerId: string = "";
|
||||
|
||||
@property({ displayName: "视频奖励广告uid" })
|
||||
videoUid: string = "";
|
||||
|
||||
@property({ displayName: "插屏广告uid" })
|
||||
interstitialUid: string = "";
|
||||
|
||||
@property({ displayName: "分享图url" })
|
||||
shareImageUrl: string = "https://mmocgame.qpic.cn/wechatgame/fNvVoACuBEOmNhzE802RLqnUuQyZ4rXTicDqz7OlVKypjYcHHo7nyfoYe7Urvdk6T/0";
|
||||
|
||||
@property({ displayName: "分享tile文本" })
|
||||
shareTilt: string = "超好玩解压停车场";
|
||||
|
||||
bannerAdv = null
|
||||
videoAdv = null
|
||||
interstitialAd = null
|
||||
|
||||
|
||||
static instance: WXSdk;
|
||||
|
||||
protected onLoad(): void {
|
||||
WXSdk.instance = this
|
||||
}
|
||||
successCallback = null
|
||||
|
||||
initBanner() {
|
||||
let winSize = wx.getSystemInfoSync();//获取像素size
|
||||
let bannerWidth = 300
|
||||
let bannerHeight = 80
|
||||
// 创建 原生模板 广告实例,提前初始化
|
||||
let CustomAd = wx.createCustomAd({
|
||||
adUnitId: 'adunit-dbdd10d1ca3690d2',
|
||||
style: {
|
||||
left: (winSize.windowWidth - bannerWidth) / 2,
|
||||
top: winSize.windowHeight - bannerHeight,
|
||||
width: bannerWidth,
|
||||
}
|
||||
})
|
||||
// // 在适合的场景显示 原生模板 广告
|
||||
// CustomAd.show()
|
||||
|
||||
// 监听 原生模板 广告错误事件
|
||||
CustomAd.onError(err => {
|
||||
console.error(err.errMsg)
|
||||
});
|
||||
|
||||
this.bannerAdv = CustomAd
|
||||
|
||||
}
|
||||
|
||||
initVideo() {
|
||||
// 创建激励视频广告实例,提前初始化
|
||||
this.videoAdv = wx.createRewardedVideoAd({
|
||||
adUnitId: this.videoUid//传入自己的id,此处为视频广告位ID
|
||||
})
|
||||
}
|
||||
|
||||
initInterstitial() {
|
||||
if (wx.createInterstitialAd) {
|
||||
this.interstitialAd = wx.createInterstitialAd({
|
||||
adUnitId: this.interstitialUid//传入自己的id,此处为插屏广告位ID
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
if (sys.platform == sys.Platform.WECHAT_GAME) {
|
||||
|
||||
this.initBanner()
|
||||
this.initVideo()
|
||||
// 创建插屏广告实例,提前初始化
|
||||
this.initInterstitial()
|
||||
this.passivityShare()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 主动分享
|
||||
public initativeShare(callBack?: any) {
|
||||
let shareTitle = this.shareTilt
|
||||
let imageUrl = this.shareImageUrl
|
||||
// 主动拉起转发,进入选择通讯录界面
|
||||
wx.shareAppMessage({
|
||||
// 转发标题, 没有则默认使用小游戏的昵称
|
||||
title: shareTitle,
|
||||
// 图片链接,
|
||||
imageUrl: imageUrl
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
passivityShare(callBack?: any) {
|
||||
// 授权显示菜单
|
||||
wx.showShareMenu({
|
||||
withShareTicket: false,
|
||||
// 显示菜单
|
||||
menus: ['shareAppMessage', 'shareTimeline'],
|
||||
success: (res) => {
|
||||
console.log("开始被动转发shareMenu成功");
|
||||
},
|
||||
fail: () => {
|
||||
console.log("开始被动转发shareMenu失败");
|
||||
}
|
||||
});
|
||||
let shareTitle = this.shareTilt
|
||||
let imageUrl = this.shareImageUrl
|
||||
// 好友点击回调
|
||||
wx.onShareAppMessage(() => {
|
||||
return {
|
||||
// 转发标题, 没有则默认使用小游戏的昵称
|
||||
title: shareTitle,
|
||||
// 图片链接,
|
||||
imageUrl: imageUrl
|
||||
};
|
||||
});
|
||||
// 朋友圈点击回调
|
||||
wx.onShareTimeline(() => {
|
||||
return {
|
||||
title: shareTitle,
|
||||
imageUrl: imageUrl
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
showBanner() {
|
||||
this.bannerAdv.show()
|
||||
}
|
||||
|
||||
hideBanner() {
|
||||
this.bannerAdv.hide()
|
||||
}
|
||||
|
||||
showInterstitial() {
|
||||
// 在适合的场景显示插屏广告
|
||||
if (this.interstitialAd) {
|
||||
this.interstitialAd.show().catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
showVideo(successCallback, failCallback) {
|
||||
// 用户触发广告后,显示激励视频广告
|
||||
|
||||
if (this.videoUid == "test" || this.videoUid == "") {
|
||||
successCallback()
|
||||
return
|
||||
}
|
||||
let self = this
|
||||
self.videoAdv.show().catch(() => {
|
||||
// 失败重试
|
||||
self.videoAdv.load()
|
||||
.then(() => self.videoAdv.show())
|
||||
.catch(err => {
|
||||
console.log('激励视频 广告显示失败')
|
||||
failCallback()
|
||||
})
|
||||
})
|
||||
//拉取异常处理
|
||||
self.videoAdv.onError((err) => {
|
||||
console.log(err);
|
||||
failCallback()
|
||||
})
|
||||
self.videoAdv.onClose((res) => {
|
||||
if (!self.videoAdv) return;
|
||||
self.videoAdv.offClose();//需要清除回调,否则第N次广告会一次性给N个奖励
|
||||
//关闭
|
||||
if (res && res.isEnded || res === undefined) {
|
||||
//正常播放结束,需要下发奖励
|
||||
successCallback()
|
||||
} else {
|
||||
//播放退出,不下发奖励
|
||||
failCallback()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "73835816-1977-46d1-ac3b-0a0843758eae",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user