using Core.Game; using TowerDefense.Game; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.SceneManagement; using UnityEngine.UI; namespace TowerDefense.UI { /// /// The button for selecting a level /// [RequireComponent(typeof(Button))] public class LevelSelectButton : MonoBehaviour, ISelectHandler { /// /// Reference to the required button component /// protected Button m_Button; /// /// The UI text element that displays the name of the level /// public Text titleDisplay; public Text description; public Sprite starAchieved; public Image[] stars; protected MouseScroll m_MouseScroll; /// /// The data concerning the level this button displays /// protected LevelItem m_Item; /// /// When the user clicks the button, change the scene /// public void ButtonClicked() { ChangeScenes(); } /// /// A method for assigning the data from item to the button /// /// /// The data with the information concerning the level /// public void Initialize(LevelItem item, MouseScroll mouseScroll) { LazyLoad(); if (titleDisplay == null) { return; } m_Item = item; titleDisplay.text = item.name; description.text = item.description; HasPlayedState(); m_MouseScroll = mouseScroll; } /// /// Configures the feedback concerning if the player has played /// protected void HasPlayedState() { GameManager gameManager = GameManager.instance; if (gameManager == null) { return; } int starsForLevel = gameManager.GetStarsForLevel(m_Item.id); for (int i = 0; i < starsForLevel; i++) { stars[i].sprite = starAchieved; } } /// /// Changes the scene to the scene name provided by m_Item /// protected void ChangeScenes() { SceneManager.LoadScene(m_Item.sceneName); } /// /// Ensure is not null /// protected void LazyLoad() { if (m_Button == null) { m_Button = GetComponent