59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import { _decorator, Component, Prefab } from 'cc';
|
||
import { ViewManager } from './scripts/core/ViewManager';
|
||
import { ToastManager } from './scripts/utils/ToastManager';
|
||
const { ccclass, property } = _decorator;
|
||
|
||
/**
|
||
* 主入口脚本
|
||
* 负责初始化 ViewManager 并注册页面
|
||
*/
|
||
@ccclass('main')
|
||
export class main extends Component {
|
||
@property({ type: Prefab, tooltip: '首页预制体' })
|
||
pageHomePrefab: Prefab | null = null;
|
||
|
||
@property({ type: Prefab, tooltip: '关卡页面预制体' })
|
||
pageLevelPrefab: Prefab | null = null;
|
||
|
||
@property({ type: Prefab, tooltip: 'Toast 预制体' })
|
||
toastPrefab: Prefab | null = null;
|
||
|
||
/**
|
||
* onLoad 比 start 更早执行
|
||
* 确保 ViewManager 在 PageLoading.start() 之前初始化
|
||
*/
|
||
onLoad() {
|
||
this._initViewManager();
|
||
}
|
||
|
||
/**
|
||
* 初始化页面管理器
|
||
*/
|
||
private _initViewManager(): void {
|
||
// 初始化 ViewManager,绑定 Canvas 作为页面容器
|
||
ViewManager.instance.init(this.node);
|
||
|
||
// 注册页面配置(通过编辑器属性引用预制体)
|
||
if (this.pageHomePrefab) {
|
||
ViewManager.instance.register('PageHome', {
|
||
prefab: this.pageHomePrefab,
|
||
cache: true,
|
||
zIndex: 0
|
||
});
|
||
}
|
||
|
||
if (this.pageLevelPrefab) {
|
||
ViewManager.instance.register('PageLevel', {
|
||
prefab: this.pageLevelPrefab,
|
||
cache: true,
|
||
zIndex: 1
|
||
});
|
||
}
|
||
|
||
// 初始化 Toast 管理器
|
||
if (this.toastPrefab) {
|
||
ToastManager.instance.init(this.toastPrefab, this.node);
|
||
}
|
||
}
|
||
}
|