From 23ef235a263191230031dfaa02c054197fdddd91 Mon Sep 17 00:00:00 2001 From: chenxin <chenxin6991@163.com> Date: Tue, 20 Oct 2020 14:08:19 +0800 Subject: [PATCH] 完善PVE界面逻辑,使用正式的界面资源 解决bug:1.打掉小怪没有获得金币 2.摧毁塔位 塔没有消失 --- Assets/Scripts/TowerDefense/UI/HUD/EndlessGameUI.cs | 31 ++++++++++++++++++++++--------- 1 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/TowerDefense/UI/HUD/EndlessGameUI.cs b/Assets/Scripts/TowerDefense/UI/HUD/EndlessGameUI.cs index b03cc39..c3398f0 100644 --- a/Assets/Scripts/TowerDefense/UI/HUD/EndlessGameUI.cs +++ b/Assets/Scripts/TowerDefense/UI/HUD/EndlessGameUI.cs @@ -4,6 +4,7 @@ using DG.Tweening; using JetBrains.Annotations; using System; +using System.Collections; using System.Collections.Generic; using TMPro; using TowerDefense.Level; @@ -201,6 +202,8 @@ // 测试屏幕显示相关的倒计时. protected bool bLoaded = false; + private Timer overTimer; + /// <summary> /// 总兵线数 /// </summary> @@ -228,6 +231,8 @@ /// 所有攻击塔位的摧毁信息,是否被摧毁,默认全部没有被摧毁 /// </summary> private bool[,] TowerDestroyArr; + + public event Action GameOverEvent; public IPlacementArea selfTowerPlaceArea { @@ -421,12 +426,9 @@ break; case State.Paused: case State.GameOver: - // if (oldState == State.Building) - // { - // CancelGhostPlacement(); - // } - // Time.timeScale = 0f; - Debug.Log("--------------------- game over !!! ---------------------"); + if (oldState == State.Building) + CancelGhostPlacement(); + Time.timeScale = 1f; break; default: throw new ArgumentOutOfRangeException("newState", newState, null); @@ -681,7 +683,7 @@ } TowerDestroyArr[xidx, i] = true; - Tower tower = FindTowerWithGridIdx(xidx, i); + Tower tower = FindTowerWithGridIdx(xidx, 3 - i); if (tower) { @@ -730,7 +732,15 @@ // 红心减少逻辑 // HealthHeartState.instance.killHeart(false); GameOver(); + overTimer = new Timer(1f, SafelyCallGameOverEvent); } + } + + private void SafelyCallGameOverEvent() + { + if (GameOverEvent != null) + GameOverEvent(); + overTimer = null; } /// <summary> @@ -1471,7 +1481,7 @@ int cost = TowerPrice.instance.currentTowerPrice; if (zeroCost) cost = 0; - + if (forceCost != -1) cost = forceCost; @@ -1499,7 +1509,7 @@ PlaceTower(lvl); } - + return true; } @@ -2001,6 +2011,9 @@ /// </summary> private void Update() { + if (overTimer != null) + overTimer.Tick(Time.deltaTime); + for (int ti = listTowerTimer.Count - 1; ti >= 0; ti--) { // 如果执行到,会在DelTower函数内删除对应的listTowerTimer. -- Gitblit v1.9.1