public virtual void Show(TowerAgent target) { if (target == null) { return; } myTower = target; AdjustPosition(); this.gameObject.SetActive(true); int sellValue = myTower.GetSellLevel(); if (upgradeButton != null) { upgradeButton.interactable = BattleField.instance.currency.CanAfford(myTower.GetCostForNextLevel()); bool maxLevel = target.isAtMaxLevel; upgradeButton.gameObject.SetActive(!maxLevel); if (!maxLevel) { //Debug.Log(target.GetNextUpgradeAgents()[0].UpgradeDescription.ToUpper()); } } XEventBus.Instance.Register(EventId.CurrencyChanged, OnCurrencyChanged); }
public void TrySelectTarget(PointerInfo info) { if (state != State.Normal) { throw new InvalidOperationException("Trying to select towers outside of Normal state"); } UIPointer uiPointer = WrapPointer(info); if (uiPointer.overUI) { return; } RaycastHit hit; if (Physics.Raycast(uiPointer.ray, out hit, float.MaxValue)) { switch (hit.collider.tag) { case "Tower": case "Enemy": XEventBus.Instance.Post(EventId.UserClick, new XEventArgs(hit.collider.gameObject)); TowerAgent tower = hit.collider.GetComponent <TowerAgent>(); if (tower != null) { SelectTarget(tower); } break; } } }
public void DeselectTarget(bool isRemoveSelectTarget = false) { if (state != State.Normal) { throw new InvalidOperationException("Trying to deselect tower whilst not in Normal state"); } if (currentSelectedTarget != null) { currentSelectedTarget.removed -= OnTargetDied; currentSelectedTarget.Show(); if (isRemoveSelectTarget) { currentSelectedTarget.Sell(); } } currentSelectedTarget = null; if (selectionChanged != null) { selectionChanged(null); } radiusVisualizerController.HideRadiusVisualizers(); }
public virtual void Hide() { myTower = null; if (GameUIManager.instanceExists) { GameUIManager.instance.HideRadiusVisualizer(); } this.gameObject.SetActive(false); XEventBus.Instance.UnRegister(EventId.CurrencyChanged, OnCurrencyChanged); }
protected virtual void OnUISelectionChanged(TowerAgent target) { if (target != null) { Show(target); } else { Hide(); } }
public void SelectTarget(TowerAgent target) { if (state != State.Normal) { throw new InvalidOperationException("Trying to select whilst not in a normal state"); } DeselectTarget(); currentSelectedTarget = target; if (currentSelectedTarget != null) { currentSelectedTarget.removed += OnTargetDied; } MonsterCfg monster = target.currentTargetLevelData.monster; radiusVisualizerController.SetupRadiusVisualizers(monster, target.transform); if (selectionChanged != null) { selectionChanged(target); } }
protected void PlaceTargetGhost(UIPointer pointer) { if (m_CurrentGhost == null || !isBuilding) { throw new InvalidOperationException( "Trying to position a Target ghost while the UI is not currently in a building state."); } MoveGhost(pointer); if (m_CurrentArea != null) { bool isFits = IsGhostAtValidPosition(); if (isFits) { if (currentSelectedTarget) { currentSelectedTarget.UpdateTargetPos(m_CurrentArea, m_GridPosition); currentSelectedTarget.Show(); CancelGhostPlacement(); } else { int cost = m_CurrentGhost.defaultLevel.Cost; bool successfulPurchase = BattleField.instance.currency.TryPurchase(cost); if (successfulPurchase) { GameObject createdTarget = Instantiate(Resources.Load <GameObject>("Prefab/Game/Tower"), m_CurrentArea.transform); TowerAgent tower = createdTarget.GetComponent <TowerAgent>(); object[] myObjArray = { m_CurrentArea, m_GridPosition }; tower.Initialize(m_CurrentGhost.towerId, myObjArray); CancelGhostPlacement(); } else { KindlyReminderUI.instance.ShowTip(new ShowTipParams { msg = "金币不足" }); CancelGhostPlacement(); } } } else { if (!currentSelectedTarget) { return; } currentSelectedTarget.UpdateTargetPos(m_CurrentArea, m_GridPosition); currentSelectedTarget.Show(); CancelGhostPlacement(); Tower target = m_CurrentArea.GetController().GetComponent <Tower>(); if (target != currentSelectedTarget) { if (target.currentLevel == currentSelectedTarget.currentLevel) { if (!target.isAtMaxLevel) { int upgradeCost = target.GetCostForNextLevel(); bool successfulUpgrade = BattleField.instance.currency.TryPurchase(upgradeCost); if (successfulUpgrade) { target.UpgradeTarget(); CancelGhostPlacement(true); } else { KindlyReminderUI.instance.ShowTip(new ShowTipParams { msg = "没钱升什么级" }); CancelGhostPlacement(); } } else { KindlyReminderUI.instance.ShowTip(new ShowTipParams { msg = "炮台已经是最高等级了" }); } } else { CancelGhostPlacement(); KindlyReminderUI.instance.ShowTip(new ShowTipParams { msg = "不是同一级别的炮台" }); } } else { CancelGhostPlacement(); } } } }