Răsfoiți Sursa

时间管理器

woso_javan 2 luni în urmă
părinte
comite
e93b18a5d7

+ 2 - 0
assets/module_storm_sunder/RoosterStormSunder.ts

@@ -8,6 +8,7 @@ import { tgxUIMgr } from '../core_tgx/tgx';
 import { UI_Setting } from '../scripts/UIDef';
 import { StormSunderAudioMgr } from './Script/Manager/StormSunderAudioMgr';
 import { GameMgr, GameStatus } from './Script/Manager/GameMgr';
+import { TimerMgr } from './Script/Manager/TimerMgr';
 const { ccclass, property } = _decorator;
 
 @ccclass('RoosterStormSunder')
@@ -43,6 +44,7 @@ export class RoosterStormSunder extends Component {
         battleUI.active = true;
 
         GameMgr.inst.setGameStatus(GameStatus.Playing);
+        TimerMgr.inst.startCountdown();
     }
 
     private onClickSet(): void {

+ 1 - 1
assets/module_storm_sunder/Script/Component/PropComponent.ts

@@ -1,4 +1,4 @@
-import { _decorator, CCBoolean, CCFloat, Collider, Component, ITriggerEvent, Node, tween, Tween, Vec3 } from 'cc';
+import { _decorator, CCBoolean, CCFloat, Collider, Component, ITriggerEvent, Node, PhysicsSystem, tween, Tween, Vec3 } from 'cc';
 import { Effect2DUIMgr } from '../Manager/Effect2DUIMgr';
 const { ccclass, property } = _decorator;
 

+ 1 - 1
assets/module_storm_sunder/Script/Component/PropMoveComponent.ts

@@ -1,4 +1,4 @@
-import { _decorator, Component, Collider, ITriggerEvent, Node, CCFloat, Vec3, randomRange } from 'cc';
+import { _decorator, Component, Collider, ITriggerEvent, Node, CCFloat, Vec3, randomRange, PhysicsSystem } from 'cc';
 import { PropComponent, PropStatus } from './PropComponent';
 const { ccclass, property } = _decorator;
 

+ 44 - 0
assets/module_storm_sunder/Script/Manager/PropMgr.ts

@@ -0,0 +1,44 @@
+import { assetManager, instantiate, Prefab, Node, UITransform, Vec3, Vec2, view, game } from "cc";
+import { resLoader } from "db://assets/core_tgx/base/ResLoader";
+import { StormSunderGlobalInstance } from "../StormSunderGlobalInstance";
+
+/** 道具生成管理器*/
+export class PropMgr {
+    private static _instance: PropMgr;
+    public static get Instance(): PropMgr {
+        if (this._instance == null) {
+            this._instance = new PropMgr();
+        }
+        return this._instance;
+    }
+
+    public static get inst(): PropMgr {
+        return this.Instance;
+    }
+
+    //初始数量
+    public propInitNum: number = 10;
+    //数量上限
+    public propMaxNum: number = 100;
+    //生成周期
+    public propCreateCycle: number = 10;
+    //生成数量
+    public propCreateNum: number = 1;
+
+    public tornadoNode: Node = null;//玩家节点
+
+    public genaratorInitialData() {
+        //DOTO 取配置 先定义假数据
+
+        this.propInitNum = 10;
+        this.propMaxNum = 100;
+        this.propCreateCycle = 2;
+        this.propCreateNum = 1;
+    }
+
+    public update(deltaTime?: number) {
+        //DOTO 生成道具
+        console.log('deltaTime:', deltaTime)
+    }
+}
+

+ 9 - 0
assets/module_storm_sunder/Script/Manager/PropMgr.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.23",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "b0c6524b-b4f9-41d6-82f9-39a5a8303c8a",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 61 - 0
assets/module_storm_sunder/Script/Manager/TimerMgr.ts

@@ -0,0 +1,61 @@
+import { assetManager, instantiate, Prefab, Node, UITransform, Vec3, Vec2, view, game, director, Scheduler } from "cc";
+import { resLoader } from "db://assets/core_tgx/base/ResLoader";
+import { StormSunderGlobalInstance } from "../StormSunderGlobalInstance";
+import { PropMgr } from "./PropMgr"; // 假设PropMgr在同一个目录下
+
+/** 时间管理器*/
+export class TimerMgr {
+    private static _instance: TimerMgr;
+    public static get Instance(): TimerMgr {
+        if (this._instance == null) {
+            this._instance = new TimerMgr();
+        }
+        return this._instance;
+    }
+
+    public static get inst(): TimerMgr {
+        return this.Instance;
+    }
+
+    public countDownTime: number = 10;
+    private timerId: number = 0;
+    private propMgr: PropMgr;
+
+    constructor() {
+        this.propMgr = PropMgr.Instance; // 初始化PropMgr实例
+    }
+
+    // 开始倒计时
+    public startCountdown(): void {
+        this.timerId = setInterval(() => {
+            this.countDownTime--;
+            if (this.countDownTime <= 0) {
+                this.stopCountdown();
+                console.log("Countdown finished!");
+            }
+        }, 1000); // 每秒减少一次
+
+
+        Scheduler.enableForTarget(this);
+        director.getScheduler().schedule(this.update, this, 0);
+    }
+
+    // 停止倒计时
+    private stopCountdown(): void {
+        if (this.timerId) {
+            clearInterval(this.timerId);
+            this.timerId = 0;
+        }
+    }
+
+    // update方法,每帧调用
+    public update(dt: number): void {
+        this.propMgr.update(dt);
+    }
+
+    // 销毁时清理
+    public destroy(): void {
+        this.stopCountdown();
+        director.getScheduler().unscheduleUpdate(this);
+    }
+}

+ 9 - 0
assets/module_storm_sunder/Script/Manager/TimerMgr.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.23",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "f366ff7d-adc3-4de6-b817-046b0fe56acb",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}