51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// ThemeSelectionScreen scene manager
|
|
/// </summary>
|
|
public class ThemeSelectionScreen : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// Theme prefab
|
|
/// </summary>
|
|
public GameObject themePrefab;
|
|
|
|
/// <summary>
|
|
/// Reference to container holding all theme-buttons
|
|
/// </summary>
|
|
public Transform themesContainer;
|
|
|
|
/// <summary>
|
|
/// Start is called before the first frame update
|
|
/// </summary>
|
|
void Start()
|
|
{
|
|
// TODO: change to ScriptableObject
|
|
ThemeList themeList = ThemeLoader.LoadJson();
|
|
|
|
for (int i = 0; i < themeList.themes.Length; i++)
|
|
{
|
|
Theme theme = themeList.themes[i];
|
|
|
|
// First, you need to create a new button game object
|
|
GameObject instance = GameObject.Instantiate(themePrefab, themesContainer);
|
|
|
|
// Dynamically load appearance
|
|
ThemeItem item = instance.GetComponent<ThemeItem>();
|
|
item.themeTitle = theme.name;
|
|
item.themeDescription = theme.description;
|
|
item.startGameCallback = () => OnButtonClick(theme.name);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load the game with a specified theme
|
|
/// </summary>
|
|
/// <param name="clickedTheme">Name of the clicked theme</param>
|
|
public void OnButtonClick(string clickedTheme)
|
|
{
|
|
PlayerPrefs.SetString("themeName", clickedTheme);
|
|
SystemController.GetInstance().SwapScene(PlayerPrefs.GetString("gamePath"));
|
|
}
|
|
}
|