82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
import { _decorator, Component } from 'cc';
|
|
import { AppStatusManager } from '../App/AppStatus/AppStatusManager';
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/**
|
|
* Boot启动组件
|
|
*
|
|
* 使用方法:
|
|
* 1. 在Cocos Creator中打开主场景(main.scene)
|
|
* 2. 创建一个空节点,命名为 "Boot"
|
|
* 3. 将此脚本挂载到Boot节点上
|
|
* 4. 运行游戏,应用将自动启动
|
|
*
|
|
* 职责:
|
|
* - 作为整个应用的入口点
|
|
* - 初始化AppStatusManager
|
|
* - 启动应用状态流转
|
|
* - 在每帧更新状态机
|
|
*/
|
|
@ccclass('Boot')
|
|
export class Boot extends Component {
|
|
private _appStatusManager: AppStatusManager | null = null;
|
|
|
|
/**
|
|
* 组件首次激活时调用
|
|
*/
|
|
start() {
|
|
console.log("=================================");
|
|
console.log(" Cocos3.x Roguelike Game");
|
|
console.log(" Boot Component Started");
|
|
console.log("=================================");
|
|
|
|
// 初始化并启动应用
|
|
this.initApp();
|
|
}
|
|
|
|
/**
|
|
* 初始化应用
|
|
*/
|
|
private initApp(): void {
|
|
console.log("[Boot] 初始化应用...");
|
|
|
|
try {
|
|
// 1. 获取AppStatusManager单例
|
|
this._appStatusManager = AppStatusManager.getInstance();
|
|
|
|
// 2. 启动应用(从Boot状态开始)
|
|
this._appStatusManager.start();
|
|
|
|
console.log("[Boot] 应用启动成功");
|
|
|
|
} catch (error) {
|
|
console.error("[Boot] 应用启动失败:", error);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 每帧更新
|
|
* @param deltaTime 距离上一帧的时间增量(秒)
|
|
*/
|
|
update(deltaTime: number) {
|
|
// 更新应用状态机
|
|
if (this._appStatusManager) {
|
|
this._appStatusManager.update(deltaTime);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 组件销毁时调用
|
|
*/
|
|
onDestroy() {
|
|
console.log("[Boot] 组件销毁");
|
|
|
|
// 销毁应用状态管理器
|
|
if (this._appStatusManager) {
|
|
this._appStatusManager.destroy();
|
|
this._appStatusManager = null;
|
|
}
|
|
}
|
|
}
|