浏览代码

解决能量条问题

181404010226 4 月之前
父节点
当前提交
5247056748
共有 2 个文件被更改,包括 162 次插入362 次删除
  1. 113 350
      assets/Scenes/GameLevel.scene
  2. 49 12
      assets/scripts/LevelSystem/IN_game.ts

文件差异内容过多而无法显示
+ 113 - 350
assets/Scenes/GameLevel.scene


+ 49 - 12
assets/scripts/LevelSystem/IN_game.ts

@@ -118,6 +118,20 @@ export class InGameManager extends Component {
     private energyBar: ProgressBar = null;
     private selectSkillUI: Node = null;
 
+    // 能量条UI节点
+    @property({
+        type: Node,
+        tooltip: '拖拽能量条节点到这里 (Canvas/GameLevelUI/EnergyBar)'
+    })
+    public energyBarNode: Node = null;
+
+    // 技能选择UI节点
+    @property({
+        type: Node,
+        tooltip: '拖拽技能选择UI节点到这里 (Canvas/GameLevelUI/SelectSkillUI)'
+    })
+    public selectSkillUINode: Node = null;
+
     // GameBlockSelection组件
     private blockSelectionComponent: GameBlockSelection = null;
 
@@ -180,6 +194,7 @@ export class InGameManager extends Component {
         eventBus.on(GameEvents.GAME_DEFEAT, this.onGameDefeatEvent, this);
         eventBus.on(GameEvents.GAME_RESUME, this.onGameResumeEvent, this);
         eventBus.on('ENEMY_KILLED', this.onEnemyKilledEvent, this);
+        eventBus.on(GameEvents.RESET_ENERGY_SYSTEM, this.resetEnergySystem, this);
     }
 
     /**
@@ -345,9 +360,16 @@ export class InGameManager extends Component {
         const remaining = this.currentWaveTotalEnemies - this.currentWaveEnemyCount;
         console.log(`[InGameManager] 敌人被消灭,当前波剩余敌人: ${remaining}/${this.currentWaveTotalEnemies}`);
         
+        // 每死一个敌人就立即增加能量
+        const energyBeforeIncrement = this.energyPoints;
+        this.incrementEnergy();
+        
         // 通过事件系统更新敌人计数标签
         EventBus.getInstance().emit(GameEvents.ENEMY_UPDATE_COUNT, this.currentWaveEnemyCount);
         
+        // 检查能量是否已满,如果满了需要触发技能选择
+        const energyWillBeFull = energyBeforeIncrement + 1 >= this.energyMax;
+        
         // 通过事件系统检查是否有活跃敌人
         let hasActiveEnemies = false;
         EventBus.getInstance().emit(GameEvents.ENEMY_CHECK_ACTIVE, (active: boolean) => {
@@ -359,11 +381,7 @@ export class InGameManager extends Component {
             if (isWaveEnd) {
                 console.log(`[InGameManager] 波次结束检测: remaining=${remaining}, hasActiveEnemies=${hasActiveEnemies}`);
                 
-                const energyBeforeIncrement = this.energyPoints;
-                this.incrementEnergy();
-                
-                const energyWillBeFull = energyBeforeIncrement + 1 >= this.energyMax;
-                
+                // 如果能量已满,设置等待方块选择状态
                 if (energyWillBeFull) {
                     this.pendingBlockSelection = true;
                     this.preparingNextWave = true;
@@ -375,10 +393,12 @@ export class InGameManager extends Component {
                         this.triggerGameSuccess();
                     }
                 }
+            } else if (energyWillBeFull) {
+                // 如果波次未结束但能量已满,也需要触发技能选择
+                console.log('[InGameManager] 能量已满但波次未结束,触发技能选择');
+                this.currentState = GameState.BLOCK_SELECTION;
             }
         });
-        
-        // 能量增加逻辑移到了回调函数中,这里不再需要重复处理
     }
 
     /**
@@ -517,13 +537,26 @@ export class InGameManager extends Component {
      */
     private initUINodes() {
         // 初始化能量条
-        const energyBarNode = find('Canvas/GameLevelUI/EnergyBar');
-        if (energyBarNode) {
-            this.energyBar = energyBarNode.getComponent(ProgressBar);
+        if (this.energyBarNode) {
+            this.energyBar = this.energyBarNode.getComponent(ProgressBar);
+            if (this.energyBar) {
+                console.log('[InGameManager] 能量条组件初始化成功');
+                // 初始化能量条显示
+                this.updateEnergyBar();
+            } else {
+                console.error('[InGameManager] 能量条节点存在但ProgressBar组件未找到');
+            }
+        } else {
+            console.error('[InGameManager] 能量条节点未通过装饰器挂载,请在Inspector中拖拽EnergyBar节点');
         }
         
         // 初始化技能选择UI
-        this.selectSkillUI = find('Canvas/GameLevelUI/SelectSkillUI');
+        if (this.selectSkillUINode) {
+            this.selectSkillUI = this.selectSkillUINode;
+            console.log('[InGameManager] 技能选择UI节点初始化成功');
+        } else {
+            console.error('[InGameManager] 技能选择UI节点未通过装饰器挂载,请在Inspector中拖拽SelectSkillUI节点');
+        }
     }
     
     /**
@@ -531,7 +564,11 @@ export class InGameManager extends Component {
      */
     private updateEnergyBar() {
         if (this.energyBar) {
-            this.energyBar.progress = this.energyPoints / this.energyMax;
+            const progress = this.energyPoints / this.energyMax;
+            this.energyBar.progress = progress;
+            console.log(`[InGameManager] 能量条更新: ${this.energyPoints}/${this.energyMax} (${Math.round(progress * 100)}%)`);
+        } else {
+            console.warn('[InGameManager] 能量条组件未初始化,无法更新显示');
         }
     }
     

部分文件因为文件数量过多而无法显示