import { _decorator, Button, Component, Label, Node, Sprite, Tween, tween, Vec3 } from 'cc'; import { LocalSaveMgr } from '../framework/data/LocalSaveMgr'; import { UIManager } from '../framework/ui/UIManager'; import { UISwitcher } from '../framework/ui/UISwitcher'; import { AudioMgr } from '../framework/audio/AudioMgr'; import { PanelBase } from '../framework/ui/PanelBase'; import { AssetController } from '../AssetController'; import { GameController } from '../GameController'; const { ccclass, property } = _decorator; @ccclass('LoadingPanel') export class LoadingPanel extends PanelBase { static instance: LoadingPanel; @property({ type: Sprite }) loadingSprite: Sprite = null; @property fillDuration: number = 5; // 填充持续时间,单位为秒 private fillAmount: number = 0; // 当前填充量 startFill() { this.schedule(this.updateFill, 0.01); // 每0.01秒更新一次填充量 } protected onOpen(): void { LoadingPanel.instance.startFill() } loadingComplete: boolean = false completeCallback = null onLoadingComplete(callBack) { this.completeCallback = callBack this.loadingComplete = true if (this.fillAmount < 1) { this.fillDuration = 1 } else { UIManager.instance.closePanel(LoadingPanel) callBack() } } protected onDestroy(): void { this.unschedule(this.updateFill); } updateFill() { if (this.fillAmount < 1) { this.fillAmount += 0.01 / this.fillDuration; // 根据持续时间逐步增加填充量 this.loadingSprite.fillRange = this.fillAmount; // 更新 Sprite 的填充量 } else { this.unschedule(this.updateFill); // 填充完成后停止更新 if (this.loadingComplete) { UIManager.instance.closePanel(LoadingPanel) this.completeCallback() } } } onLoad() { LoadingPanel.instance = this; } }