/// <summary> /// Define the button information for the tower /// </summary> /// <param name="towerData"> /// The tower to initialize the button with /// </param> public void InitializeButton(TowerYfb towerData) { m_Tower = towerData; if (towerData.levels.Length > 0) { TowerLevelYfb firstTower = towerData.levels[0]; buttonText.text = firstTower.cost.ToString(); towerIcon.sprite = firstTower.levelData.icon; } else { Debug.LogWarning("[Tower Spawn Button] No level data for tower"); } if (LevelManagerYfb.instanceExists) { m_Currency = LevelManagerYfb.instance.currency; m_Currency.currencyChanged += UpdateButton; } else { Debug.LogWarning("[Tower Spawn Button] No level manager to get currency object"); } UpdateButton(); }
/// <summary> /// Place the ghost at the pointer's position /// </summary> /// <param name="pointer">The pointer to place the ghost at</param> /// <exception cref="InvalidOperationException"> /// If we're not in the correct state /// </exception> protected void PlaceGhost(UIPointer pointer) { if (m_CurrentTower == null || !isBuilding) { throw new InvalidOperationException( "Trying to position a tower ghost while " + " the UI is not currently in a building state."); } MoveGhost(pointer); if (m_CurrentArea != null) { TowerFitStatus fits = m_CurrentArea.Fits( m_GridPosition, m_CurrentTower.controller.dimensions); if (fits == TowerFitStatus.Fits) { // Place the ghost TowerYfb controller = m_CurrentTower.controller; TowerYfb createdTower = Instantiate(controller); createdTower.Initialize(m_CurrentArea, m_GridPosition); CancelGhostPlacement(); } } }
/// <summary> /// Hides the tower info UI and the radius visualizer /// </summary> public virtual void Hide() { m_Tower = null; //if (GameUIYfb.instanceExists) //{ // GameUIYfb.instance.HideRadiusVisualizer(); //} m_Canvas.enabled = false; //LevelManagerYfb.instance.currency.currencyChanged -= OnCurrencyChanged; }
/// <summary> /// Fires when tower is selected/deselected /// </summary> /// <param name="newTower"></param> protected virtual void OnUISelectionChanged(TowerYfb newTower) { if (newTower != null) { Show(newTower); } else { Hide(); } }
/// <summary> /// Initialize this ghost /// </summary> /// <param name="tower">The tower controller we're a ghost of</param> public virtual void Initialize(TowerYfb tower) { m_MeshRenderers = GetComponentsInChildren <MeshRenderer>(); controller = tower; //if (GameUIYfb.instanceExists) //{ // GameUIYfb.instance.SetupRadiusVisualizer(controller, transform); //} ghostCollider = GetComponent <Collider>(); m_MoveVel = Vector3.zero; m_ValidPos = false; }
/// <summary> /// Sets the UI into a build state for a given tower /// </summary> /// <param name="towerToBuild"> /// The tower to build /// </param> /// <exception cref="InvalidOperationException"> /// Throws exception trying to enter Build Mode when not in Normal Mode /// </exception> public void SetToBuildMode([NotNull] TowerYfb towerToBuild) { if (state != State.Normal) { throw new InvalidOperationException("Trying to enter Build mode when not in Normal mode"); } if (m_CurrentTower != null) { // Destroy current ghost CancelGhostPlacement(); } SetUpGhostTower(towerToBuild); SetState(State.Building); }
/// <summary> /// Creates and hides the tower and shows the buildInfoUI /// </summary> /// <exception cref="ArgumentNullException"> /// Throws exception if the <paramref name="towerToBuild"/> is null /// </exception> void SetUpGhostTower([NotNull] TowerYfb towerToBuild) { if (towerToBuild == null) { throw new ArgumentNullException("towerToBuild"); } m_CurrentTower = Instantiate(towerToBuild.towerGhostPrefab); m_CurrentTower.Initialize(towerToBuild); m_CurrentTower.Hide(); //activate build info if (buildInfoUI != null) { buildInfoUI.Show(towerToBuild); } }
/// <summary> /// Activates the tower controller UI with the specific information /// </summary> /// <param name="tower"> /// The tower controller information to use /// </param> /// <exception cref="InvalidOperationException"> /// Throws exception when selecting tower when <see cref="State" /> does not equal <see cref="State.Normal" /> /// </exception> public void SelectTower(TowerYfb tower) { if (state != State.Normal) { throw new InvalidOperationException( "Trying to select whilst not in a normal state"); } DeselectTower(); currentSelectedTower = tower; if (currentSelectedTower != null) { currentSelectedTower.removed += OnTowerDied; } //radiusVisualizerController.SetupRadiusVisualizers(tower); if (selectionChanged != null) { selectionChanged(tower); } }
/// <summary> /// Shows the information /// </summary> /// <param name="controller"> /// The tower information to display /// </param> public virtual void Show(TowerYfb controller) { m_TowerUI.Show(controller); if (m_State == AnimationState.Shown) { return; } anim.Play(showClipName); if (m_State == AnimationState.Hiding) { anim[showClipName].normalizedTime = 1; m_State = AnimationState.Shown; return; } m_State = anim[showClipName].normalizedTime < 1 ? AnimationState.Showing : AnimationState.Shown; }
/// <summary> /// Draws the tower data on to the canvas, /// if the relevant text components are populated /// </summary> /// <param name="tower">The tower to gain info from</param> /// <param name="levelOfTower">The level of the tower</param> public void Show(TowerYfb tower, int levelOfTower) { if (levelOfTower >= tower.levels.Length) { return; } TowerLevelYfb towerLevel = tower.levels[levelOfTower]; DisplayText(towerName, tower.towerName); DisplayText(description, towerLevel.description); //DisplayText(dps, towerLevel.GetTowerDps().ToString("f2")); //DisplayText(health, string.Format("{0}/{1}", tower.configuration.currentHealth, towerLevel.maxHealth)); //DisplayText(level, (levelOfTower + 1).ToString()); //DisplayText(dimensions, string.Format("{0}, {1}", tower.dimensions.x, tower.dimensions.y)); //if (levelOfTower + 1 < tower.levels.Length) //{ // DisplayText(upgradeCost, tower.levels[levelOfTower + 1].cost.ToString()); //} //int sellValue = tower.GetSellLevel(levelOfTower); //DisplayText(sellPrice, sellValue.ToString()); }
/// <summary> /// Draws the tower data on to the canvas /// </summary> /// <param name="towerToShow"> /// The tower to gain info from /// </param> public virtual void Show(TowerYfb towerToShow) { if (towerToShow == null) { return; } m_Tower = towerToShow; AdjustPosition(); m_Canvas.enabled = true; int sellValue = m_Tower.GetSellLevel(); if (sellButton != null) { sellButton.gameObject.SetActive(sellValue > 0); } if (upgradeButton != null) { upgradeButton.interactable = LevelManagerYfb.instance.currency.CanAfford(m_Tower.GetCostForNextLevel()); bool maxLevel = m_Tower.isAtMaxLevel; upgradeButton.gameObject.SetActive(!maxLevel); if (!maxLevel) { upgradeDescription.text = m_Tower.levels[m_Tower.currentLevel + 1].upgradeDescription.ToUpper(); } } //LevelManagerYfb.instance.currency.currencyChanged += OnCurrencyChanged; towerInfoDisplay.Show(towerToShow); foreach (var button in confirmationButtons) { button.SetActive(false); } }
/// <summary> /// The text component for the description /// </summary> //public Text dps; /// <summary> /// The text component for the level /// </summary> //public Text level; /// <summary> /// The text component for the health /// </summary> //public Text health; /// <summary> /// The text component for the dimensions /// </summary> //public Text dimensions; /// <summary> /// The text component for the dimensions /// </summary> //public Text upgradeCost; /// <summary> /// The text component for the dimensions /// </summary> //public Text sellPrice; /// <summary> /// Draws the tower data on to the canvas, if the relevant text components are populated /// </summary> /// <param name="tower"> /// The tower to gain info from /// </param> public void Show(TowerYfb tower) { int levelOfTower = tower.currentLevel; Show(tower, levelOfTower); }