import { Widget, _decorator, Node, tween, v3, Label, Vec2, v2, math, Tween,sys } from 'cc'; import { GameMgr } from '../manager/GameMgr'; import { AudioMgr } from '../manager/AudioMgr'; import { CoinMgr } from '../manager/CoinMgr'; import { ArrayUtil } from '../util/ArrayUtil'; import { InputBlock } from '../misc/InputBlock'; import { TimeMgr } from '../manager/TimeMgr'; import { UI } from '../enum/UI'; import { UIBase } from '../scriptBase/UIBase'; import { CoinItem } from '../uiItem/CoinItem'; import { Global } from '../Global'; import { TransMgr } from '../manager/TransMgr'; import { BYTEDANCE } from 'cc/env'; import { ModeName } from '../enum/Mode'; import { AdMgr } from '../manager/AdMgr'; import { Debug } from "../util/Debug"; const Tag: string = 'zh:UIWin'; import ATRewardedVideoSDK from "../AnyThinkAds/ATRewardedVideoTSSDK" import AAJS2 from "../utils/ATAndroidJS2"; import ATJSSDK from "../AnyThinkAds/ATJSSDK"; const { ccclass, property, requireComponent } = _decorator; @ccclass('UI/UIWin') @requireComponent(Widget) export class UIWin extends UIBase { private pointer: Node = null private lbCoin: Label = null private coinItem: CoinItem = null private coin: number = 0 public set Coin(v: number) { this.coin = Math.max(v, 0) this.lbCoin.string = `x${this.coin}` } private multi: number = 1 private readonly posArr: Vec2[] = [ v2(-120, -74), v2(-72, 80), v2(-17, 29), v2(32, 86), v2(90, 120), ] private readonly multiArr: number[] = [2, 3, 5, 3, 4] private tw: Tween = null protected onLoad(): void { this.pointer = this.findNode('Pointer') this.lbCoin = this.findComp('LbCoin', Label) this.coinItem = this.findComp('CoinItem', CoinItem) this.initAdForPage(); } /** * 初始化广告 */ 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); } } public onOpen(data?: unknown): void { AudioMgr.stopBgm() AudioMgr.playSfx('通关成功') GameMgr.passGame() this.coinItem.init(CoinMgr.CurCoin) GameMgr.Pause = true const duration: number = 0.75 this.tw = tween(this.pointer).sequence( tween(this.pointer).to(duration, { position: v3(120, -25) }), tween(this.pointer).to(duration, { position: v3(-120, -25) }) ).repeatForever().start() this.Coin = Global.Normal_Level_Coin_Default_Cnt + (GameMgr.CurLevel - 1) * Global.Normal_Level_Coin_Add_Cnt CoinMgr.CurCoin += this.coin } public onClose(data?: unknown): void { GameMgr.Pause = false InputBlock.Active = false } protected async onBtnMultiClick() { console.log('zh:点击了多倍奖励s') const onSucc = async () => { Debug.Log(Tag, 'onSucc 111') this.tw.stop() const idx: number = ArrayUtil.pickItem([0, 0, 0, 0, 0, 1, 2, 3]) this.multi = this.multiArr[idx] const posRange: Vec2 = this.posArr[idx] const posX: number = math.randomRangeInt(posRange.x, posRange.y) this.pointer.setPosition(posX, this.pointer.position.y) const extraCoin: number = (this.multi - 1) * this.coin this.Coin = this.multi * this.coin CoinMgr.CurCoin += extraCoin this.coinItem.updateCoin(CoinMgr.CurCoin) Debug.Log(Tag, 'onSucc 222') InputBlock.Active = true await TimeMgr.delay(2) await TransMgr.Inst.fadeIn() GameMgr.startGame() this.close() TransMgr.Inst.fadeOut() Debug.Log(Tag, 'onSucc 333') } console.log('zh:点击了多倍奖励e'); if (sys.os == sys.OS.ANDROID) { if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) { Debug.Log(Tag, 'onBtnGetClick ad ok') sys.localStorage.setItem('yxAdMark', 'duoBeiGetXingXing');//看广告用于 多倍星星 ATRewardedVideoSDK.showAd(AAJS2.getPlacementId()); // onSucc(); AdMgr.showRewardedVideo(onSucc) } else { Debug.Log(Tag, 'onBtnGetClick ad no ok') AdMgr.showRewardedVideo(onSucc) } } //下面是原有的逻辑 // AdMgr.showRewardedVideo(onSucc) // console.log('zh:点击了多倍奖励e2'); } protected async onBtnNextClick() { this.coinItem.updateCoin(CoinMgr.CurCoin) InputBlock.Active = true await TimeMgr.delay(2) await TransMgr.Inst.fadeIn() GameMgr.startGame() this.close() TransMgr.Inst.fadeOut() } protected async onBtnCloseClick() { await TransMgr.Inst.fadeIn() this.close() GameMgr.quitGame() this.open(UI.Main) TransMgr.Inst.fadeOut() } }