Files
mp-xieyingeng/assets/main.ts
richarjiang 0bda6904fa feat: 添加微信SDK和关卡页面,重构预制体结构
- 新增 WxSDK 微信SDK工具类
- 新增 PageLevel 关卡选择页面组件
- 将 prefabs 目录从 resources 移至根目录
- 更新 ViewManager 支持预制体属性引用
- 添加 BaseView 页面基类

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 10:35:21 +08:00

50 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { _decorator, Component, Prefab } from 'cc';
import { ViewManager } from './scripts/core/ViewManager';
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;
/**
* 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
});
}
}
}