Files
unity-application/Assets/Common/Scripts/MinigameItem.cs
2023-03-19 17:37:50 +00:00

61 lines
1.6 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Handles the display of minigames in the ListMinigameScreen scene
/// </summary>
public class MinigameItem : MonoBehaviour
{
/// <summary>
/// Reference to the minigame object
/// </summary>
public Minigame minigame;
/// <summary>
/// UI Reference to the image for displaying the minigame thumbnail
/// </summary>
public Image thumbnail;
/// <summary>
/// The minigamelist, we need this to change the index of the selected minigame before changing scene.
/// </summary>
public MinigameList minigameList;
/// <summary>
/// UI Reference to the gameobject for displaying the minigame title
/// </summary>
public TMP_Text title;
/// <summary>
/// UI Reference to the button so the correct callback can be trigger on click
/// </summary>
public Button button;
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
// Use public function so that this component can get Instantiated
GenerateContent();
}
/// <summary>
/// (Re)generate the MinigameItem object and update its appearance
/// </summary>
public void GenerateContent()
{
// Set appearance
thumbnail.sprite = minigame.thumbnail;
title.text = minigame.title;
// Add click functionality
button.onClick.AddListener(() =>
{
minigameList.SetCurrentMinigame(minigame.index);
SystemController.GetInstance().LoadNextScene("Common/Scenes/MinigameActivityScreen");
});
}
}