import { Widget, _decorator, Node, Sprite, Label, sys } from 'cc'; import { SkillType } from '../enum/SkillType'; import { SkillMgr } from '../manager/SkillMgr'; import { GameMgr } from '../manager/GameMgr'; import { UIBase } from '../scriptBase/UIBase'; import { CfgSkillInfo } from '../config/CfgSkillInfo'; import { ResMgr } from '../manager/ResMgr'; import { Bundle } from '../enum/Bundle'; import { AdMgr } from '../manager/AdMgr'; import { Debug } from "../util/Debug"; import { EventMgr } from '../manager/EventMgr'; import ATRewardedVideoSDK from "../AnyThinkAds/ATRewardedVideoTSSDK" import AAJS2 from "../utils/ATAndroidJS2"; import ATJSSDK from "../AnyThinkAds/ATJSSDK"; const Tag: string = 'zh:UIGetSkill'; const { ccclass, property, requireComponent } = _decorator; @ccclass('UI/UIGetSkill') @requireComponent(Widget) export class UIGetSkill extends UIBase { private icon: Sprite = null private lbTitle: Label = null private lbDesc: Label = null private skill: SkillType = null /** * 初始化广告 */ initAdForPage() { Debug.Log(Tag, 'initAdForPage foir UIGetSkill.ts') if (sys.os === sys.OS.ANDROID) { let deviceId = AAJS2.getDeviceUserId(); Debug.Log(Tag, 'checkAdStatus ='+ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId())); var setting = {}; setting[ATRewardedVideoSDK.userIdKey] = deviceId; ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting); } } protected onLoad(): void { this.icon = this.findComp('Icon', Sprite) this.lbTitle = this.findComp('LbTitle', Label) this.lbDesc = this.findComp('LbDesc', Label) this.initAdForPage() console.log('zh:uigetskill onload 注册事件 Ad_play_end s') EventMgr.on('Ad_play_end', this.defCode, this) console.log('zh:uigetskill onload 注册事件 Ad_play_end e') } /** * * @param event 是否看完了AD */ onCustomEvent(event) { // 处理自定义事件 const userData = event.getUserData(); console.log('zh: ad end Received custom event:', userData); } onDestroy() { // 注销自定义事件监听器 // this.node.off('custom-event', this.onCustomEvent, this); } public onOpen(data?: unknown): void { GameMgr.Pause = true this.skill = data as SkillType const skillInfo = CfgSkillInfo[this.skill] this.lbTitle.string = skillInfo.name this.lbDesc.string = skillInfo.desc this.icon.spriteFrame = ResMgr.getSpriteFrame(Bundle.Icon, skillInfo.icon) } public onClose(data?: unknown): void { GameMgr.Pause = false } protected onBtnGetClick(): void { Debug.Log(Tag, '点击了获取xxxx道具', this.skill) switch (this.skill) { case SkillType.DoubleCoin: Debug.Log(Tag, '星星') Debug.Log(Tag, SkillType.DoubleCoin) break; case SkillType.FreezeTime: Debug.Log(Tag, '冰冻时间') Debug.Log(Tag, SkillType.FreezeTime) break; case SkillType.RefreshPosition: Debug.Log(Tag, '转换') Debug.Log(Tag, SkillType.RefreshPosition) break; case SkillType.EraseGroup: Debug.Log(Tag, '灯泡') Debug.Log(Tag, SkillType.EraseGroup) break; default: Debug.Log(Tag, 'onBtnGetClick 未知skill。。。。') break; } if (sys.os == sys.OS.ANDROID) { if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) { Debug.Log(Tag, 'onBtnGetClick ad ok') sys.localStorage.setItem('yxAdMark', this.skill);//看广告用于 xx 标记 ATRewardedVideoSDK.showAd(AAJS2.getPlacementId()); // this.defcode(); //这里如果仔细测试就会发现一个BUG } else { Debug.Log(Tag, 'onBtnGetClick ad no ok') this.defCode(); } }else{ Debug.Log(Tag, 'onBtnGetClick H5直接发奖励') this.defCode(); } } /** * 默认代码,原有的逻辑 */ public defCode(): void { console.log('zh:uigetskill Ad_play_end go .....') AdMgr.showRewardedVideo(() => { SkillMgr.addSkill(this.skill) this.close() }) } }