Resolve WES-76 "87 themeselection"
This commit is contained in:
51
Assets/Common/Scripts/ThemeSelectionController.cs
Normal file
51
Assets/Common/Scripts/ThemeSelectionController.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for the theme selection screen
|
||||
/// </summary>
|
||||
public class ThemeSelectionController : MonoBehaviour
|
||||
{
|
||||
[Header("Theme Selection")]
|
||||
/// <summary>
|
||||
/// Theme prefab
|
||||
/// </summary>
|
||||
public GameObject themePrefab;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to container holding all theme-buttons
|
||||
/// </summary>
|
||||
public Transform themesContainer;
|
||||
|
||||
/// <summary>
|
||||
/// Function that is called upon loading the scene
|
||||
/// </summary>
|
||||
public 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>
|
||||
/// Function that is called upon a button click
|
||||
/// </summary>
|
||||
public void OnButtonClick(string clickedTheme)
|
||||
{
|
||||
PlayerPrefs.SetString("themeName", clickedTheme);
|
||||
SceneManager.LoadScene(PlayerPrefs.GetString("gamePath"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user