| | |
| | | using TowerDefense.Towers.Placement; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | using DG.Tweening; |
| | | |
| | | /// <summary> |
| | | /// 当前类用于开启新的TowerPlacementGrid,用于无尽模式。当前类附加在对应的购买开启按钮上。 |
| | |
| | | public class EndlessTowerGridOpen : MonoBehaviour |
| | | { |
| | | // 当前Button对应的Cash Text数据 |
| | | public TextMeshProUGUI cashText; |
| | | public TextMeshPro cashText; |
| | | |
| | | // 当前Button对应的image. |
| | | public Image mImage; |
| | |
| | | bWaitOpen = false; |
| | | } |
| | | |
| | | public void SetBuyBtnInfo(int x, int y, TowerPlacementGridEndless tpg) |
| | | /// <summary> |
| | | /// Subscribe to the level manager |
| | | /// </summary> |
| | | protected virtual void OnEnable() |
| | | { |
| | | if (EndlessLevelManager.instanceExists) |
| | | EndlessLevelManager.instance.Currency.currencyChanged += OnCurrencyChanged; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Unsubscribe from the level manager |
| | | /// </summary> |
| | | protected virtual void OnDisable() |
| | | { |
| | | if (EndlessLevelManager.instanceExists) |
| | | EndlessLevelManager.instance.Currency.currencyChanged -= OnCurrencyChanged; |
| | | } |
| | | |
| | | private void OnCurrencyChanged() |
| | | { |
| | | CheckCurrencyEnough(); |
| | | } |
| | | |
| | | public void CheckCurrencyEnough() |
| | | { |
| | | int result; |
| | | int.TryParse(cashText.text.ToString(), out result); |
| | | int current = EndlessLevelManager.instance.Currency.currentCurrency; |
| | | |
| | | if (current >= result) |
| | | cashText.color = new Color(1f, 1f, 1f); |
| | | else |
| | | cashText.color = new Color(0.5f, 0.5f, 0.5f); |
| | | } |
| | | |
| | | public void SetBuyBtnInfo(int x, int y, TowerPlacementGridEndless tpg, string cost) |
| | | { |
| | | gridX = x; |
| | | gridY = y; |
| | | towerGrid = tpg; |
| | | |
| | | TowerDefense.UI.HUD.PlacementTile tile = TowerPlacementGridEndless.instance.GetOneTile(x, y); |
| | | if (tile != null && tile.BuyMesh != null) |
| | | { |
| | | //cashText.gameObject.SetActive(false); |
| | | Transform ts = tile.BuyMesh.transform.Find("CashText"); |
| | | cashText = ts.GetComponent<TextMeshPro>(); |
| | | } |
| | | |
| | | cashText.SetText(cost); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | if (bWaitOpen) return; |
| | | |
| | | if (GameConfig.IsNewbie) |
| | | { |
| | | if (!GameConfig.CanOpenNewTower) return; |
| | | // if (GameConfig.IsNewbie) |
| | | // { |
| | | // if (!GameConfig.CanOpenNewTower) return; |
| | | |
| | | if (!isOpenTower) |
| | | { |
| | | isOpenTower = true; |
| | | EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.GetOneTowerPos); |
| | | } |
| | | } |
| | | // if (!isOpenTower) |
| | | // { |
| | | // isOpenTower = true; |
| | | // EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.GetOneTowerPos); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | if (towerGrid != null) |
| | | { |
| | | float cashToOpen = TowerPlacementGridEndless.GRID_OPENCASH; |
| | | if (EndlessLevelManager.instance.Currency.currentCurrency < cashToOpen) |
| | | { |
| | | AudioSourceManager.Ins.Play(AudioEnum.UIDisable); |
| | | cashText.color = new Color(218f / 255f, 32f / 255f, 32f / 255f); |
| | | DOTween.To(() => cashText.color, (Color v) => cashText.color = v, cashText.color, 0.2f) |
| | | .OnComplete(CheckCurrencyEnough); |
| | | return; |
| | | } |
| | | |
| | | // 减少Cash并开启相应塔防管理器的兵线 |
| | | bool bsucc = EndlessLevelManager.instance.Currency.TryPurchase((int)cashToOpen); |