Files
unity-application/Assets/Common/Scripts/ThemeItem.cs
2023-04-30 15:51:41 +00:00

66 lines
1.8 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Handles the display of themes in the ThemeSelectionController scene
/// </summary>
public class ThemeItem : MonoBehaviour
{
/// <summary>
/// Reference to the theme object
/// </summary>
public Theme theme;
/// <summary>
/// Reference to the minigame list
/// </summary>
public MinigameList minigameList;
/// <summary>
/// UI reference to the gameobject for displaying the theme title
/// </summary>
public TMP_Text title;
/// <summary>
/// UI reference to the gameobject for displaying the description
/// </summary>
public TMP_Text description;
/// <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 ThemeItem object and update its appearance
/// </summary>
public void GenerateContent()
{
// Set appearance
title.text = theme.title;
// TODO: make description only visible when hovering
description.text = theme.description;
// Add click functionality
button.onClick.AddListener(() =>
{
//PlayerPrefs.SetString("gamePath", minigame.minigameEntryPoint);
Minigame minigame = minigameList.minigames[minigameList.currentMinigameIndex];
minigame.themeList.SetCurrentTheme(theme.themeIndex);
SystemController.GetInstance().SwapScene(minigame.minigameEntryPoint);
});
}
}