MainUIControlller.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. // MainUIController.ts
  2. import { _decorator, Component, Node, Button, Label, JsonAsset, resources } from 'cc';
  3. import { SaveDataManager } from '../../LevelSystem/SaveDataManager';
  4. import { GameManager, AppState } from '../../LevelSystem/GameManager';
  5. import { GameState } from '../../LevelSystem/IN_game';
  6. import { GameStartMove } from '../../Animations/GameStartMove';
  7. import { TopBarController } from '../TopBarController';
  8. import { MoneyAni } from '../../Animations/MoneyAni';
  9. import EventBus, { GameEvents } from '../../Core/EventBus';
  10. import { Audio } from '../../AudioManager/AudioManager';
  11. import { BundleLoader } from '../../Core/BundleLoader';
  12. import { ResourcePreloader } from '../../Core/ResourcePreloader';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('MainUIController')
  15. export class MainUIController extends Component {
  16. /* 奖励节点 */
  17. @property(Node) rewardMoneyNode: Node = null; // 左钞票奖励
  18. @property(Node) rewardDiamondNode: Node = null; // 右钻石奖励
  19. @property(Label) levelNumberLabel: Label = null; // 第 X 关文本
  20. /* 升级 */
  21. @property(Button) upgradeBtn: Button = null; // 升级按钮
  22. @property(Node) upgradeCostLabel: Node = null; // 消耗钞票数字
  23. @property(Node) upgradeHpLabel: Node = null; // 升级后血量数字
  24. @property(Label) upgradeCurrentHpLabel: Label = null; // 当前血量Label
  25. @property(Label) upgradeNextHpLabel: Label = null; // 升级后血量Label
  26. @property(Label) upgradeInfoLabel: Label = null; // 升级信息Label(显示"升级墙壁"或"已满级")
  27. @property(Node) upgradeArrowNode: Node = null; // 箭头符号节点xxtb
  28. /* 墙体配置 */
  29. // @property(JsonAsset) wallConfigAsset: JsonAsset = null; // 墙体配置JSON资源 - 已改为动态加载
  30. /* 主功能按钮 */
  31. @property(Node) battleBtn: Node = null; // 战斗
  32. // 底栏按钮由 NavBarController 统一管理,这里不再需要引用
  33. @property(Node) topArea: Node = null; // Canvas-001/TopArea
  34. /* UI节点引用 - 替换find查找 */
  35. @property(Node) mainUI: Node = null; // Canvas/MainUI
  36. @property(Node) gameUI: Node = null; // Canvas/GameLevelUI
  37. @property(Node) gameManagerNode: Node = null; // Canvas/GameLevelUI/GameManager
  38. @property(Node) navBarNode: Node = null; // Canvas/NavBar
  39. @property(Node) topBarNode: Node = null; // Canvas/TopBar
  40. @property(Node) cameraNode: Node = null; // Canvas/Camera
  41. /* 奖励动画系统 */
  42. @property(Node) moneyAniNode: Node = null; // MoneyAni节点
  43. private sdm: SaveDataManager = null;
  44. private wallConfig: any = null;
  45. async onLoad () {
  46. console.log('[MainUIController] onLoad 开始执行');
  47. this.sdm = SaveDataManager.getInstance();
  48. await this.loadWallConfig();
  49. this.sdm.initialize();
  50. console.log('[MainUIController] SaveDataManager 初始化完成');
  51. this.bindButtons();
  52. this.refreshAll();
  53. // TopArea 默认隐藏,在点击战斗后再显示
  54. if (this.topArea) this.topArea.active = false;
  55. // 播放主界面背景音乐(等待bundle加载完成)
  56. await this.playMainUIBGM();
  57. // 预加载当前关卡和下一关的资源
  58. this.preloadLevelResources();
  59. console.log('[MainUIController] onLoad 执行完成');
  60. }
  61. /* 绑定按钮事件 */
  62. private bindButtons () {
  63. console.log('[MainUIController] bindButtons 开始执行');
  64. console.log('[MainUIController] upgradeBtn 状态:', this.upgradeBtn ? '已设置' : '未设置');
  65. console.log('[MainUIController] battleBtn 状态:', this.battleBtn ? '已设置' : '未设置');
  66. // 升级按钮绑定 - upgradeBtn是Button类型
  67. if (this.upgradeBtn) {
  68. console.log('[MainUIController] upgradeBtn.node:', this.upgradeBtn.node ? '存在' : '不存在');
  69. this.upgradeBtn.node.on(Button.EventType.CLICK, this.upgradeWallHp, this);
  70. console.log('[MainUIController] 升级按钮事件已绑定');
  71. } else {
  72. console.error('[MainUIController] upgradeBtn未设置,无法绑定升级事件');
  73. }
  74. // 战斗按钮绑定 - battleBtn是Node类型
  75. if (this.battleBtn) {
  76. this.battleBtn.on(Button.EventType.CLICK, this.onBattle, this);
  77. console.log('[MainUIController] 战斗按钮事件已绑定');
  78. } else {
  79. console.error('[MainUIController] battleBtn未设置,无法绑定战斗事件');
  80. }
  81. console.log('[MainUIController] bindButtons 执行完成');
  82. }
  83. /* ================= 配置加载 ================= */
  84. /**
  85. * 加载墙体配置
  86. */
  87. private async loadWallConfig(): Promise<void> {
  88. try {
  89. const bundleLoader = BundleLoader.getInstance();
  90. const wallData = await bundleLoader.loadDataJson('wall');
  91. if (!wallData) {
  92. console.error('[MainUIController] 墙体配置文件内容为空');
  93. return;
  94. }
  95. this.wallConfig = wallData.json;
  96. console.log('[MainUIController] 墙体配置加载成功:', this.wallConfig);
  97. // 将配置传递给SaveDataManager
  98. this.sdm.setWallConfig(this.wallConfig);
  99. } catch (error) {
  100. console.error('[MainUIController] 加载墙体配置失败:', error);
  101. }
  102. }
  103. /**
  104. * 获取墙体升级费用
  105. */
  106. private getWallUpgradeCost(level: number): number {
  107. if (this.wallConfig && this.wallConfig.wallConfig && this.wallConfig.wallConfig.upgradeCosts) {
  108. const costs = this.wallConfig.wallConfig.upgradeCosts;
  109. return costs[level.toString()] || 0;
  110. }
  111. return 0;
  112. }
  113. /**
  114. * 获取墙体血量
  115. */
  116. private getWallHealthByLevel(level: number): number {
  117. if (this.wallConfig && this.wallConfig.wallConfig && this.wallConfig.wallConfig.healthByLevel) {
  118. const healthByLevel = this.wallConfig.wallConfig.healthByLevel;
  119. return healthByLevel[level.toString()] || 100;
  120. }
  121. return 100;
  122. }
  123. /**
  124. * 获取墙体最大等级
  125. */
  126. private getWallMaxLevel(): number {
  127. if (this.wallConfig && this.wallConfig.wallConfig && this.wallConfig.wallConfig.maxLevel) {
  128. return this.wallConfig.wallConfig.maxLevel;
  129. }
  130. return 5;
  131. }
  132. /* ================= 业务逻辑 ================= */
  133. private upgradeWallHp () {
  134. // 播放UI点击音效
  135. Audio.playUISound('data/弹球音效/level up 2');
  136. console.log('[MainUIController] 升级墙体按钮被点击');
  137. // 检查SaveDataManager是否初始化
  138. if (!this.sdm) {
  139. console.error('[MainUIController] SaveDataManager未初始化');
  140. return;
  141. }
  142. // 打印当前状态用于调试
  143. const currentMoney = this.sdm.getMoney();
  144. const currentWallLevel = this.sdm.getWallLevel();
  145. const upgradeCost = this.getWallUpgradeCost(currentWallLevel);
  146. console.log(`[MainUIController] 当前状态: 钞票=${currentMoney}, 墙体等级=${currentWallLevel}, 升级费用=${upgradeCost}`);
  147. // 检查墙体等级是否已达到最大值
  148. const maxLevel = this.getWallMaxLevel();
  149. if (currentWallLevel >= maxLevel) {
  150. console.log('[MainUIController] 墙体已达到最大等级');
  151. EventBus.getInstance().emit(GameEvents.SHOW_TOAST, {
  152. message: '墙体已达到最大等级',
  153. duration: 2.0
  154. });
  155. return;
  156. }
  157. // 检查钞票是否足够
  158. if (currentMoney < upgradeCost) {
  159. EventBus.getInstance().emit(GameEvents.SHOW_RESOURCE_TOAST, {
  160. message: `钞票不足,需要${upgradeCost}钞票`,
  161. duration: 2.0
  162. });
  163. return;
  164. }
  165. // 执行升级
  166. if (!this.sdm.spendMoney(upgradeCost)) {
  167. console.log('[MainUIController] 扣除钞票失败');
  168. return;
  169. }
  170. if (!this.sdm.upgradeWallLevel()) {
  171. console.log('[MainUIController] 墙体升级失败');
  172. return;
  173. }
  174. console.log('[MainUIController] 墙体升级成功');
  175. // 刷新所有UI显示
  176. this.refreshAll();
  177. // 通过事件系统通知UI更新
  178. EventBus.getInstance().emit(GameEvents.CURRENCY_CHANGED);
  179. // 通知墙体组件更新血量显示
  180. const newLevel = this.sdm.getWallLevel();
  181. const newHealth = this.getWallHealthByLevel(newLevel);
  182. EventBus.getInstance().emit(GameEvents.WALL_HEALTH_CHANGED, {
  183. previousHealth: 0,
  184. currentHealth: newHealth,
  185. maxHealth: newHealth
  186. });
  187. }
  188. private onBattle () {
  189. // 停止主界面背景音乐,避免与游戏内音效冲突
  190. Audio.stopMusic();
  191. // 播放战斗背景音乐,音量较小
  192. setTimeout(() => {
  193. Audio.playMusic('data/弹球音效/fight bgm', true);
  194. Audio.setMusicVolume(0.4); // 设置较小的音量
  195. console.log('[MainUIController] 开始播放战斗背景音乐');
  196. }, 500); // 延迟500ms等start zombie音效播放
  197. // 显示 TopArea(拖拽引用),避免使用 find()
  198. if (this.topArea) this.topArea.active = true;
  199. // 若上一关已完成则自动+1
  200. const lvl = this.sdm.getCurrentLevel();
  201. if (this.sdm.isLevelCompleted(lvl)) {
  202. const pd = this.sdm.getPlayerData();
  203. pd.currentLevel = lvl + 1;
  204. this.sdm.savePlayerData();
  205. }
  206. this.refreshLevelNumber();
  207. // 切场景 UI - 使用装饰器引用
  208. if (this.mainUI) this.mainUI.active = false;
  209. if (this.gameUI) this.gameUI.active = true;
  210. const gm = this.gameManagerNode?.getComponent(GameManager);
  211. // 设置应用状态为游戏中(会自动隐藏TopBar和NavBar)
  212. gm?.setAppState(AppState.IN_GAME);
  213. // 统一使用StartGame启动游戏流程
  214. const eventBus = EventBus.getInstance();
  215. eventBus.emit(GameEvents.GAME_START);
  216. gm?.loadCurrentLevelConfig();
  217. // 镜头下移动画现在已集成到StartGame流程中的slideUpFromBottom方法里
  218. }
  219. /* ================= 刷新 ================= */
  220. private refreshLevelNumber(){
  221. if (this.levelNumberLabel) this.levelNumberLabel.string = `第 ${this.sdm.getCurrentLevel()} 关`;
  222. }
  223. private refreshAll(){
  224. this.refreshLevelNumber();
  225. this.refreshUpgradeInfo();
  226. this.refreshRewardDisplay();
  227. }
  228. /** 刷新奖励显示 - 从JSON配置读取 */
  229. private async refreshRewardDisplay() {
  230. const currentLevel = this.sdm.getCurrentLevel();
  231. try {
  232. // 从SaveDataManager获取关卡奖励配置
  233. const rewards = await this.sdm.getLevelRewardsFromConfig(currentLevel);
  234. if (rewards) {
  235. // 更新钞票奖励显示
  236. if (this.rewardMoneyNode) {
  237. const coinLabel = this.rewardMoneyNode.getComponent(Label) || this.rewardMoneyNode.getComponentInChildren(Label);
  238. if (coinLabel) {
  239. coinLabel.string = rewards.money.toString();
  240. }
  241. }
  242. // 更新钻石奖励显示
  243. if (this.rewardDiamondNode) {
  244. const diamondLabel = this.rewardDiamondNode.getComponent(Label) || this.rewardDiamondNode.getComponentInChildren(Label);
  245. if (diamondLabel) {
  246. diamondLabel.string = rewards.diamonds.toString();
  247. }
  248. }
  249. } else {
  250. console.warn(`无法获取关卡${currentLevel}的奖励配置,使用默认值`);
  251. // 使用默认奖励值
  252. this.setDefaultRewards();
  253. }
  254. } catch (error) {
  255. console.error('刷新奖励显示时出错:', error);
  256. this.setDefaultRewards();
  257. }
  258. }
  259. /** 设置默认奖励值 */
  260. private setDefaultRewards() {
  261. // 钞票奖励默认值
  262. if (this.rewardMoneyNode) {
  263. const coinLabel = this.rewardMoneyNode.getComponent(Label) || this.rewardMoneyNode.getComponentInChildren(Label);
  264. if (coinLabel) {
  265. coinLabel.string = '50';
  266. }
  267. }
  268. // 钻石奖励默认值
  269. if (this.rewardDiamondNode) {
  270. const diamondLabel = this.rewardDiamondNode.getComponent(Label) || this.rewardDiamondNode.getComponentInChildren(Label);
  271. if (diamondLabel) {
  272. diamondLabel.string = '5';
  273. }
  274. }
  275. }
  276. /** 刷新升级信息显示 */
  277. private refreshUpgradeInfo () {
  278. console.log('[MainUIController] refreshUpgradeInfo 开始执行');
  279. const costLbl = this.upgradeCostLabel?.getComponent(Label);
  280. const hpLbl = this.upgradeHpLabel?.getComponent(Label);
  281. const currentLevel = this.sdm.getWallLevel();
  282. const maxLevel = this.getWallMaxLevel();
  283. // 检查是否已达到最大等级
  284. if (currentLevel >= maxLevel) {
  285. // 满级状态:显示"已满级",隐藏当前血量和箭头,只显示满级血量
  286. if (this.upgradeInfoLabel) {
  287. this.upgradeInfoLabel.string = "已满级";
  288. }
  289. // 隐藏当前血量Label和箭头符号
  290. if (this.upgradeCurrentHpLabel) {
  291. this.upgradeCurrentHpLabel.node.active = false;
  292. }
  293. if (this.upgradeArrowNode) {
  294. this.upgradeArrowNode.active = false;
  295. }
  296. // 只显示满级血量
  297. if (this.upgradeNextHpLabel) {
  298. const maxHp = this.getWallHealthByLevel(currentLevel);
  299. this.upgradeNextHpLabel.string = `${maxHp}`;
  300. this.upgradeNextHpLabel.node.active = true;
  301. }
  302. // 隐藏升级费用
  303. if (costLbl) {
  304. costLbl.string = "";
  305. }
  306. console.log(`[MainUIController] 满级状态显示: 等级=${currentLevel}, 血量=${this.getWallHealthByLevel(currentLevel)}`);
  307. } else {
  308. // 非满级状态:正常显示升级信息
  309. if (this.upgradeInfoLabel) {
  310. this.upgradeInfoLabel.string = "升级墙壁";
  311. }
  312. // 显示升级费用
  313. const cost = this.getWallUpgradeCost(currentLevel);
  314. if (costLbl) {
  315. costLbl.string = cost.toString();
  316. console.log(`[MainUIController] 升级费用: ${cost}`);
  317. }
  318. // 显示当前和下一级血量
  319. const currentHp = this.getWallHealthByLevel(currentLevel);
  320. const nextHp = this.getWallHealthByLevel(currentLevel + 1);
  321. // 显示当前血量Label和箭头符号
  322. if (this.upgradeCurrentHpLabel) {
  323. this.upgradeCurrentHpLabel.string = `${currentHp}>>`;
  324. this.upgradeCurrentHpLabel.node.active = true;
  325. }
  326. if (this.upgradeArrowNode) {
  327. this.upgradeArrowNode.active = true;
  328. }
  329. // 显示升级后血量
  330. if (this.upgradeNextHpLabel) {
  331. this.upgradeNextHpLabel.string = `${nextHp}`;
  332. this.upgradeNextHpLabel.node.active = true;
  333. }
  334. console.log(`[MainUIController] 升级信息显示: 当前=${currentHp}, 升级后=${nextHp}, 当前等级: ${currentLevel}`);
  335. }
  336. // 升级按钮始终保持可点击状态,通过Toast显示各种提示
  337. console.log(`[MainUIController] 升级按钮保持可交互状态`);
  338. }
  339. // 供外部(如 GameManager)调用的公共刷新接口
  340. public updateUI (): void {
  341. this.refreshAll();
  342. // 通过事件系统通知UI更新
  343. EventBus.getInstance().emit(GameEvents.CURRENCY_CHANGED);
  344. }
  345. /**
  346. * 游戏失败或成功返回MainUI后的UI状态管理
  347. * 隐藏Canvas-001并显示Canvas/TopBar和Canvas/NavBar
  348. */
  349. public onReturnToMainUI(): void {
  350. console.log('MainUIController.onReturnToMainUI 开始执行');
  351. // 注意:应用状态已在GameManager中设置,这里不需要重复设置
  352. // 隐藏 TopArea (Canvas-001)
  353. if (this.topArea) {
  354. this.topArea.active = false;
  355. console.log('TopArea (Canvas-001) 已隐藏');
  356. }
  357. // 显示主UI
  358. if (this.mainUI) {
  359. this.mainUI.active = true;
  360. console.log('MainUI 已显示');
  361. }
  362. // 隐藏游戏UI
  363. if (this.gameUI) {
  364. this.gameUI.active = false;
  365. console.log('GameUI 已隐藏');
  366. }
  367. // 显示顶部钱币栏 TopBar
  368. if (this.topBarNode) {
  369. this.topBarNode.active = true;
  370. console.log('TopBar 已显示');
  371. }
  372. // 显示底部导航栏 NavBar
  373. if (this.navBarNode) {
  374. this.navBarNode.active = true;
  375. console.log('NavBar 已显示');
  376. }
  377. // 播放主界面背景音乐
  378. this.playMainUIBGM();
  379. // 刷新UI显示
  380. this.refreshAll();
  381. // 通过事件系统通知UI更新
  382. EventBus.getInstance().emit(GameEvents.CURRENCY_CHANGED);
  383. // 返回主界面时重新预加载资源,确保下次进入游戏时资源已准备就绪
  384. this.preloadLevelResources();
  385. console.log('MainUIController.onReturnToMainUI 执行完成');
  386. }
  387. /**
  388. * 游戏成功返回MainUI并播放奖励动画
  389. */
  390. public onReturnToMainUIWithReward(): void {
  391. console.log('MainUIController.onReturnToMainUIWithReward 开始执行');
  392. // 先执行基本的UI状态管理
  393. this.onReturnToMainUI();
  394. // 延迟播放奖励动画,确保UI已经完全显示
  395. this.scheduleOnce(() => {
  396. this.playRewardAnimation();
  397. }, 0.5);
  398. }
  399. /**
  400. * 播放奖励动画
  401. */
  402. private async playRewardAnimation(): Promise<void> {
  403. console.log('MainUIController.playRewardAnimation 开始播放奖励动画');
  404. const currentLevel = this.sdm.getCurrentLevel();
  405. try {
  406. // 直接获取SaveDataManager中已经计算好的奖励数据
  407. // 注意:不再依赖当前游戏状态判断,因为游戏数据清理可能已经重置了状态
  408. // SaveDataManager.getLastRewards()已经包含了正确的奖励信息(成功或失败奖励)
  409. const rewards = this.sdm.getLastRewards();
  410. console.log('获取已计算的奖励:', rewards);
  411. if (rewards && (rewards.money > 0 || rewards.diamonds > 0)) {
  412. // 使用MoneyAni播放奖励动画
  413. if (this.moneyAniNode) {
  414. const moneyAni = this.moneyAniNode.getComponent(MoneyAni);
  415. if (moneyAni) {
  416. moneyAni.playRewardAnimation(rewards.money, rewards.diamonds, () => {
  417. console.log('奖励动画播放完成');
  418. });
  419. } else {
  420. console.error('MoneyAni组件未找到');
  421. // 使用静态方法作为备选
  422. MoneyAni.playReward(rewards.money, rewards.diamonds);
  423. }
  424. } else {
  425. console.warn('MoneyAni节点未设置,使用静态方法播放动画');
  426. MoneyAni.playReward(rewards.money, rewards.diamonds);
  427. }
  428. } else {
  429. console.log('当前关卡没有奖励或奖励为0,跳过动画播放');
  430. }
  431. } catch (error) {
  432. console.error('播放奖励动画时出错:', error);
  433. // 使用默认奖励
  434. MoneyAni.playReward(25, 2);
  435. }
  436. }
  437. /**
  438. * 播放主界面背景音乐
  439. */
  440. private async playMainUIBGM(): Promise<void> {
  441. console.log('[MainUIController] 开始播放主界面背景音乐');
  442. try {
  443. // 获取BundleLoader实例
  444. const bundleLoader = BundleLoader.getInstance();
  445. // 确保data bundle已加载完成
  446. await bundleLoader.loadBundle('data');
  447. console.log('[MainUIController] data bundle加载完成,开始播放音乐');
  448. // 先停止当前音乐(包括战斗背景音乐)
  449. Audio.stopMusic();
  450. // 恢复正常音乐音量
  451. Audio.setMusicVolume(0.8);
  452. // 播放主界面BGM,循环播放
  453. Audio.playMusic('data/弹球音效/ui bgm', true);
  454. console.log('[MainUIController] 主界面背景音乐播放完成');
  455. } catch (error) {
  456. console.error('[MainUIController] 播放主界面背景音乐失败:', error);
  457. }
  458. }
  459. /**
  460. * 预加载当前关卡和下一关的资源
  461. * 在MainUI场景加载时提前预加载,避免进入游戏时的资源加载延迟
  462. */
  463. private async preloadLevelResources(): Promise<void> {
  464. console.log('[MainUIController] 开始预加载关卡资源');
  465. try {
  466. const resourcePreloader = ResourcePreloader.getInstance();
  467. const currentLevel = this.sdm.getCurrentLevel();
  468. // 预加载当前关卡资源
  469. console.log(`[MainUIController] 预加载当前关卡 ${currentLevel} 的资源`);
  470. try {
  471. await resourcePreloader.preloadLevelResources(currentLevel);
  472. console.log(`[MainUIController] 当前关卡 ${currentLevel} 资源预加载完成`);
  473. } catch (error) {
  474. console.warn(`[MainUIController] 当前关卡 ${currentLevel} 资源预加载失败:`, error);
  475. }
  476. // 预加载下一关资源(如果存在)
  477. const nextLevel = currentLevel + 1;
  478. console.log(`[MainUIController] 预加载下一关卡 ${nextLevel} 的资源`);
  479. try {
  480. await resourcePreloader.preloadLevelResources(nextLevel);
  481. console.log(`[MainUIController] 下一关卡 ${nextLevel} 资源预加载完成`);
  482. } catch (error) {
  483. console.warn(`[MainUIController] 下一关卡 ${nextLevel} 资源预加载失败(可能不存在该关卡):`, error);
  484. }
  485. console.log('[MainUIController] 关卡资源预加载流程完成');
  486. } catch (error) {
  487. console.error('[MainUIController] 预加载关卡资源时发生错误:', error);
  488. }
  489. }
  490. /* =============== Util =============== */
  491. private format(n:number){ return n>=1000000? (n/1e6).toFixed(1)+'M' : n>=1000? (n/1e3).toFixed(1)+'K' : n.toString(); }
  492. }