数数代码

This commit is contained in:
COMPUTER\EDY 2025-10-17 18:08:59 +08:00
parent 4a14470513
commit 7d4c88b906
6 changed files with 137 additions and 28 deletions

View File

@ -17581,7 +17581,7 @@
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "b51c6577-3f31-4777-bf4a-6bfad58f0612"
"__uuid__": "ab9b1a6d-9c1b-4d87-ba50-43dbe414eb7f"
},
"_type": 0,
"_sizeMode": 1,

View File

@ -409,11 +409,11 @@ export default class GameManager extends cc.Component {
if (data) {
if (data.isFirst == true) {
cc.fx.GameConfig.GM_INFO.first = true;
if (data.register_time) {
const time = data.register_time;
let share = cc.fx.GameTool.isFromShareByScene();
MiniGameSdk.API.shushu_userSet(time, share);
}
// if (data.register_time) {
// const time = data.register_time;
// let share = cc.fx.GameTool.isFromShareByScene();
// MiniGameSdk.API.shushu_userSet(time, share);
// }
}
else {
}

View File

@ -1979,38 +1979,37 @@ export default class MapConroler extends cc.Component {
// coin: -coin
}
// cc.fx.GameTool.shareToWX(() => {
// cc.fx.GameTool.onShowVideo(() => {
// this.runRewive(data);
// });
let overData = {
ad_placement_name: "2000", //内部广告位名称
current_page: "GameScene" //所在页面
}
// let coin = 500;
if (type == "time") {
if (cc.fx.GameTool.canObtainByShare("reviveTime")) {
cc.fx.GameTool.shareToWX(this.runRewive(data))
} else {
cc.fx.GameTool.onShowVideo(this.runRewive(data))
cc.fx.GameTool.onShowVideo(this.runRewive(data), overData)
}
}
else if (type == "boom") {
if (cc.fx.GameTool.canObtainByShare("removeBomb")) {
cc.fx.GameTool.shareToWX(this.runRewive(data))
} else {
cc.fx.GameTool.onShowVideo(this.runRewive(data))
cc.fx.GameTool.onShowVideo(this.runRewive(data), overData)
}
}
else if (type == "lock") {
if (cc.fx.GameTool.canObtainByShare("openDoor")) {
cc.fx.GameTool.shareToWX(this.runRewive(data))
} else {
cc.fx.GameTool.onShowVideo(this.runRewive(data))
cc.fx.GameTool.onShowVideo(this.runRewive(data), overData)
}
}
else if (type == "revolving") {
if (cc.fx.GameTool.canObtainByShare("removeJam")) {
cc.fx.GameTool.shareToWX(this.runRewive(data))
} else {
cc.fx.GameTool.onShowVideo(this.runRewive(data))
cc.fx.GameTool.onShowVideo(this.runRewive(data), overData)
}
} else {
// this.runRewive(data);

View File

@ -280,7 +280,7 @@ export namespace MiniGameSdk {
* @param maxVideoCount 3
* @returns
*/
show(onResult: (res: EAdVideoResult, count: number) => void, target?: any, maxVideoCount: number = 3): void {
show(onResult: (res: EAdVideoResult, count: number) => void, target?: any, maxVideoCount: number = 3, video_data: any = null): void {
let callback = (state: EAdVideoResult, count: number) => {
// 确保广告实例被清理
if (this._adVideo) {
@ -321,15 +321,29 @@ export namespace MiniGameSdk {
}
}
}
let responseData = {
ad_type: "激励视频", //广告类型
ad_placement_name: video_data?.ad_placement_name || "", //内部广告位名称 //2000复活 道具 2001 2002 2003
ad_placement_id: "adunit-32a23bc2b2f4ee0a", //内部广告位ID
current_page: video_data?.current_page || "", //所在页面
error_detail_info: "", //错误信息
error_detail_code: "", //错误码
is_filled_success: false //是否完整播放
}
if (isWechat()) {
try {
// @ts-ignore
this._adVideo = wx.createRewardedVideoAd({
adUnitId: this._adUid
});
responseData.is_filled_success = true;
cc.fx.GameTool.shushu_Track("ad_response", responseData);
} catch (e) {
console.error('Failed to create rewarded video ad:', e);
responseData.is_filled_success = false;
responseData.error_detail_info = e.toString();
responseData.error_detail_code = e.errCode?.toString() || "";
cc.fx.GameTool.shushu_Track("ad_response", responseData);
callback(EAdVideoResult.ERROR, 0);
return;
}
@ -357,6 +371,7 @@ export namespace MiniGameSdk {
this._adVideo.onError((err: { errMsg: string, errCode: number }) => {
console.log('Ad video error:', err);
cc.fx.GameTool.shushu_Track("ad_response", showData);
if (err.errCode) {
console.log('Ad video error code:', err.errCode);
}
@ -369,13 +384,28 @@ export namespace MiniGameSdk {
// this._adVideo.onError(onErrorHandler);
this._adVideo.onClose(onAdVideoClosed);
let showData = {
ad_type: "激励视频", //广告类型
ad_placement_name: video_data?.ad_placement_name || "", //内部广告位名称 //2000复活 道具 2001 2002 2003
ad_placement_id: "adunit-32a23bc2b2f4ee0a", //内部广告位ID
current_page: video_data?.current_page || "", //所在页面
error_detail_info: "", //错误信息
error_detail_code: "", //错误码
is_show_success: false //是否完整播放
}
// 尝试显示广告
this._adVideo.show().catch((err: { errMsg: string, errCode: number }) => {
console.log('Show video ad error:', err);
// 尝试加载广告后再显示
this._adVideo.load().then(() => {
showData.is_show_success = true;
cc.fx.GameTool.shushu_Track("ad_show", showData);
return this._adVideo.show();
}).catch((loadErr: { errMsg: string, errCode: number }) => {
showData.is_show_success = false;
showData.error_detail_info = loadErr.errMsg;
showData.error_detail_code = loadErr.errCode.toString();
cc.fx.GameTool.shushu_Track("ad_show", showData);
console.log('Load and show video ad error:', loadErr);
if (loadErr.errCode) {
console.log('Load error code:', loadErr.errCode);
@ -533,10 +563,10 @@ export namespace MiniGameSdk {
* @param target onVideoResult的拥有者
* @param maxVideoCount 3count的结果永远是1或0
*/
public showVideo(adUid: string, onVideoResult: (res: EAdVideoResult, count: number) => void, target?: any, maxVideoCount: number = 3) {
public showVideo(adUid: string, video_data, onVideoResult: (res: EAdVideoResult, count: number) => void, target?: any, maxVideoCount: number = 3) {
this._video?.destory();
this._video = new ADVideo(adUid);
this._video.show(onVideoResult, target, maxVideoCount);
this._video.show(onVideoResult, target, maxVideoCount, video_data);
}
/**

View File

@ -103,7 +103,11 @@ export default class NewClass extends cc.Component {
if (cc.fx.GameTool.canObtainByShare("health")) {
cc.fx.GameTool.shareToWX(callback)
} else {
cc.fx.GameTool.onShowVideo(callback)
let data = {
ad_placement_name: "1002", //内部广告位名称
current_page: "HomeScene" //所在页面
}
cc.fx.GameTool.onShowVideo(callback, data)
}
}

View File

@ -703,26 +703,32 @@ var GameTool = {
callback();
}
let video_data = {
ad_placement_name: "", //内部广告位名称
current_page: "GameScene" //所在页面
}
if (propid == 2001) {
if (cc.fx.GameTool.canObtainByShare("freeze")) {
cc.fx.GameTool.shareToWX(cb)
} else {
cc.fx.GameTool.onShowVideo(cb)
video_data.ad_placement_name = propid.toString();
cc.fx.GameTool.onShowVideo(cb, video_data)
}
}
else if (propid == 2002) {
if (cc.fx.GameTool.canObtainByShare("hammer")) {
cc.fx.GameTool.shareToWX(cb)
} else {
cc.fx.GameTool.onShowVideo(cb)
video_data.ad_placement_name = propid.toString();
cc.fx.GameTool.onShowVideo(cb, video_data)
}
}
else if (propid == 2003) {
if (cc.fx.GameTool.canObtainByShare("magicWand")) {
cc.fx.GameTool.shareToWX(cb)
} else {
cc.fx.GameTool.onShowVideo(cb)
video_data.ad_placement_name = propid.toString();
cc.fx.GameTool.onShowVideo(cb, video_data)
}
}
// cc.fx.GameTool.shareToWX(() => {
@ -959,13 +965,61 @@ var GameTool = {
success: data.success || null, //被帮助关卡是否成功
}
break;
case "daily_task":
eventData = {
task_id: data.id,
task_status: data.status
}
break;
case "ad_request": //点击广告按钮
eventData = {
ad_type: data.ad_type, //广告类型
ad_placement_name: data.ad_placement_name, //内部广告位名称
ad_placement_id: data.ad_placement_id, //内部广告位ID
current_page: data.current_page //所在页面
}
break;
case "ad_response": //广告填充完成
eventData = {
ad_type: data.ad_type, //广告类型
ad_placement_name: data.ad_placement_name, //内部广告位名称
ad_placement_id: data.ad_placement_id, //内部广告位ID
current_page: data.current_page, //所在页面
is_filled_success: data.is_filled_success, //是否填充成功
error_detail_info: data.error_detail_info, //错误详情信息
error_detail_code: data.error_detail_code, //错误详情代码
}
break;
case "ad_show": //广告展示
eventData = {
ad_type: data.ad_type, //广告类型
ad_placement_name: data.ad_placement_name, //内部广告位名称
ad_placement_id: data.ad_placement_id, //内部广告位ID
current_page: data.current_page, //所在页面
is_show_success: data.is_show_success, //是否填充成功
error_detail_info: data.error_detail_info, //错误详情信息
error_detail_code: data.error_detail_code, //错误详情代码
}
break;
case "ad_click":
eventData = {
ad_type: data.ad_type, //广告类型
ad_placement_name: data.ad_placement_name, //内部广告位名称
ad_placement_id: data.ad_placement_id, //内部广告位ID
current_page: data.current_page //所在页面
}
break;
case "ad_close": //广告关闭
eventData = {
ad_type: data.ad_type, //广告类型
ad_placement_name: data.ad_placement_name, //内部广告位名称
ad_placement_id: data.ad_placement_id, //内部广告位ID
current_page: data.current_page, //所在页面
ad_duration: data.ad_duration, //广告展示时长
ad_play_duration: data.ad_play_duration, //广告播放时长
is_complete_play: data.is_complete_play //是否完整播放
}
break;
}
if (name == "stage_help") {
console.log("准备上报完成", data);
@ -1417,20 +1471,42 @@ var GameTool = {
},
onShowVideo(callback: Function, parentNode) {
MiniGameSdk.AdvertManager.instance.showVideo('adunit-32a23bc2b2f4ee0a', (res: MiniGameSdk.EAdVideoResult, count: number) => {
onShowVideo(callback: Function, videoData: any) {
let requestData = {
ad_type: "激励视频", //广告类型
ad_placement_name: videoData.ad_placement_name, //内部广告位名称 //2000复活 道具 2001 2002 2003
ad_placement_id: "adunit-32a23bc2b2f4ee0a", //内部广告位ID
current_page: videoData.current_page, //所在页面
}
cc.fx.GameTool.shushu_Track("ad_request", requestData);
MiniGameSdk.AdvertManager.instance.showVideo('adunit-32a23bc2b2f4ee0a', videoData, (res: MiniGameSdk.EAdVideoResult, count: number) => {
console.log('用户看的视频广告个数是:', count);
// 根据用户观看广告的结果,执行不同的逻辑
// 根据用户观看广告的结果执行不同的逻辑s
console.log('用户观看视频广告结果:', res);
let data = {
ad_type: "激励视频", //广告类型
ad_placement_name: videoData.ad_placement_name, //内部广告位名称 //2000复活 道具 2001 2002 2003
ad_placement_id: "adunit-32a23bc2b2f4ee0a", //内部广告位ID
current_page: videoData.current_page, //所在页面
ad_duration: 0, //广告展示时长
ad_play_duration: 30, //广告播放时长
is_complete_play: false //是否完整播放
}
switch (res) {
case MiniGameSdk.EAdVideoResult.ACCEPT:
data.is_complete_play = true;
// MiniGameSdk.API.showToast('用户看完广告,可以奖励');
cc.fx.GameTool.shushu_Track("ad_close", data);
callback();
break;
case MiniGameSdk.EAdVideoResult.REJECT:
data.is_complete_play = false;
MiniGameSdk.API.showToast('广告中断,未获得奖励');
cc.fx.GameTool.shushu_Track("ad_close", data);
break;
case MiniGameSdk.EAdVideoResult.ERROR:
MiniGameSdk.API.showToast('广告加载失败,请稍后再试');
cc.fx.GameTool.shushu_Track("ad_close", data);
break;
default:
// 其他情况,不作处理