feat: 提交资源
This commit is contained in:
79
assets/scripts/HotupdateLoading.ts
Normal file
79
assets/scripts/HotupdateLoading.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import { _decorator, Component, Label, ProgressBar } from "cc";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("HotupdateLoading")
|
||||
export class HotupdateLoading extends Component {
|
||||
@property(Label)
|
||||
label: Label = null;
|
||||
|
||||
@property(ProgressBar)
|
||||
progressBar: ProgressBar = null;
|
||||
|
||||
/** 动画定时器ID */
|
||||
private animationTimer: NodeJS.Timeout | null = null;
|
||||
/** 当前动画状态 */
|
||||
private animationState: number = 0;
|
||||
/** 动画基础文本 */
|
||||
private baseText: string = "";
|
||||
|
||||
protected onDestroy() {
|
||||
this.stopTextAnimation();
|
||||
}
|
||||
|
||||
public updateProgress(current: number, total: number) {
|
||||
this.progressBar.progress = current / total;
|
||||
this.progressBar.node.active = true;
|
||||
this.label.string = `正在更新中 ${current}/${total}`;
|
||||
}
|
||||
|
||||
public updateProgressText(text: string, enableAnimation: boolean = false) {
|
||||
this.stopTextAnimation();
|
||||
|
||||
if (enableAnimation) {
|
||||
this.startTextAnimation(text);
|
||||
} else {
|
||||
this.label.string = text;
|
||||
}
|
||||
|
||||
this.progressBar.node.active = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始文本动画
|
||||
* @param baseText 基础文本,如"加载中"
|
||||
* @param interval 动画间隔时间,默认500毫秒
|
||||
*/
|
||||
public startTextAnimation(baseText: string, interval: number = 500) {
|
||||
this.stopTextAnimation();
|
||||
this.baseText = baseText;
|
||||
this.animationState = 0;
|
||||
|
||||
// 立即显示第一帧
|
||||
this.updateAnimationText();
|
||||
|
||||
// 启动定时器
|
||||
this.animationTimer = setInterval(() => {
|
||||
this.animationState = (this.animationState + 1) % 4; // 0,1,2,3 循环
|
||||
this.updateAnimationText();
|
||||
}, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止文本动画
|
||||
*/
|
||||
public stopTextAnimation() {
|
||||
if (this.animationTimer !== null) {
|
||||
clearInterval(this.animationTimer);
|
||||
this.animationTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新动画文本显示
|
||||
*/
|
||||
private updateAnimationText() {
|
||||
const dots = ".".repeat(this.animationState);
|
||||
this.label.string = this.baseText + dots;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user