2 Commits 5eacde94e6 ... 5f1973b085

Autor SHA1 Mensaje Fecha
  0224995 5f1973b085 loadScene hace 1 mes
  0224995 56b5b14f13 applyNodePool hace 1 mes

+ 17 - 1
assets/Scene.meta

@@ -5,5 +5,21 @@
   "uuid": "e9e17630-3958-4a45-956e-1413bf95cdaf",
   "files": [],
   "subMetas": {},
-  "userData": {}
+  "userData": {
+    "bundleName": "Scene",
+    "isBundle": true,
+    "bundleFilterConfig": [
+      {
+        "range": "exclude",
+        "type": "asset",
+        "patchOption": {
+          "patchType": "glob",
+          "value": "db://assets/*.test"
+        },
+        "assets": [
+          "099ece80-6a52-4fc1-8f49-dcd0345183d0"
+        ]
+      }
+    ]
+  }
 }

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 774 - 79
assets/Scene/StartScene.scene


+ 6 - 1
assets/Script/Game/MyApp/GameScene/EnemyMgr.ts

@@ -9,6 +9,7 @@ import { GameMgr } from '../../GameFrameWork/GameMgr';
 import { TouchGame } from '../TouchGame';
 import { Tools } from '../../Tools/Tools';
 import { EnemyTower } from './EnemyTower';
+import { PoolManager } from '../../GameFrameWork/NodePool/PoolManager';
 const { ccclass, property } = _decorator;
 
 @ccclass('EnemyMgr')
@@ -34,6 +35,9 @@ export class EnemyMgr extends ModulerBase {
         this._enemyTower = this.node.parent.getChildByName("EnemyTower");
     }
     init() {
+        //创建多个敌人预制体
+        PoolManager.instance.registerPool(resMgr.getPrefab("Enemy"),6);
+
         this._roleDatas = dataMgr.getAllDataByName("RoleCardData");
         //第几关的数据
         this._lvDt = this._lvDts[GameInfo.Instance.getCurlv() - 1];
@@ -48,7 +52,8 @@ export class EnemyMgr extends ModulerBase {
     }
 
     private _createEnemy() {
-        const enemy: Node = instantiate(resMgr.getPrefab("Enemy"));
+        //const enemy: Node = instantiate(resMgr.getPrefab("Enemy"));
+        const enemy: Node = PoolManager.instance.get(resMgr.getPrefab("Enemy"));
         enemy.parent = this.node;
         const enemyTS = enemy.getComponent(Enemy);
         const imgNameArray = this._lvDt.imgName;

+ 1 - 1
assets/Script/Game/MyApp/GameScene/MyRole.ts

@@ -9,7 +9,7 @@ const { ccclass, property } = _decorator;
 @ccclass('MyRole')
 export class MyRole extends Role {
     private _lifeBar: LifeBar = null;
-
+    
     protected onLoad(): void {
         this._lifeBar = this.node.getComponent(LifeBar);
     }

+ 55 - 7
assets/Script/Game/MyApp/Role.ts

@@ -53,7 +53,15 @@ export class Role extends Component {
 
     //状态管理
     _state: RoleState = null;
-    
+    //被回收时,重置属性
+    protected onDisable(): void {
+        this._clearData();
+    }
+    //重新激活时
+    protected onEnable(): void {
+
+    }
+
     init(name: string, pos: Vec3, roleDatas: RoleData[], dir?: number) {
         this._bulletPool = this.node.getComponent(BulletPool);
         this._bulletPool.init();
@@ -97,7 +105,6 @@ export class Role extends Component {
         //位置
         this.node.setWorldPosition(pos);
         this.bulletLayer = find("Canvas/GameRoot/BulletLayer");
-
     }
 
     private _setRoleData(roleData: RoleData) {
@@ -125,14 +132,14 @@ export class Role extends Component {
     }
 
     update(deltaTime: number) {
-        
+
         if (this._state === RoleState.Die) return;
         //只有游戏结束才能执行后续操作
-        if(GameInfo.Instance.getIsGameOver()) return;
-        
+        if (GameInfo.Instance.getIsGameOver()) return;
+
         if (!this.currentTarget) {
             this._handleMovement(deltaTime);
-            
+
             this._detectEnemies();
         } else {
             this._handleAttack(deltaTime);
@@ -156,7 +163,7 @@ export class Role extends Component {
         //节点不可用,不寻敌
         if (!this.node.isValid) return;
         //游戏结束,不寻敌
-        if(GameInfo.Instance.getIsGameOver()) return;
+        if (GameInfo.Instance.getIsGameOver()) return;
         //const startPos = new Vec2(this.node.position.x, this.node.position.y);
         const startPos = this.node.position.clone();
         const endPos = new Vec2((this.direction * this.atkLength) + this.node.position.x, this.node.position.y);
@@ -312,6 +319,47 @@ export class Role extends Component {
         })
     }
 
+    private _clearData() {
+        // 重置基础数据
+        this.hp = null;
+        this.atk = null;
+        this.atkLength = null;
+        this.moveSpeed = null;
+
+        // 重置方向和状态
+        this.direction = 1;
+        this.isStop = false;
+
+        // 清除战斗系统状态
+        this._attackTimer = 0;
+        this.targetNode = null;
+        this.currentTarget = null;
+
+        // 释放子弹资源
+        if (this._bullet) {
+            // 如果使用了对象池,将子弹放回池
+            if (this._bulletPool) {
+                const isEnemy = this.direction === -1;
+                this._bulletPool.recycle(this._bullet, isEnemy);
+            } else {
+                // 否则直接销毁
+                this._bullet.destroy();
+            }
+            this._bullet = null;
+        }
+
+        // 重置动画状态
+        if (this._animation) {
+            this._animation.stop();
+        }
+
+        // 重置状态机
+        this._state = null;
+
+        // 清除节点引用
+        //this.bulletLayer = null;
+    }
+
     //要求子类实现的碰撞分组和阵营判断方法,确保不同阵营角色可以正确交互
     protected _getCollisionGroup(): number {
         throw new Error("Method not implemented");

+ 3 - 3
assets/Script/Game/MyApp/SelectTroopsBottom.ts

@@ -1,4 +1,4 @@
-import { _decorator, Button, Component, director, Node,  Sprite, SpriteFrame } from 'cc';
+import { _decorator, Button, Component, director, find, Node,  Sprite, SpriteFrame } from 'cc';
 import { GameInfo } from '../../GameInfo';
 const { ccclass, property } = _decorator;
 
@@ -21,8 +21,8 @@ export class SelectTroopsBottom extends Component {
         if (this._names) {
             GameInfo.Instance.setRoleImgNames(this._names);
             GameInfo.Instance.getGameOverReward().clear();
-            
-            director.loadScene("GameScene");
+            find("Canvas/LoadScene").active = true;
+            //director.loadScene("GameScene");
         }
     }
 

+ 13 - 6
assets/Script/Game/MyApp/TouchGame.ts

@@ -1,4 +1,4 @@
-import { _decorator,  Node, EventTouch, Rect, UITransform, Sprite, SpriteFrame, Vec2, instantiate, Vec3, Component } from 'cc';
+import { _decorator, Node, EventTouch, Rect, UITransform, Sprite, SpriteFrame, Vec2, instantiate, Vec3, Component } from 'cc';
 import { resMgr } from '../../Frames/ResourcesMgr';
 import { Role } from './Role';
 import { dataMgr } from '../../Frames/DataManager';
@@ -7,6 +7,7 @@ import { ModulerBase } from '../GameFrameWork/ModulerBase';
 import { MyRole } from './GameScene/MyRole';
 import { Card } from './Card';
 import { Bottom } from './GameScene/Bottom';
+import { PoolManager } from '../GameFrameWork/NodePool/PoolManager';
 const { ccclass, property } = _decorator;
 
 @ccclass('TouchGame')
@@ -36,6 +37,9 @@ export class TouchGame extends ModulerBase {
     }
 
     protected start(): void {
+        //创建6个预制体
+        PoolManager.instance.registerPool(resMgr.getPrefab("Role"), 6);
+
         this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
         this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
         this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
@@ -51,7 +55,7 @@ export class TouchGame extends ModulerBase {
             if (box.contains(pos)) {
                 this._clickedNode = element;
                 this._clickedNodeCom = this._clickedNode.getComponent(Card);
-                if(!this._clickedNodeCom.disabled && this._clickedNodeCom.clickable){
+                if (!this._clickedNodeCom.disabled && this._clickedNodeCom.clickable) {
                     const img: SpriteFrame = element.getChildByName("Sprite").getComponent(Sprite).spriteFrame;
                     if (!img) {
                         this._isDragging = false;
@@ -65,7 +69,7 @@ export class TouchGame extends ModulerBase {
                         this.setDragNodePosition(pos);
                     }
                     break; // 找到一个就停止遍历 
-                } 
+                }
             }
         }
     }
@@ -105,7 +109,7 @@ export class TouchGame extends ModulerBase {
         for (const element of this._load.children) {
             if (element.name !== "Roles") {
                 const box = element.getComponent(UITransform).getBoundingBoxToWorld();
-                if (box.contains(new Vec2(pos.x,pos.y))) {
+                if (box.contains(new Vec2(pos.x, pos.y))) {
                     this._highLightIdx = element.getSiblingIndex();
                     if (this._highLightIdx >= 6) {
                         this._hideNode();
@@ -115,7 +119,10 @@ export class TouchGame extends ModulerBase {
                 }
             }
         }
-        const role: Node = instantiate(resMgr.getPrefab("Role"));
+        
+        //从NodePool里获取一个Node
+        const role: Node = PoolManager.instance.get(resMgr.getPrefab("Role"));
+        //const role: Node = instantiate(resMgr.getPrefab("Role"));
         role.parent = this._load.getChildByName("Roles");
 
         const roleTS: Role = role.getComponent(MyRole);
@@ -130,7 +137,7 @@ export class TouchGame extends ModulerBase {
         this._clickedNode.getComponent(Card).aniPlay();
         this._hideNode();
     }
-    
+
     private _hideNode() {
         this._dragNode.active = false;
         this._dragNode.getComponent(Sprite).spriteFrame = null;

+ 37 - 0
assets/Script/Game/UI/LoadScene.ts

@@ -0,0 +1,37 @@
+import { _decorator, assetManager, Component, director, ProgressBar } from 'cc';
+const { ccclass, property } = _decorator;
+
+@ccclass('LoadScene')
+export class LoadScene extends Component {
+    private progressBar: ProgressBar = null;
+
+    start() {
+        this.progressBar = this.node.getComponentInChildren(ProgressBar);
+        this.loadSceneWithProgress("GameScene");
+    }
+
+    loadSceneWithProgress(sceneName: string) {
+        assetManager.loadBundle("Scene", (err, bundle) => {
+            if (err) {
+                console.log("加载失败", err);
+                return;
+            }
+            bundle.loadScene(
+                sceneName,
+                (finished: number, total: number) => {
+                    this.progressBar.progress = finished / total;
+                },
+                (err, sceneAsset) => {
+                    if (err) {
+                        console.log("加载场景失败", err);
+                        return;
+                    }
+                    this.node.active = false;
+                    director.runSceneImmediate(sceneAsset);
+                }
+            );
+        });
+    }
+}
+
+

+ 9 - 0
assets/Script/Game/UI/LoadScene.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.23",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "847ffa57-158f-4731-8919-cb92542b6eb3",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 6 - 7
assets/Script/Game/UI/LoadingUI.ts

@@ -1,5 +1,4 @@
-import { _decorator,Component,director,Label, ProgressBar } from 'cc';
-import { UIBase } from '../GameFrameWork/UIBase';
+import { _decorator, Component, Label, ProgressBar } from 'cc';
 const { ccclass, property } = _decorator;
 
 @ccclass('LoadingUI')
@@ -35,16 +34,16 @@ export class LoadingUI extends Component {
         this.progressLabel = this.getComponentInChildren(Label);
         this.whichRes = this.node.getChildByName("_which").getComponent(Label);
     }
-    public updateProgress(progress: number){
-        if(this.progressBar){
+    public updateProgress(progress: number) {
+        if (this.progressBar) {
             this.progressBar.progress = progress;
         }
-        if(this.progressLabel){
+        if (this.progressLabel) {
             this.progressLabel.string = `${Math.floor(progress * 100)}%`;
         }
     }
-    public updateWhichRes(which: number){
-        if(this.whichRes){
+    public updateWhichRes(which: number) {
+        if (this.whichRes) {
             this.whichRes.string = `${which}/3`;
         }
     }

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio