浏览代码

1.资源管理
2.换枪报错BUG
3.血条BUG

GregGJ 4 年之前
父节点
当前提交
442d38c0da

+ 6 - 5
assets/scripts/engines/gui/GUIProxy.ts

@@ -58,11 +58,7 @@ export default class GUIProxy{
      * 添加到层上并显示
      */
     private AddToLayer():void{
-        this.uiNode=cc.instantiate(this.prefab);
-        this.mediator=this.uiNode.getComponent(GUIMediator);
-        this.mediator.uiKey=this.key;
-        //添加到层
-        LayerManager.single.AddToLayer(this.mediator.LayerIndex,this.uiNode);
+        this.uiNode.active=true;
         this.mediator.OnShow(this.data);
     }
 
@@ -81,6 +77,11 @@ export default class GUIProxy{
         }
         this.prefab=assets;
         this.state=2;
+        this.uiNode=cc.instantiate(this.prefab);
+        this.mediator=this.uiNode.getComponent(GUIMediator);
+        this.mediator.uiKey=this.key;
+        //添加到层
+        LayerManager.single.AddToLayer(this.mediator.LayerIndex,this.uiNode);
         if(this.isShowing){
             this.AddToLayer();
         }

+ 7 - 1
assets/scripts/games/ui/fightings/FightingMediator.ts

@@ -142,6 +142,11 @@ export class FightingMediator extends GUIMediator {
         // Your initialization goes here.
     }
 
+    constructor(){
+        super();
+        console.log("创建!");
+    }
+
     OnShow():void{
         this.onShowed=false;
         this.LoadAssets();
@@ -350,7 +355,7 @@ export class FightingMediator extends GUIMediator {
             return;
         }
         super.update(deltaTime);
-        if(GameController.single.fence.hp!=this.fenceHp){
+        if(GameController.single.fence!=null&&GameController.single.fence.node!=null){
             this.RefreshFenceHp();
             this.fenceHp=GameController.single.fence.hp;
         }
@@ -395,6 +400,7 @@ export class FightingMediator extends GUIMediator {
      * 返回主界面
      */
     BackToPrepareScene():void{
+        GameController.single.OnGameOver(2);
         SceneManager.single.Swicth("PrepareScene");
         this.HideSelf();
     }

+ 26 - 11
assets/scripts/games/ui/fightings/GameController.ts

@@ -142,11 +142,8 @@ export class GameController extends EventDispatcher{
         GameModel.single.integral=0;
         //重置技能
         this.SkillReset();
-        this.GameOver=false;
         this.levelConfig=GameConfigManager.GetLevelConfig(GameModel.single.currentLevel);
         this.runTime=0;
-        //清理怪物
-        this.ClearMonsters();
         //复制一份配置
         this.monstersConfig=GameConfigManager.CreateMonsterByList(this.levelConfig.monsters,this.runTime);
         this.monsterTotalCount=this.monstersConfig.length;
@@ -154,6 +151,30 @@ export class GameController extends EventDispatcher{
         this.weapon.bulletCount=GameConfigManager.GetWeaponConfig(GameModel.single.currentWeaponId).clip;
         //初始化栅栏
         this.InitFence();
+        this.GameOver=false;
+    }
+
+    /**
+     * 游戏结束
+     * @param state 0 胜利 1 失败 2正常退出
+     */
+    OnGameOver(state:number):void{
+        //清理怪物
+        this.ClearMonsters();
+        //清理武器
+        this.weapon.Destroy();
+        //销毁栅栏
+        if(this.fence.node){
+            this.fence.node.destroy();
+        }
+        if(state==0){
+            GUIManager.single.Show(UIConst.GAME_OVER_UI,true);
+        }else if(state==1)
+        {
+            GUIManager.single.Show(UIConst.GAME_OVER_UI,false);
+        }
+        GUIManager.single.Hide(UIConst.FIGHTING_UI);
+        this.GameOver=true;
     }
 
     /**
@@ -266,10 +287,7 @@ export class GameController extends EventDispatcher{
             if(GameModel.single.currentLevel>=GameConfigManager.MaxLevel){
                 GameModel.single.currentLevel=GameConfigManager.MaxLevel;
             }
-            this.ClearMonsters();
-            this.GameOver=true;
-            GUIManager.single.Show(UIConst.GAME_OVER_UI,true);
-            GUIManager.single.Hide(UIConst.FIGHTING_UI);
+            this.OnGameOver(0);
         }
     }
     
@@ -286,9 +304,7 @@ export class GameController extends EventDispatcher{
                 this.fence.Damage(damage);
             }
         }else{
-            this.GameOver=true;
-            GUIManager.single.Show(UIConst.GAME_OVER_UI,false);
-            GUIManager.single.Hide(UIConst.FIGHTING_UI);
+            this.OnGameOver(1);
         }
     }
 
@@ -343,7 +359,6 @@ export class GameController extends EventDispatcher{
      * 武器攻击
      */
     WeaponAttack():void{
-        console.log("开枪了");
         let monsterList:MonsterBase[];
         let monsterLists:Array<Array<MonsterBase>>=[];
         //攻击1条路

+ 11 - 3
assets/scripts/games/ui/fightings/fences/FenceBase.ts

@@ -4,7 +4,6 @@ const { ccclass, property } = _decorator;
 
 @ccclass('FenceBase')
 export class FenceBase extends Component {
-    config:any;
 
     hp:number;
 
@@ -15,16 +14,25 @@ export class FenceBase extends Component {
      * 状态 0 站立 1 受伤 2 死亡
      */
     private state:number=0;
+
     start () {
         // Your initialization goes here.
-        this.hp=this.maxHp=this.config.hp;
-
         this.animation=this.getComponent(AnimationComponent);
         CCSAnimationUtils.SetAnimationSpeed(this.animation,this.config.idleAnimation,this.config.idleAnimationSpeed);
         CCSAnimationUtils.SetAnimationSpeed(this.animation,this.config.damageAnimation,this.config.damageAnimationSpeed);
         CCSAnimationUtils.SetAnimationSpeed(this.animation,this.config.dieAnimation,this.config.dieAnimationSpeed);
     }
 
+    set config(value:any){
+        this.__config=value;
+        this.hp=this.maxHp=this.config.hp;
+    }
+    
+    private __config:any;
+    get config():any{
+        return this.__config;
+    }
+
     /**
      * 闲置
      */

+ 17 - 8
assets/scripts/games/ui/fightings/monsters/MonsterBase.ts

@@ -4,6 +4,7 @@ import CCSAnimationUtils from '../../../../engines/utils/CCSAnimationUtils';
 import GameConfigManager from '../../../models/GameConfigManager';
 import { GameController } from '../GameController';
 import { MonsterHP } from './MonsterHP';
+import { MonsterHPUIPool } from './MonsterHPUIPool';
 const { ccclass, property } = _decorator;
 
 @ccclass('MonsterBase')
@@ -65,7 +66,7 @@ export class MonsterBase extends Component {
     private InitAnimations():void{
         CCSAnimationUtils.SetAnimationSpeed(this.animation,this.monsterConfig.moveAnimation,this.monsterConfig.moveAnimationSpeed);
         CCSAnimationUtils.SetAnimationSpeed(this.animation,this.monsterConfig.attackAnimation,this.monsterConfig.attackAnimationSpeed);
-        CCSAnimationUtils.SetAnimationEvent(this.animation,this.monsterConfig.attackAnimation,this.monsterConfig.attackAnimationEvents);
+        // CCSAnimationUtils.SetAnimationEvent(this.animation,this.monsterConfig.attackAnimation,this.monsterConfig.attackAnimationEvents);
         CCSAnimationUtils.SetAnimationSpeed(this.animation,this.monsterConfig.dieAnimation,this.monsterConfig.dieAnimationSpeed);
     }
 
@@ -161,15 +162,17 @@ export class MonsterBase extends Component {
         this.animation.play(this.monsterConfig.attackAnimation);
     }
 
-    /**
-     * 攻击生效帧回调
-     */
-    AttackDamageFrame():void{
-        console.log(this.config.mId+"攻击"+this.attackType);
-        GameController.single.MonsterAttack(this.attackType,this.config.damage);
-    }
+    // /**
+    //  * 攻击生效帧回调
+    //  */
+    // AttackDamageFrame():void{
+    //     console.log(this.config.mId+"攻击"+this.attackType);
+    //     GameController.single.MonsterAttack(this.attackType,this.config.damage);
+    // }
 
     private AttackComplete():void{
+        console.log(this.config.mId+"攻击"+this.attackType);
+        GameController.single.MonsterAttack(this.attackType,this.config.damage);
         this.state=0;
         this.Move();
     }
@@ -248,8 +251,14 @@ export class MonsterBase extends Component {
     private DieComplete():void{
         this.node.active=false;
         this.node.destroy();
+
+    }
+
+    onDestroy():void{
         SoundManager.single.ClearSound(this.config.id);
         this.danHen=null;
+        MonsterHPUIPool.Recycle(this.hpView);
+        this.hpView=null;
     }
 
     private removeAllAnimationEvent():void{

+ 6 - 4
assets/scripts/games/ui/fightings/monsters/MonsterHP.ts

@@ -19,6 +19,12 @@ export class MonsterHP extends Component {
         this.progressBar.progress=0;
     }
 
+    onEnable():void{
+        this.progressBar=this.getComponent(ProgressBarComponent);
+        this.node.setScale(0,0,0);
+    }
+
+
     update (deltaTime: number) {
         if(this.monster==null){
             return;
@@ -36,9 +42,5 @@ export class MonsterHP extends Component {
         
         //更新HP
         this.progressBar.progress=this.monster.hp/this.monster.maxHP;
-
-        if(this.monster.isDie){
-            MonsterHPUIPool.Recycle(this);
-        }
     }
 }

+ 12 - 10
assets/scripts/games/ui/fightings/monsters/MonsterHPUIPool.ts

@@ -13,11 +13,12 @@ export class MonsterHPUIPool extends Component {
      */
     public static Create():MonsterHP{
         let monsterHPView:MonsterHP;
-        if(this.pool.length>0){
-            monsterHPView=this.pool.shift();
-            GameController.single.monsterHPUILayer.addChild(monsterHPView.node);
-            return monsterHPView
-        }
+        // if(this.pool.length>0){
+        //     monsterHPView=this.pool.shift();
+        //     // GameController.single.monsterHPUILayer.addChild(monsterHPView.node);
+        //     monsterHPView.node.active=true;
+        //     return monsterHPView
+        // }
         let prefab:Prefab=loader.getRes("ui/components/MonsterHPUI");
         let viewNode:Node=instantiate(prefab);
         monsterHPView=viewNode.addComponent(MonsterHP);
@@ -27,10 +28,11 @@ export class MonsterHPUIPool extends Component {
 
     public static Recycle(monsterHPView:MonsterHP):void{
         GameController.single.monsterHPUILayer.removeChild(monsterHPView.node);
-        monsterHPView.monster=null;
-        if(this.pool.indexOf(monsterHPView)>=0){
-            throw new Error("重复回收")
-        }
-        this.pool.push(monsterHPView);
+        monsterHPView.node.destroy();
+        // monsterHPView.monster=null;
+        // if(this.pool.indexOf(monsterHPView)>=0){
+        //     throw new Error("重复回收")
+        // }
+        // this.pool.push(monsterHPView);
     }
 }

+ 23 - 0
assets/scripts/games/ui/fightings/weapons/WeaponBase.ts

@@ -64,6 +64,27 @@ export class WeaponBase extends EventDispatcher{
         this.Idle();
     }
 
+    /**
+     * 销毁
+     */
+    Destroy():void{
+        this.weaponPrefab=null;
+        //枪口火焰
+
+        this.leftSocket.removeChild(this.leftWeapon);
+        this.leftWeapon.destroy();
+        this.leftWeapon=null;
+        this.rightSocket.removeChild(this.rightWeapon);
+        this.rightWeapon.destroy();
+        this.rightWeapon=null;
+
+        this.gunfirePrefab=null;
+        this.leftGunFire.node.destroy();
+        this.leftGunFire=null;
+        this.rightGunFire.node.destroy();
+        this.rightGunFire=null;
+    }
+
     protected InitHands():void{
         this.leftSocket=find("RootNode/Arm/upper_arm_R/lower_arm_R/transform1/hand_R/transform2/Guns",this.leftHand.node);
         this.rightSocket=find("RootNode/Arm/upper_arm_R/lower_arm_R/transform1/hand_R/transform2/Guns",this.rightHand.node);
@@ -236,4 +257,6 @@ export class WeaponBase extends EventDispatcher{
         }
         return -1;
     }
+
+ 
 }

+ 12 - 5
assets/scripts/games/ui/prepares/PrepareMediator.ts

@@ -1,4 +1,4 @@
-import { AudioClip, AudioSourceComponent, ButtonComponent, Color, EventTouch, find, instantiate, LabelComponent, LayoutComponent, loader, Material, ModelComponent, Node, Prefab, Quat, SpriteComponent, SpriteFrame, systemEvent, SystemEventType, Touch, Vec2, view, _decorator } from 'cc';
+import { ButtonComponent, EventTouch, find, instantiate, LabelComponent, LayoutComponent, loader, ModelComponent, Node, Prefab, Quat, SpriteComponent, SpriteFrame, SystemEventType, Touch, Vec2, view, _decorator } from 'cc';
 import { GUIManager } from '../../../engines/gui/GUIManager';
 import { GUIMediator } from '../../../engines/gui/GUIMediator';
 import { DataModelEventType } from '../../../engines/models/DataModelEventType';
@@ -9,10 +9,8 @@ import { PlatformManager } from '../../../Platform/PlatformManager';
 import GameConfigManager from '../../models/GameConfigManager';
 import { GameModel } from '../../models/GameModel';
 import { GamePropertys } from '../../models/GamePropertys';
-import { WeaponCell } from '../../models/weapons/WeaponCell';
 import { UIConst } from '../UIConst';
 import { WeaponCellListView } from './WeaponCellListView';
-import { WeaponCellScript } from './WeaponCellScript';
 const { ccclass, property } = _decorator;
 
 @ccclass('PrepareMediator')
@@ -123,6 +121,7 @@ export class PrepareMediator extends GUIMediator {
 
     private weaponCellListView: WeaponCellListView;
 
+
     onLoad(): void {
         this.weaponCellListView = new WeaponCellListView(this);
     }
@@ -152,9 +151,16 @@ export class PrepareMediator extends GUIMediator {
         this.modelView.node.active = true;
 
         let weaponConfig: any = GameConfigManager.GetWeaponConfig(GameModel.single.currentWeaponId);
-        if (this.prefabInstance) {
+        if (this.modelPrefab) {
             this.modelView.mesh = null;
+            let target=this.modelView.materials[0];
+            target.setProperty("mainTexture", null);
+
             this.prefabInstance.destroy();
+            this.prefabInstance=null;
+            let deps:string[]=loader.getDependsRecursively(this.modelPrefab);
+            loader.release(deps);
+            this.modelPrefab=null;
         }
         loader.loadRes(weaponConfig.prefab, Prefab, (err, prefab) => {
             if (err) {
@@ -180,7 +186,8 @@ export class PrepareMediator extends GUIMediator {
         this.RemoveEvents();
 
         this.modelView.mesh = null;
-        this.modelView.setMaterial(null, 0);
+        let target=this.modelView.materials[0];
+        target.setProperty("mainTexture", null);
         if (this.prefabInstance) {
             this.prefabInstance.destroy();
         }