Browse Source

还剩下镜头上移和关闭结束UI

181404010226 4 months ago
parent
commit
1e7d9c6651
2 changed files with 85 additions and 0 deletions
  1. 7 0
      assets/scripts/LevelSystem/GameManager.ts
  2. 78 0
      assets/scripts/LevelSystem/IN_game.ts

+ 7 - 0
assets/scripts/LevelSystem/GameManager.ts

@@ -558,6 +558,13 @@ export class GameManager extends Component {
     
     private onMainMenuClick() {
         console.log('[GameManager] 返回主菜单');
+        
+        // 首先清理游戏数据
+        if (this.inGameManager) {
+            console.log('[GameManager] 触发游戏数据清理');
+            this.inGameManager.triggerGameDataCleanup();
+        }
+        
         // 使用装饰器属性获取MainUI,避免使用find
         if (!this.mainUI) {
             console.error('[GameManager] MainUI节点未在编辑器中设置,请拖拽Canvas/MainUI到GameManager的mainUI属性');

+ 78 - 0
assets/scripts/LevelSystem/IN_game.ts

@@ -841,6 +841,76 @@ export class InGameManager extends Component {
         this.updateEnergyBar();
         console.log('[InGameManager] 能量系统重置完成');
     }
+
+    /**
+     * 清理游戏数据,为返回主页面做准备
+     * 当游戏胜利或失败返回主页面时调用
+     */
+    private cleanupGameDataForMainMenu() {
+        console.log('[InGameManager] 开始清理游戏数据,准备返回主页面');
+        
+        const eventBus = EventBus.getInstance();
+        
+        // 1. 清空场上的所有游戏对象
+        console.log('[InGameManager] 清空场上敌人、方块、球');
+        eventBus.emit(GameEvents.CLEAR_ALL_ENEMIES);     // 清空所有敌人
+        eventBus.emit(GameEvents.CLEAR_ALL_BULLETS);     // 清空所有子弹
+        eventBus.emit(GameEvents.CLEAR_ALL_GAME_OBJECTS); // 清空其他游戏对象
+        
+        // 2. 重置能量系统
+        console.log('[InGameManager] 重置能量系统');
+        this.energyPoints = 0;
+        this.updateEnergyBar();
+        
+        // 3. 清空技能选择数据(重置临时技能状态)
+        console.log('[InGameManager] 清空技能选择数据');
+        if (SkillManager.getInstance()) {
+            // 重置技能管理器中的临时技能状态
+            const skillManager = SkillManager.getInstance();
+            const allSkills = skillManager.getAllSkillsData();
+            allSkills.forEach(skill => {
+                skillManager.setSkillLevel(skill.id, 0); // 重置所有技能等级为0
+            });
+        }
+        
+        // 4. 重置关卡数据和游戏状态
+        console.log('[InGameManager] 重置关卡数据和游戏状态');
+        this.currentWave = 1;
+        this.currentWaveEnemyCount = 0;
+        this.currentWaveTotalEnemies = 0;
+        this.enemiesKilled = 0;
+        this.totalEnemiesSpawned = 0;
+        this.levelTotalEnemies = 0;
+        this.levelWaves = [];
+        this.gameStarted = false;
+        this.enemySpawningStarted = false;
+        this.preparingNextWave = false;
+        this.pendingSkillSelection = false;
+        this.pendingBlockSelection = false;
+        this.shouldShowNextWavePrompt = false;
+        
+        // 5. 重置UI状态
+        console.log('[InGameManager] 重置UI状态');
+        if (this.selectSkillUI) {
+            this.selectSkillUI.active = false;
+        }
+        
+        // 6. 清理会话数据(金币等临时数据)
+        console.log('[InGameManager] 清理会话数据');
+        if (LevelSessionManager.inst) {
+            LevelSessionManager.inst.clear(); // 清空局内金币等临时数据
+        }
+        
+        // 7. 通过事件系统通知其他组件进行清理
+        eventBus.emit(GameEvents.RESET_BALL_CONTROLLER);     // 重置球控制器
+        eventBus.emit(GameEvents.RESET_BLOCK_MANAGER);       // 重置方块管理器
+        eventBus.emit(GameEvents.RESET_BLOCK_SELECTION);     // 重置方块选择
+        eventBus.emit(GameEvents.RESET_ENEMY_CONTROLLER);    // 重置敌人控制器
+        eventBus.emit(GameEvents.RESET_WALL_HEALTH);         // 重置墙体血量
+        eventBus.emit(GameEvents.RESET_UI_STATES);           // 重置UI状态
+        
+        console.log('[InGameManager] 游戏数据清理完成,可以安全返回主页面');
+    }
     
     /**
      * 重置游戏状态(供ReStartGame调用)
@@ -858,6 +928,14 @@ export class InGameManager extends Component {
         this.checkTimer = 0;
         console.log('[InGameManager] 游戏状态重置完成');
     }
+
+    /**
+     * 手动触发游戏数据清理(供外部调用)
+     * 可以在返回主菜单按钮点击时调用
+     */
+    public triggerGameDataCleanup() {
+        this.cleanupGameDataForMainMenu();
+    }
     
     /**
      * 应用关卡配置