woso_javan 2 kuukautta sitten
vanhempi
commit
390eea7e8c

+ 3 - 0
assets/module_storm_sunder/Prefabs/UI/Revive/UI_BattleRevive_Impl.ts

@@ -6,6 +6,7 @@ import { GameMgr, GameStatus } from '../../../Script/Manager/GameMgr';
 import { tgxModuleContext } from 'db://assets/core_tgx/tgx';
 import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
 import { GameEvent } from '../../../Script/Enum/GameEvent';
+import { TimerMgr } from '../../../Script/Manager/TimerMgr';
 const { ccclass, property } = _decorator;
 
 @ccclass('UI_BattleRevive_Impl')
@@ -20,6 +21,7 @@ export class UI_BattleRevive_Impl extends UI_BattleRevive {
     }
 
     protected onCreated(): void {
+        TimerMgr.inst.pauseCountdown();
         let layout = this.layout as Layout_BattleRevive;
         this.onButtonEvent(layout.btn_revive, () => {
             EventDispatcher.instance.emit(GameEvent.EVENT_STORM_RESURRECT);
@@ -36,6 +38,7 @@ export class UI_BattleRevive_Impl extends UI_BattleRevive {
     private changeGameStatus(status: GameStatus): void {
         this.hide();
         GameMgr.inst.setGameStatus(status);
+        TimerMgr.inst.resumeCountdown();
         // console.log("changeGameStatus", status);
     }
 }

+ 30 - 6
assets/module_storm_sunder/Script/Manager/TimerMgr.ts

@@ -24,6 +24,7 @@ export class TimerMgr {
     public countDownTime: number = 1;
     private timerId: number = 0;
     private propMgr: PropMgr;
+    private isPaused: boolean = false;  // 添加暂停标志
 
     constructor() {
         this.propMgr = PropMgr.Instance; // 初始化PropMgr实例
@@ -31,14 +32,19 @@ export class TimerMgr {
 
     // 开始倒计时
     public startCountdown(): void {
+        if (this.isPaused) {
+            this.resumeCountdown();
+            return;
+        }
         this.upateLbTime();
         this.timerId = setInterval(() => {
-            this.countDownTime--;
-            if (this.countDownTime <= 0) {
-                this.stopCountdown();
-                // console.log("Countdown finished!");
+            if (!this.isPaused) {
+                this.countDownTime--;
+                if (this.countDownTime <= 0) {
+                    this.stopCountdown();
+                }
+                this.upateLbTime();
             }
-            this.upateLbTime();
         }, 1000); // 每秒减少一次
 
         Scheduler.enableForTarget(this);
@@ -65,6 +71,23 @@ export class TimerMgr {
         }
     }
 
+    // 暂停倒计时
+    public pauseCountdown(): void {
+        this.isPaused = true;
+        director.getScheduler().pauseTarget(this);
+    }
+
+    // 恢复倒计时
+    public resumeCountdown(): void {
+        this.isPaused = false;
+        director.getScheduler().resumeTarget(this);
+    }
+
+    // 获取暂停状态
+    public isPausedState(): boolean {
+        return this.isPaused;
+    }
+
     // update方法,每帧调用
     public update(dt: number): void {
         this.propMgr.update(dt);
@@ -73,11 +96,12 @@ export class TimerMgr {
     // 销毁时清理
     public reset(): void {
         this.stopCountdown();
+        this.isPaused = false;  // 重置暂停状态
         Scheduler.enableForTarget(this);
         director.getScheduler().unscheduleAllForTarget(this);
 
         const mapConfig = MapMgr.Instance.getMapConfig(1);
         this.countDownTime = mapConfig.time;
-        // this.countDownTime = 10; //测试
+        this.countDownTime = 5; //测试
     }
 }