diff --git a/assets/Scene/GameScene.fire b/assets/Scene/GameScene.fire index 6876cdd..4828ce7 100644 --- a/assets/Scene/GameScene.fire +++ b/assets/Scene/GameScene.fire @@ -15928,7 +15928,7 @@ "__id__": 380 } ], - "_active": false, + "_active": true, "_components": [], "_prefab": null, "_opacity": 255, @@ -17581,7 +17581,7 @@ "_srcBlendFactor": 770, "_dstBlendFactor": 771, "_spriteFrame": { - "__uuid__": "ab9b1a6d-9c1b-4d87-ba50-43dbe414eb7f" + "__uuid__": "b51c6577-3f31-4777-bf4a-6bfad58f0612" }, "_type": 0, "_sizeMode": 1, diff --git a/assets/Script/heathnum.ts b/assets/Script/heathnum.ts index 1b2cc0b..2b1385f 100644 --- a/assets/Script/heathnum.ts +++ b/assets/Script/heathnum.ts @@ -23,6 +23,12 @@ export default class NewClass extends cc.Component { //切换的按钮数组 // 删除此按钮数组内的 金币买体力 改成分享 @property([cc.Node]) switchButtons: cc.Node[] = []; + + @property(cc.Sprite) + share_img: cc.Sprite = null; + + @property(cc.Sprite) + ad_img: cc.Sprite = null; //金币花费数 // @property(cc.Node) // coin: cc.Node = null; @@ -32,13 +38,13 @@ export default class NewClass extends cc.Component { onLoad() { this.btn_Touch = true; if (cc.fx.GameTool.canObtainByShare("health")) { - // 分享 - this.switchButtons[2].getChildByName("share_img").active = true; - this.switchButtons[2].getChildByName("ad_img").active = false; + this.share_img.node.active = true; + + this.ad_img.node.active = false; } else { - // 视频 - this.switchButtons[2].getChildByName("share_img").active = true; - this.switchButtons[2].getChildByName("ad_img").active = false; + this.share_img.node.active = false; + + this.ad_img.node.active = true; } } start() { @@ -72,6 +78,7 @@ export default class NewClass extends cc.Component { return; } this.btn_Touch = false; + var self = this; //获取当前体力 // let curHeath = cc.fx.GameConfig.GM_INFO.hp; //获取当前金币 @@ -79,27 +86,30 @@ export default class NewClass extends cc.Component { // if (curCoin >= 1000) { // cc.fx.GameConfig.GM_INFO.hp = 1; // 测试时不通过微信分享使用 - var callback = function () { + var callback = function (isType) { //// 分享成功后才执行以下代码 - console.log("分享得体力"); - this.switchButtons[1].active = false; + if (isType == true) { + console.log("分享得体力"); + self.switchButtons[1].active = false; - cc.fx.GameConfig.GM_INFO.hp = 1; - cc.fx.GameConfig.GM_INFO.min_Time = 0; - // NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.hp, 40, 20, "month_", this.heatht, true); - const parentNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点 - if (parentNode) { - const jiazaiComp = parentNode.getComponent(JiaZai); - if (jiazaiComp) { - jiazaiComp.setHealthInfo(false); + cc.fx.GameConfig.GM_INFO.hp = 1; + // cc.fx.GameConfig.GM_INFO.min_Time = 0; + // NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.hp, 40, 20, "month_", this.heatht, true); + const parentNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点 + if (parentNode) { + const jiazaiComp = parentNode.getComponent(JiaZai); + if (jiazaiComp) { + jiazaiComp.setHealthInfo(false); + } } - } - this.switchButtons[0].active = true; - cc.fx.GameTool.setUserHealth(0, (data) => { - cc.fx.GameTool.getHealth(null); - }) + self.switchButtons[0].active = true; + cc.fx.GameTool.setUserHealth(0, (data) => { + cc.fx.GameTool.getHealth(null); + }) + + cc.fx.GameTool.addShareCount("health") + } - cc.fx.GameTool.addShareCount("health") } if (cc.fx.GameTool.canObtainByShare("health")) { diff --git a/assets/Script/module/Tool/GameTool.ts b/assets/Script/module/Tool/GameTool.ts index f83c3d0..d3d2a89 100644 --- a/assets/Script/module/Tool/GameTool.ts +++ b/assets/Script/module/Tool/GameTool.ts @@ -663,48 +663,50 @@ var GameTool = { //@ts-ignore if (typeof wx !== 'undefined' && wx !== null) { - var cb = function () { - let num = 1; //3 + var cb = function (isType) { + if (isType) { + let num = 1; //3 - if (propid == 2003) { - num = 1; // 3 - } - else if (propid == 2002) { - num = 1; - } - let _id = ""; - let propNumber = 0; - if (propid == 2001) { - _id = "freeze_in_game"; - cc.fx.GameConfig.GM_INFO.freezeAmount += num; - propNumber = cc.fx.GameConfig.GM_INFO.freezeAmount; - } - else if (propid == 2002) { - _id = "hammer_in_game"; - cc.fx.GameConfig.GM_INFO.hammerAmount += num; - propNumber = cc.fx.GameConfig.GM_INFO.hammerAmount; - } - else if (propid == 2003) { - _id = "wand_in_game"; - cc.fx.GameConfig.GM_INFO.magicAmount += num; - propNumber = cc.fx.GameConfig.GM_INFO.magicAmount; - } + if (propid == 2003) { + num = 1; // 3 + } + else if (propid == 2002) { + num = 1; + } + let _id = ""; + let propNumber = 0; + if (propid == 2001) { + _id = "freeze_in_game"; + cc.fx.GameConfig.GM_INFO.freezeAmount += num; + propNumber = cc.fx.GameConfig.GM_INFO.freezeAmount; + } + else if (propid == 2002) { + _id = "hammer_in_game"; + cc.fx.GameConfig.GM_INFO.hammerAmount += num; + propNumber = cc.fx.GameConfig.GM_INFO.hammerAmount; + } + else if (propid == 2003) { + _id = "wand_in_game"; + cc.fx.GameConfig.GM_INFO.magicAmount += num; + propNumber = cc.fx.GameConfig.GM_INFO.magicAmount; + } - //console.log("购买道具:", num); - cc.fx.GameTool.setUserProp(propid, propNumber, (data) => { - }) + //console.log("购买道具:", num); + cc.fx.GameTool.setUserProp(propid, propNumber, (data) => { + }) - const data = { - change_reason: "share", - id: propid, - num: num, - compensate: false + const data = { + change_reason: "share", + id: propid, + num: num, + compensate: false + } + cc.fx.GameTool.shushu_Track("resource_get", data); + if (propid == 2001) cc.fx.GameTool.addShareCount("freeze") + else if (propid == 2002) cc.fx.GameTool.addShareCount("hammer") + else if (propid == 2003) cc.fx.GameTool.addShareCount("magicWand") + callback(); } - cc.fx.GameTool.shushu_Track("resource_get", data); - if (propid == 2001) cc.fx.GameTool.addShareCount("freeze") - else if (propid == 2002) cc.fx.GameTool.addShareCount("hammer") - else if (propid == 2003) cc.fx.GameTool.addShareCount("magicWand") - callback(); } let video_data = { ad_placement_name: "", //内部广告位名称 @@ -1354,144 +1356,146 @@ var GameTool = { console.log("Share to WX"); // if (this._sharing) return; // this._sharing = true; - - let iphoneArr = [ - "https://mmocgame.qpic.cn/wechatgame/Lf3SBqy9XpNkakoIZygRzXqww3HTibq6VyibazqmicwibjCS3YpgqbZtkdyABm4Y1wAr/0", - "https://mmocgame.qpic.cn/wechatgame/TWKuFxnCn7ksT3KXfhCC4yOfZeD4b0hrptDSJ2DFmwz02Yc8SppcwyPAOoS1MsMr/0", - "https://mmocgame.qpic.cn/wechatgame/dibaH2x79o1wSwBDymhyzXwfcyicaDb6R5icrFIO7251T4NgxIzXRXErHvAvn50vXFA/0", - "https://mmocgame.qpic.cn/wechatgame/Pgxad80d8ws3o69OicV3DTuTkcP81upQeJ0JBNS1xib3pzYLTF1ZqGY3niciaI7ICKlL/0", - "https://mmocgame.qpic.cn/wechatgame/SfB1vrRBIHKn9ffKFt5sib62yPLE31m2rCvk6DKlEicJNVZSoryEObD6ItwsQn4xibR/0", - "https://mmocgame.qpic.cn/wechatgame/OiaWk33I6QjgWiatrb5YVUq2p0QRmQgO6rLUWxEQDZ4ib9Ny4Pr8iaHnHI6WdxibY2nPL/0", - "https://mmocgame.qpic.cn/wechatgame/CG5xBibollws251aYD4msEPWCiafrcn4Fgtic4T2wME6sWmdfAUtfibgsWoxm59VadDD/0" - ] - let randomIphone = iphoneArr[Math.floor(Math.random() * iphoneArr.length)]; - let img = randomIphone; - const shareParams = { - title: '如果你突然打了个喷嚏,那一定是我在等你帮忙过关!', // 分享标题 - imageUrl: img, // 分享图片链接 - }; - - let hideTime: number = 0; // 记录进入后台的时间 - let timer: any = null; // 定时器引用 - // 分享成功的处理函数 - const handleShareSuccess = () => { - // if (!this._sharing) return; // 已经回调过了 - // this._sharing = false; - - // 清除定时器 - if (timer) { - clearTimeout(timer); - timer = null; - } - - // 取消监听事件 - if (cc.sys.platform === cc.sys.WECHAT_GAME) { - //@ts-ignore - wx.offHide(hideListener); - //@ts-ignore - wx.offShow(showListener); - } - - console.log('分享成功'); - //@ts-ignore - wx.showToast({ - title: '分享成功', - icon: 'success', - duration: 2000 - }); - callback(true); // 回调表示分享成功 - }; - - // 分享失败的处理函数 - const handleShareFail = () => { - // if (!this._sharing) return; // 已经回调过了 - // this._sharing = false; - - // 清除定时器 - if (timer) { - clearTimeout(timer); - timer = null; - } - - // // 取消监听事件 - if (cc.sys.platform === cc.sys.WECHAT_GAME) { - //@ts-ignore - wx.offHide(hideListener); - //@ts-ignore - wx.offShow(showListener); - } - - console.log('分享失败'); - // callback(false); // 回调表示分享失败 - wx.showToast({ - title: '请分享给爱玩游戏的朋友,感谢!', - icon: 'none', - duration: 2000 - }); - }; - - if (cc.sys.platform === cc.sys.WECHAT_GAME) { - //@ts-ignore - wx.shareAppMessage(shareParams); - - // 进入后台的监听函数 - const hideListener = () => { - hideTime = Date.now(); // 记录进入后台的时间 - console.log("进入后台时间:", hideTime); + if (typeof wx !== 'undefined' && wx !== null) { + let iphoneArr = [ + "https://mmocgame.qpic.cn/wechatgame/Lf3SBqy9XpNkakoIZygRzXqww3HTibq6VyibazqmicwibjCS3YpgqbZtkdyABm4Y1wAr/0", + "https://mmocgame.qpic.cn/wechatgame/TWKuFxnCn7ksT3KXfhCC4yOfZeD4b0hrptDSJ2DFmwz02Yc8SppcwyPAOoS1MsMr/0", + "https://mmocgame.qpic.cn/wechatgame/dibaH2x79o1wSwBDymhyzXwfcyicaDb6R5icrFIO7251T4NgxIzXRXErHvAvn50vXFA/0", + "https://mmocgame.qpic.cn/wechatgame/Pgxad80d8ws3o69OicV3DTuTkcP81upQeJ0JBNS1xib3pzYLTF1ZqGY3niciaI7ICKlL/0", + "https://mmocgame.qpic.cn/wechatgame/SfB1vrRBIHKn9ffKFt5sib62yPLE31m2rCvk6DKlEicJNVZSoryEObD6ItwsQn4xibR/0", + "https://mmocgame.qpic.cn/wechatgame/OiaWk33I6QjgWiatrb5YVUq2p0QRmQgO6rLUWxEQDZ4ib9Ny4Pr8iaHnHI6WdxibY2nPL/0", + "https://mmocgame.qpic.cn/wechatgame/CG5xBibollws251aYD4msEPWCiafrcn4Fgtic4T2wME6sWmdfAUtfibgsWoxm59VadDD/0" + ] + let randomIphone = iphoneArr[Math.floor(Math.random() * iphoneArr.length)]; + let img = randomIphone; + const shareParams = { + title: '如果你突然打了个喷嚏,那一定是我在等你帮忙过关!', // 分享标题 + imageUrl: img, // 分享图片链接 }; - // 从后台返回的监听函数 - const showListener = () => { - if (hideTime > 0) { - const showTime = Date.now(); // 记录返回时间 - const duration = showTime - hideTime; // 计算后台停留时间 - console.log("从后台返回时间:", showTime, "停留时间:", duration, "毫秒"); + let hideTime: number = 0; // 记录进入后台的时间 + let timer: any = null; // 定时器引用 + // 分享成功的处理函数 + const handleShareSuccess = () => { + // if (!this._sharing) return; // 已经回调过了 + // this._sharing = false; - // 如果后台停留时间大于等于3秒,则认为分享成功 - if (duration >= 3000) { - handleShareSuccess(); + // 清除定时器 + if (timer) { + clearTimeout(timer); + timer = null; + } + + // 取消监听事件 + if (cc.sys.platform === cc.sys.WECHAT_GAME) { + //@ts-ignore + wx.offHide(hideListener); + //@ts-ignore + wx.offShow(showListener); + } + + console.log('分享成功'); + //@ts-ignore + wx.showToast({ + title: '分享成功', + icon: 'success', + duration: 2000 + }); + callback(true); // 回调表示分享成功 + }; + + // 分享失败的处理函数 + const handleShareFail = () => { + // if (!this._sharing) return; // 已经回调过了 + // this._sharing = false; + + // 清除定时器 + if (timer) { + clearTimeout(timer); + timer = null; + } + + // // 取消监听事件 + if (cc.sys.platform === cc.sys.WECHAT_GAME) { + //@ts-ignore + wx.offHide(hideListener); + //@ts-ignore + wx.offShow(showListener); + } + + console.log('分享失败'); + // callback(false); // 回调表示分享失败 + wx.showToast({ + title: '请分享给爱玩游戏的朋友,感谢!', + icon: 'none', + duration: 2000 + }); + }; + + if (cc.sys.platform === cc.sys.WECHAT_GAME) { + //@ts-ignore + wx.shareAppMessage(shareParams); + + // 进入后台的监听函数 + const hideListener = () => { + hideTime = Date.now(); // 记录进入后台的时间 + console.log("进入后台时间:", hideTime); + }; + + // 从后台返回的监听函数 + const showListener = () => { + if (hideTime > 0) { + const showTime = Date.now(); // 记录返回时间 + const duration = showTime - hideTime; // 计算后台停留时间 + console.log("从后台返回时间:", showTime, "停留时间:", duration, "毫秒"); + + // 如果后台停留时间大于等于3秒,则认为分享成功 + if (duration >= 3000) { + handleShareSuccess(); + } else { + // 停留时间不足3秒,认为分享失败 + handleShareFail(); + } } else { - // 停留时间不足3秒,认为分享失败 + // 没有记录到进入后台时间,认为分享失败 handleShareFail(); } - } else { - // 没有记录到进入后台时间,认为分享失败 + }; + + // 注册监听事件 + //@ts-ignore + wx.onHide(hideListener); + //@ts-ignore + wx.onShow(showListener); + } else { + // 非微信环境直接失败 + setTimeout(() => { handleShareFail(); - } - }; - - // 注册监听事件 - //@ts-ignore - wx.onHide(hideListener); - //@ts-ignore - wx.onShow(showListener); - } else { - // 非微信环境直接失败 - setTimeout(() => { - handleShareFail(); - }, 1000); + }, 1000); + } } - }, onShowVideo(callback: Function, videoData: any) { + console.log("调用视频广告"); if (typeof wx !== 'undefined' && wx !== null) { let scene = null; - const jiazaiNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点 - if (jiazaiNode) { - scene = jiazaiNode.getComponent(JiaZai); - if (scene) { - scene.openLoad(); + if (videoData.current_page == "HomeScene") { + const jiazaiNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点 + if (jiazaiNode) { + scene = jiazaiNode.getComponent(JiaZai); + if (scene) { + scene.openLoad(); + } } - } else { + } + else if (videoData.current_page == "GameScene") { const canvasTemp = cc.find("Canvas"); // 假设 Canvas 节点 if (canvasTemp) { scene = canvasTemp.getComponent("SceneManager"); if (scene) { scene.openLoad(); } - } else { - console.log("SceneManager 节点未找到"); } } let requestData = { @@ -1523,16 +1527,18 @@ var GameTool = { data.is_complete_play = true; MiniGameSdk.API.showToast('用户看完广告,可以奖励'); cc.fx.GameTool.shushu_Track("ad_close", data); - callback(); + callback(true); break; case MiniGameSdk.EAdVideoResult.REJECT: data.is_complete_play = false; MiniGameSdk.API.showToast('广告中断,未获得奖励'); cc.fx.GameTool.shushu_Track("ad_close", data); + callback(false); break; case MiniGameSdk.EAdVideoResult.ERROR: MiniGameSdk.API.showToast('广告加载失败,请稍后再试'); cc.fx.GameTool.shushu_Track("ad_close", data); + callback(false); break; default: // 其他情况,不作处理 @@ -1548,10 +1554,13 @@ var GameTool = { const today = new Date().toDateString(); const lastResetDate = cc.fx.StorageMessage.getStorage(`shareCountResetDate_${propType}`) || ""; + console.log("本地存储的分享时间", propType, today, lastResetDate) // 如果是新的一天,重置分享次数 if (today !== lastResetDate) { cc.fx.GameConfig.GM_INFO.dailyShareCounts[propType] = 0; cc.fx.StorageMessage.setStorage(`shareCountResetDate_${propType}`, today); + // 保存重置后的计数 + cc.fx.StorageMessage.setStorage(`dailyShareCounts${propType}`, 0); } else { // 从本地存储获取当前的分享次数 const storedShareCount = cc.fx.StorageMessage.getStorage(`dailyShareCounts${propType}`); @@ -1573,6 +1582,8 @@ var GameTool = { if (today !== lastResetDate) { cc.fx.GameConfig.GM_INFO.dailyShareCounts[propType] = 0; cc.fx.StorageMessage.setStorage(`shareCountResetDate_${propType}`, today); + // 保存重置后的计数 + cc.fx.StorageMessage.setStorage(`dailyShareCounts${propType}`, 0); } else { // 从本地存储获取当前的分享次数 const storedShareCount = cc.fx.StorageMessage.getStorage(`dailyShareCounts${propType}`); diff --git a/assets/prefab/pop/heathpop.prefab b/assets/prefab/pop/heathpop.prefab index 2f91a9b..32a78a9 100644 --- a/assets/prefab/pop/heathpop.prefab +++ b/assets/prefab/pop/heathpop.prefab @@ -1320,6 +1320,8 @@ "switchNode": null, "timeNode": null, "switchButtons": [], + "share_img": null, + "ad_img": null, "_id": "" }, { @@ -1724,7 +1726,7 @@ "__type__": "TypedArray", "ctor": "Float64Array", "array": [ - 0, + 5.417888360170764e-14, 8, 0, 0, @@ -1733,7 +1735,7 @@ 1, 1, 1, - 1 + 0 ] }, "_eulerAngles": { @@ -1791,7 +1793,7 @@ "asset": { "__id__": 0 }, - "fileId": "d1sq1BsQlHK4ffc6DVGC5U", + "fileId": "88fFBkhQxKxKtuG2Wlfzi1", "sync": false }, { @@ -1833,7 +1835,7 @@ "__type__": "TypedArray", "ctor": "Float64Array", "array": [ - 0, + 5.417888360170764e-14, 8, 0, 0, @@ -1842,7 +1844,7 @@ 1, 1, 1, - 1 + 0 ] }, "_eulerAngles": { @@ -1900,7 +1902,7 @@ "asset": { "__id__": 0 }, - "fileId": "dbVicLG/9Fp69/J1fbmuj1", + "fileId": "e31ZoJdZJEg68Z4aHcVNpL", "sync": false }, { @@ -2774,6 +2776,12 @@ "__id__": 42 } ], + "share_img": { + "__id__": 44 + }, + "ad_img": { + "__id__": 47 + }, "_id": "" }, {