| | |
| | | using DG.Tweening; |
| | | using JetBrains.Annotations; |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using TMPro; |
| | | using TowerDefense.Level; |
| | |
| | | using UnityEngine.EventSystems; |
| | | using UnityEngine.UI; |
| | | using TowerDefense.Nodes; |
| | | using TowerDefense.Affectors; |
| | | using KTGMGemClient; |
| | | |
| | | namespace TowerDefense.UI.HUD |
| | | { |
| | |
| | | // 测试屏幕显示相关的倒计时. |
| | | protected bool bLoaded = false; |
| | | |
| | | private Timer overTimer; |
| | | |
| | | /// <summary> |
| | | /// 总兵线数 |
| | | /// </summary> |
| | |
| | | /// 所有攻击塔位的摧毁信息,是否被摧毁,默认全部没有被摧毁 |
| | | /// </summary> |
| | | private bool[,] TowerDestroyArr; |
| | | |
| | | public event Action GameOverEvent; |
| | | |
| | | /// <summary> |
| | | /// 塔升级特效预制体 |
| | | /// </summary> |
| | | public GameObject TowerUpgradeEffectPrefab; |
| | | |
| | | /// <summary> |
| | | /// 宝石出现特效预制体 |
| | | /// </summary> |
| | | public GameObject TowerAppearEffectPrefab; |
| | | |
| | | public IPlacementArea selfTowerPlaceArea |
| | | { |
| | |
| | | public bool towerInList(Tower t) |
| | | { |
| | | return m_listTower.Contains(t); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置已经上阵的所有塔的攻击状态,是否可以攻击 |
| | | /// </summary> |
| | | /// <param name="canAttack"></param> |
| | | public void SetAttackingTowerState(bool canAttack) |
| | | { |
| | | foreach (Tower tower in m_listTower) |
| | | { |
| | | tower.bInAttackMode = canAttack; |
| | | } |
| | | } |
| | | |
| | | public void delTower(Tower t) |
| | |
| | | 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); |
| | |
| | | } |
| | | |
| | | TowerDestroyArr[xidx, i] = true; |
| | | Tower tower = FindTowerWithGridIdx(xidx, i); |
| | | Tower tower = FindTowerWithGridIdx(xidx, 3 - i); |
| | | |
| | | if (tower) |
| | | { |
| | |
| | | // 红心减少逻辑 |
| | | // HealthHeartState.instance.killHeart(false); |
| | | GameOver(); |
| | | overTimer = new Timer(1.2f, SafelyCallGameOverEvent); |
| | | } |
| | | } |
| | | |
| | | private void SafelyCallGameOverEvent() |
| | | { |
| | | if (GameOverEvent != null) |
| | | GameOverEvent(); |
| | | overTimer = null; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | CancelPlaceTower(pointerInfo); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 强制放置塔,主要是用于新手 |
| | | /// </summary> |
| | | /// <param name="newTower"></param> |
| | | /// <param name="pos"></param> |
| | | /// <param name="level">塔的等级</param> |
| | | public void PlaceTowerForce(Tower newTower, IntVector2 pos, int level) |
| | | { |
| | | TowerPlacementGhost currentTower = Instantiate(newTower.towerGhostPrefab); |
| | | currentTower.Initialize(newTower); |
| | | Tower controller = currentTower.controller; |
| | | Tower createdTower = Instantiate(controller); |
| | | createdTower.Initialize(m_CurrentArea, pos); |
| | | createdTower.SetLevel(level - 1); |
| | | |
| | | addTower(createdTower); |
| | | Destroy(currentTower.gameObject); |
| | | } |
| | | |
| | | protected bool SkillPlayEndDrag(PointerInfo pointer) |
| | | { |
| | | // 我操,终于可以了!ATTENTION TO OPP: |
| | |
| | | // 播放特效,并处理伤害. |
| | | EndlessWaveLineManager.instance.PlayWaveLineEffect(selEff.waveLineId); |
| | | AgentInsManager.instance.ExecWavelineAttack(selEff.waveLineId, sId, sLevel, false); |
| | | ++GameConfig.EndlessPortUseSkillTowerCount; |
| | | return true; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放升级特效 |
| | | /// </summary> |
| | | /// <param name="worldPos"></param> |
| | | public void PlayUpgradeEffect(Tower newTower) |
| | | { |
| | | 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); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Deselect the current tower and hides the UI |
| | | /// </summary> |
| | | public void DeselectTower() |
| | |
| | | /// <exception cref="InvalidOperationException"> |
| | | /// Throws exception if not in Build State or <see cref="m_CurrentTower"/> is not at a valid position |
| | | /// </exception> |
| | | public void PlaceTower(int lvl = 0, bool opponent = false) |
| | | public void PlaceTower(int lvl = 0, bool isUpgrade = false, bool opponent = false) |
| | | { |
| | | if (!isBuilding) |
| | | throw new InvalidOperationException("Trying to place tower when not in a Build Mode"); |
| | |
| | | |
| | | // River: 内部缓存数据,用于后期容易找到数据. |
| | | addTower(createdTower); |
| | | |
| | | CancelGhostPlacement(); |
| | | if (!isUpgrade) |
| | | PlayAppearEffect(createdTower.transform.position); |
| | | else |
| | | PlayUpgradeEffect(createdTower); |
| | | |
| | | // 处理成长骰子,复制骰子等等功能. |
| | | if (lvl == 0) |
| | | { |
| | | ProcessFeatureTower(createdTower); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放宝石出现特效 |
| | | /// </summary> |
| | | public void PlayAppearEffect(Vector3 worldPos) |
| | | { |
| | | GameObject obj = Instantiate(TowerAppearEffectPrefab); |
| | | obj.transform.position = worldPos; |
| | | 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); |
| | | } |
| | | |
| | | protected void ProcessFeatureTower(Tower ctower) |
| | |
| | | /// 直接在IPlaceArea上随机放置一个Tower。这是随机放置塔防的入口类。这是入口的塔防类。 |
| | | /// </summary> |
| | | /// <param name="tow"></param> |
| | | public bool RandomPlaceTower(Tower tow, int posx = -1, int posy = -1, int lvl = 0, int forceCost = -1) |
| | | public bool RandomPlaceTower(Tower tow, int posx = -1, int posy = -1, int lvl = 0, int forceCost = -1, bool isUpgrade = false) |
| | | { |
| | | // 获取IPlaceArea. |
| | | if (m_CurrentArea == null) |
| | |
| | | int cost = TowerPrice.instance.currentTowerPrice; |
| | | if (zeroCost) |
| | | cost = 0; |
| | | |
| | | |
| | | if (forceCost != -1) |
| | | cost = forceCost; |
| | | |
| | |
| | | m_CurrentTower.Show(); |
| | | if (successfulPurchase) |
| | | { |
| | | ++GameConfig.EndlessBuyTowerCount; |
| | | // 删除towerToMove,确保塔防数据不再出现多个 |
| | | if (zeroCost && (towerToMove != null)) |
| | | { |
| | |
| | | OnSuccessBuyTower(); |
| | | SetState(State.Building); |
| | | |
| | | PlaceTower(lvl); |
| | | PlaceTower(lvl, isUpgrade); |
| | | } |
| | | |
| | | |
| | | return true; |
| | | } |
| | | |
| | |
| | | |
| | | // ATTENTION TO FIX:是否应该加入List: |
| | | addTower(createdTower); |
| | | PlayToAttackEffect(createdTower.attributeId, createdTower.transform.position); |
| | | dragTowerLevel = 0; |
| | | CancelGhostPlacement(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放宝石上阵特效 |
| | | /// </summary> |
| | | /// <param name="attributeId">101 火,105 水,109 木</param> |
| | | /// <param name="worldPos">世界坐标</param> |
| | | public void PlayToAttackEffect(int attributeId, Vector3 worldPos) |
| | | { |
| | | string path = $"UI/ToBattle_{attributeId}"; |
| | | GameObject prefab = Resources.Load<GameObject>(path); |
| | | GameObject obj = Instantiate(prefab); |
| | | obj.transform.position = worldPos; |
| | | 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); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | private void Update() |
| | | { |
| | | if (overTimer != null) |
| | | overTimer.Tick(Time.deltaTime); |
| | | |
| | | for (int ti = listTowerTimer.Count - 1; ti >= 0; ti--) |
| | | { |
| | | // 如果执行到,会在DelTower函数内删除对应的listTowerTimer. |