- 实现 ViewManager 单例页面管理器,支持页面注册、打开、关闭、缓存 - 实现 BaseView 页面基类,提供统一的页面生命周期 - 添加 PageHome 首页,包含开始游戏按钮跳转功能 - 添加 PageLevel 关卡页面,继承 BaseView - 更新 PageLoading 支持进度条显示和页面预加载 - 添加相关图片资源和预制体 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
63 lines
1.4 KiB
TypeScript
63 lines
1.4 KiB
TypeScript
import { _decorator, Component, ProgressBar } from 'cc';
|
|
import { ViewManager } from './scripts/core/ViewManager';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/**
|
|
* 页面加载组件
|
|
* 负责预加载资源并显示加载进度
|
|
*/
|
|
@ccclass('PageLoading')
|
|
export class PageLoading extends Component {
|
|
@property(ProgressBar)
|
|
progressBar: ProgressBar | null = null;
|
|
|
|
start() {
|
|
this._startPreload();
|
|
}
|
|
|
|
/**
|
|
* 开始预加载
|
|
*/
|
|
private _startPreload(): void {
|
|
// 初始化进度条
|
|
if (this.progressBar) {
|
|
this.progressBar.progress = 0;
|
|
}
|
|
|
|
// 预加载 PageHome
|
|
ViewManager.instance.preload('PageHome',
|
|
(progress) => {
|
|
this._updateProgress(progress);
|
|
},
|
|
() => {
|
|
this._onPreloadComplete();
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 更新进度条
|
|
*/
|
|
private _updateProgress(progress: number): void {
|
|
if (this.progressBar) {
|
|
this.progressBar.progress = progress;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 预加载完成回调
|
|
*/
|
|
private _onPreloadComplete(): void {
|
|
// 确保进度条显示完成
|
|
this._updateProgress(1);
|
|
|
|
// 打开 PageHome
|
|
ViewManager.instance.open('PageHome', {
|
|
onComplete: () => {
|
|
// PageHome 打开成功后,销毁自身
|
|
this.node.destroy();
|
|
}
|
|
});
|
|
}
|
|
}
|