From e5e16b76d8bee667f7e9b26bf6a816f66ba520d8 Mon Sep 17 00:00:00 2001 From: chenxin <chenxin6991@163.com> Date: Wed, 09 Dec 2020 18:14:58 +0800 Subject: [PATCH] 木桩瞄准特效大小 --- Assets/Scripts/TowerDefense/UI/HUD/EndlessGameUI.cs | 265 ++++++++++++++++++++++++++++++++-------------------- 1 files changed, 162 insertions(+), 103 deletions(-) diff --git a/Assets/Scripts/TowerDefense/UI/HUD/EndlessGameUI.cs b/Assets/Scripts/TowerDefense/UI/HUD/EndlessGameUI.cs index 493f4c9..1ab09c4 100644 --- a/Assets/Scripts/TowerDefense/UI/HUD/EndlessGameUI.cs +++ b/Assets/Scripts/TowerDefense/UI/HUD/EndlessGameUI.cs @@ -1,11 +1,8 @@ -using System.Globalization; -using Core.Health; +using Core.Health; using Core.Input; using Core.Utilities; -using DG.Tweening; using JetBrains.Annotations; using System; -using System.Collections; using System.Collections.Generic; using TMPro; using TowerDefense.Level; @@ -15,7 +12,6 @@ using UnityEngine.EventSystems; using UnityEngine.UI; using TowerDefense.Nodes; -using TowerDefense.Affectors; using KTGMGemClient; namespace TowerDefense.UI.HUD @@ -127,11 +123,26 @@ public TextMoveDoTween bloodCrit; /// <summary> + /// 减速飘字 + /// </summary> + public Image SlowDownWord; + + /// <summary> + /// 暴击飘字 + /// </summary> + public Image CritWord; + + /// <summary> + /// 冰冻飘字 + /// </summary> + public Image FrostWord; + + public Image RestrainWord; + + /// <summary> /// 购买塔防按钮上的Text. /// </summary> protected TextMeshProUGUI towerPriceText; - - //protected TextMeshProUGUI towerPriceText1; protected bool tdBuyDisable = false; @@ -190,6 +201,7 @@ return m_CurrentTower != null; } } + // TowerList用于简单记录相关的数据 protected List<Tower> m_listTower = new List<Tower>(); @@ -571,7 +583,7 @@ if (tower.towerName != towerOld.towerName) continue; - newT = Instantiate(tower, transform); + newT = tower; break; } @@ -585,7 +597,7 @@ SetToDragMode(newT); if (towerOld.towerFeature == EFeatureTower.Skill_Bomb) - m_CurrentTower.SetAttackArea(dragTowerLevel, towerOld.attributeId); + m_CurrentTower.SetAttackArea(dragTowerLevel, towerOld.ElfId); } /// <summary> @@ -673,12 +685,16 @@ if (!m_CurrentTower || !IsGhostAtValidPosition()) { // 最大级别的Tower不能再合并了. - if (towerToMove.isAtMaxLevel) + if (towerToMove.IsMaxLevel) return false; // 判断格子上的塔防: UIPointer pointer = WrapPointer(pinfo); Tower sTower = PickTowerInGrid(pointer); + + // 泡泡禁锢状态不允许合并 + if (sTower && sTower.IsStartBondage) return false; + if (sTower && sTower != towerToMove) { int testLvl = dragTowerLevel; @@ -702,6 +718,9 @@ // 判断格子上的塔防: UIPointer pointer = WrapPointer(pinfo); Tower sTower = PickTowerInGrid(pointer); + + // 泡泡禁锢状态不允许置换 + if (sTower && sTower.IsStartBondage) return false; if (sTower && sTower != towerToMove) { @@ -754,6 +773,27 @@ } } return ""; + } + + /// <summary> + /// 提升所有塔的等级,如果现在塔的等级 < level,设置等级为 level,如果 > level 不做改变 + /// </summary> + /// <param name="level">从0开始</param> + public void UpgradeAllTowerMinLevel(int level) + { + if (level < 0 || level > ElfUpgradeData.MaxTowerLevel - 1) return; + + for (int i = 0; i < m_listTower.Count; ++i) + { + if (m_listTower[i].currentLevel < level) + { + m_listTower[i].currentLevel = level; + m_listTower[i].CurrentTowerLevel.SetShowLevel(level + 1); + m_listTower[i].CurrentTowerLevel.SetScale(level + 1); + PlayUpgradeEffect(m_listTower[i]); + } + } + UpdateMinLevelArr(); } /// <summary> @@ -863,6 +903,7 @@ EndlessBossSkillManager.instance.ClearSkillList(); EndlessBossHPManager.instance.SwitchHP(true); EndlessBossHPManager.instance.SetCurrentHP(0); + EndlessLevelManager.instance.WaveManager.HideTunel(); // 停止所有兵线的出兵 for (int i = 0; i < TotalWaveLines; ++i) @@ -1004,14 +1045,14 @@ if (bInAttackModeTower == null) { bInAttackModeTower = checkTowerPlaceTower; - bInAttackModeTower.currentTowerLevel.SetCanPlace(true); + bInAttackModeTower.CurrentTowerLevel.SetCanPlace(true); } else if (bInAttackModeTower != checkTowerPlaceTower) { - bInAttackModeTower.currentTowerLevel.SetCanPlace(false); + bInAttackModeTower.CurrentTowerLevel.SetCanPlace(false); bInAttackModeTower = checkTowerPlaceTower; - bInAttackModeTower.currentTowerLevel.SetCanPlace(true); + bInAttackModeTower.CurrentTowerLevel.SetCanPlace(true); } } @@ -1023,14 +1064,14 @@ if (bInAttackModeTower == null) { bInAttackModeTower = checkTowerPlaceTower; - bInAttackModeTower.currentTowerLevel.SetCanPlace(true); + bInAttackModeTower.CurrentTowerLevel.SetCanPlace(true); } else if (bInAttackModeTower != checkTowerPlaceTower) { - bInAttackModeTower.currentTowerLevel.SetCanPlace(false); + bInAttackModeTower.CurrentTowerLevel.SetCanPlace(false); bInAttackModeTower = checkTowerPlaceTower; - bInAttackModeTower.currentTowerLevel.SetCanPlace(true); + bInAttackModeTower.CurrentTowerLevel.SetCanPlace(true); } } } @@ -1064,12 +1105,12 @@ } } - void CloseCanPlace() + public void CloseCanPlace() { dragTowerPlacement.CloseCanPlace(); if (bInAttackModeTower != null) { - bInAttackModeTower.currentTowerLevel.SetCanPlace(false); + bInAttackModeTower.CurrentTowerLevel.SetCanPlace(false); bInAttackModeTower = null; } } @@ -1125,6 +1166,15 @@ #endregion /// <summary> + /// 推拽结束,如果判断HasTower==true 就强行释放 + /// </summary> + public void EndDragCancelPlaceTower() + { + Debug.Log("强行释放了m_CurrentTower"); + CancelPlaceTower(null); + } + + /// <summary> /// 拖动一个Tower之后,松开鼠标或者EndDrag. /// 1: 目标点可合成,则直接合成。 /// 2: 目标点不管是空白,还是不能放置Tower,都要让当前的Tower返回到原来的TowerPlace @@ -1162,7 +1212,7 @@ } else { - GuideCtrl.Ins.EndDrag11_1(); + GuideCtrl.Ins.EndDrag5_1(); CancelPlaceTower(pointerInfo); Debug.Log("没有放置在火塔上"); } @@ -1178,7 +1228,7 @@ } else if (isFreeAttackGrid(pointerInfo) && !bSkill) { - if (!TryPlaceTower(pointerInfo, false, true)) + if (!TryPlaceTower(pointerInfo, false)) { CancelPlaceTower(pointerInfo); Debug.Log("这里需要返回原位"); @@ -1193,10 +1243,14 @@ towerToMove.Sell(); towerToMove = null; } + if (m_CurrentTower != null && m_CurrentTower.controller != null) + Destroy(m_CurrentTower.controller.gameObject); } else if (EndlessLevelManager.instanceExists && IsSubstitute(pointerInfo)) { CheckCanChangePos(pointerInfo); + if (EndlessUIStart.instance.GameStartTime >= JsonDataCenter.DOUBLE_GEM_TIME) + UpgradeAllTowerMinLevel(1); } // 当前是Skill塔位的状态. else if (bSkill) @@ -1268,6 +1322,9 @@ //强制交换塔的时候检查自身充能条 newTower1.CheckCtrl(); newTower2.CheckCtrl(); + //Debug.Log($"newTower1:{newTower1.towerName} newTower2:{newTower2.towerName}"); + + TowerPlacementGridEndless.instance.PlayPutPs(newTower2.gridPosition.x, newTower2.gridPosition.y); return true; } } @@ -1289,8 +1346,7 @@ Tower controller = currentTower.controller; Tower createdTower = Instantiate(controller); createdTower.PlayWaveLineFlash = playEffect; - createdTower.Initialize(m_CurrentArea, pos); - createdTower.SetLevel(level - 1); + createdTower.Initialize(m_CurrentArea, pos, level - 1); if (playEffect) PlayUpgradeEffect(createdTower); @@ -1319,7 +1375,7 @@ ray = m_Camera.ScreenPointToRay(tp.currentPosition) }; - int sId = towerToMove.attributeId; + int sId = towerToMove.ElfId; int sLevel = towerToMove.currentLevel; // 火是列攻击: @@ -1409,7 +1465,7 @@ /// Attempt to position a tower at the given location /// </summary> /// <param name="pointerInfo">The pointer we're using to position the tower</param> - public bool TryPlaceTower(PointerInfo pointerInfo, bool force = false, bool zeroCost = false) + public bool TryPlaceTower(PointerInfo pointerInfo, bool force = false) { UIPointer pointer = WrapPointer(pointerInfo); @@ -1420,7 +1476,7 @@ return false; } - return BuyTower(pointer, force, zeroCost); + return BuyTower(pointer, force); } /// <summary> @@ -1520,16 +1576,11 @@ { throw new InvalidOperationException("Selected Tower is null"); } - if (currentSelectedTower.isAtMaxLevel) + if (currentSelectedTower.IsMaxLevel) { return; } - int upgradeCost = currentSelectedTower.GetCostForNextLevel(); - bool successfulUpgrade = EndlessLevelManager.instance.Currency.TryPurchase(upgradeCost); - if (successfulUpgrade) - { - currentSelectedTower.UpgradeTower(); - } + currentSelectedTower.UpgradeTower(); DeselectTower(); } @@ -1546,7 +1597,7 @@ { throw new InvalidOperationException("Selected Tower is null"); } - if (currentSelectedTower.isAtMaxLevel) + if (currentSelectedTower.IsMaxLevel) return false; // 直接随机升级,零成本。 @@ -1586,15 +1637,10 @@ { throw new InvalidOperationException("Selected Tower is null"); } - int sellValue = currentSelectedTower.GetSellLevel(); - if (EndlessLevelManager.instanceExists && sellValue > 0) - { - EndlessLevelManager.instance.Currency.AddCurrency(sellValue); - currentSelectedTower.Sell(); + currentSelectedTower.Sell(); - // 从列表中删除Tower. - delTower(currentSelectedTower); - } + // 从列表中删除Tower. + delTower(currentSelectedTower); DeselectTower(); } @@ -1614,12 +1660,7 @@ { return; } - int cost = m_CurrentTower.controller.purchaseCost; - bool successfulPurchase = EndlessLevelManager.instance.Currency.TryPurchase(cost); - if (successfulPurchase) - { - PlaceTower(); - } + PlaceTower(); } /// <summary> @@ -1629,7 +1670,7 @@ /// Throws exception when not in a build mode or when tower is not a valid position /// </exception> /// </summary> - public bool BuyTower(UIPointer pointer, bool force = false, bool zeroCost = false) + public bool BuyTower(UIPointer pointer, bool force = false) { if (!isBuilding) return false; @@ -1678,10 +1719,7 @@ return false; } - int cost = m_CurrentTower.controller.purchaseCost; - if (zeroCost) - cost = 0; - bool successfulPurchase = EndlessLevelManager.instance.Currency.TryPurchase(cost); + bool successfulPurchase = EndlessLevelManager.instance.Currency.TryPurchase(0); if (successfulPurchase) { PlaceGhost(pointer); @@ -1696,28 +1734,8 @@ /// <param name="worldPos"></param> public void PlayUpgradeEffect(Tower newTower) { - newTower.currentTowerLevel.PlayUpGradeEffect(); - // GameObject effect = TowerUpgradeEffectPrefab; - - // if (newTower.towerFeature == EFeatureTower.NULL) - // { - // string path = $"UI/ToBattle_{newTower.attributeId}"; - // GameObject prefab = Resources.Load<GameObject>(path); - // effect = Instantiate(prefab); - // } - - // // 在sTower的位置播放升级特效 - // GameObject obj = Instantiate(effect); - // obj.transform.position = newTower.transform.position; - // Vector3 pos = obj.transform.position; - // pos.y += 5f; - // obj.transform.position = pos; - // ParticleSystem ps = obj.GetComponent<ParticleSystem>(); - - // if (ps == null) - // ps = obj.transform.GetChild(0).GetComponent<ParticleSystem>(); - // ps.Play(); - // Destroy(obj, ps.main.duration); + newTower.CurrentTowerLevel.PlayUpGradeEffect(); + AudioSourceManager.Ins.Play(AudioEnum.Upgrade); } /// <summary> @@ -1776,7 +1794,7 @@ if (m_CurrentTower == null || m_CurrentArea == null) return false; - return EndlessLevelManager.instance.Currency.CanAfford(m_CurrentTower.controller.purchaseCost); + return true; } /// <summary> @@ -2049,16 +2067,57 @@ if (tm) { tm.GetComponent<Transform>().SetParent(GameObject.Find("MainUI/TextPanel").GetComponent<Transform>(), true); - string bloodStr = ""; - if (doubleHit) - bloodStr += "Dble!"; - if (crit) - bloodStr += "Crt!"; - bloodStr += "-"; + string bloodStr = "-"; bloodStr += ((Int64)val).ToString(); tm.moveBloodText(spos.x, spos.y, bloodStr, crit); } + } + + /// <summary> + /// 减速飘字 + /// </summary> + public void FloatSlowDownWord(Vector3 worldPos) + { + Vector3 screenPos = m_Camera.WorldToScreenPoint(worldPos); + GameObject obj = Instantiate(SlowDownWord.gameObject); + obj.GetComponent<Transform>().SetParent(GameObject.Find("MainUI/TextPanel").GetComponent<Transform>(), false); + obj.GetComponent<TextMoveDoTween>().FloatSlowDownWord(screenPos.x, screenPos.y); + } + + /// <summary> + /// 暴击飘字 + /// </summary> + public void FloatCritWord(Vector3 worldPos) + { + Vector3 screenPos = m_Camera.WorldToScreenPoint(worldPos); + GameObject obj = Instantiate(CritWord.gameObject); + obj.GetComponent<Transform>().SetParent(GameObject.Find("MainUI/TextPanel").GetComponent<Transform>(), false); + obj.GetComponent<TextMoveDoTween>().FloatCritWord(screenPos.x, screenPos.y); + } + + /// <summary> + /// 冰冻飘字 + /// </summary> + /// <param name="worldPos"></param> + public void FloatFrostWord(Vector3 worldPos) + { + Vector3 screenPos = m_Camera.WorldToScreenPoint(worldPos); + GameObject obj = Instantiate(FrostWord.gameObject); + obj.GetComponent<Transform>().SetParent(GameObject.Find("MainUI/TextPanel").GetComponent<Transform>(), false); + obj.GetComponent<TextMoveDoTween>().FloatFrostWord(screenPos.x, screenPos.y); + } + + /// <summary> + /// 克制飘字 + /// </summary> + /// <param name="worldPos"></param> + public void FloatRestrainWord(Vector3 worldPos) + { + Vector3 screenPos = m_Camera.WorldToScreenPoint(worldPos); + GameObject obj = Instantiate(RestrainWord.gameObject); + obj.GetComponent<Transform>().SetParent(GameObject.Find("MainUI/TextPanel").GetComponent<Transform>(), false); + obj.GetComponent<TextMoveDoTween>().FloatRestrainWord(screenPos.x, screenPos.y); } private void Start() @@ -2233,6 +2292,9 @@ var controller = output.collider.GetComponent<Tower>(); if (controller != null) { + // 泡泡禁锢状态不允许拖动 + if (controller.IsStartBondage) return; + SelectTower(controller); } @@ -2240,7 +2302,21 @@ CalSelTowerScreenOffset(info, controller); } + public void OnPressed(PointerInfo info) + { + UIPointer uiPointer = WrapPointer(info); + RaycastHit output; + bool hasHit = Physics.Raycast(uiPointer.ray, out output, float.MaxValue, towerSelectionLayer); + if (uiPointer.overUI) return; + + if (hasHit) + { + Tower controller = output.collider.GetComponent<Tower>(); + if (controller != null) + controller.OnPressed(); + } + } /// <summary> /// 鼠标选中一个Tower的时候,计算当前鼠标位置与当前Tower位置在屏幕上坐标位置的偏移量。 @@ -2315,22 +2391,6 @@ m_Camera = GameObject.Find("SceneCamera3D").GetComponent<Camera>(); //m_Camera = GetComponent<Camera>(); TowerDestroyArr = new bool[5, AttackRowNumbers]; - } - - /// <summary> - /// 战场内所有的Tower实例都需要升级相关的数据. - /// 找到相同类型的所有Tower,然后进行局内升级的修改。 - /// </summary> - /// <param name="td"></param> - protected void towerUpgradeInBattle(TowerLevelUp tlu) - { - foreach (Tower tower in m_listTower) - { - if (tlu.towerName != tower.towerName) - continue; - tower.upGradeInSceneTL(); - } - return; } /// <summary> @@ -2566,12 +2626,11 @@ // Place the ghost Tower controller = m_CurrentTower.controller; Tower createdTower = Instantiate(controller); - createdTower.Initialize(m_CurrentArea, m_GridPosition); - createdTower.SetLevel(dragTowerLevel); + createdTower.Initialize(m_CurrentArea, m_GridPosition, dragTowerLevel); // ATTENTION TO FIX:是否应该加入List: addTower(createdTower); - PlayToAttackEffect(createdTower.attributeId, createdTower.transform.position); + PlayToAttackEffect(createdTower.ElfId, createdTower.transform.position); dragTowerLevel = 0; CancelGhostPlacement(); } @@ -2581,11 +2640,11 @@ /// <summary> /// 播放宝石上阵特效 /// </summary> - /// <param name="attributeId">101 火,105 水,109 木</param> + /// <param name="ElfId">101 火,201 水,301 木</param> /// <param name="worldPos">世界坐标</param> - public void PlayToAttackEffect(int attributeId, Vector3 worldPos) + public void PlayToAttackEffect(int ElfId, Vector3 worldPos) { - string path = $"UI/DengChang_{attributeId}"; + string path = $"UI/DengChang_{ElfId}"; GameObject prefab = Resources.Load<GameObject>(path); GameObject obj = Instantiate(prefab); -- Gitblit v1.9.1