Resolve WES-43 "Minigame framework"
This commit is contained in:
42
Assets/SpellingBee/Scripts/ThemeSelectionController.cs
Normal file
42
Assets/SpellingBee/Scripts/ThemeSelectionController.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class ThemeSelectionController : MonoBehaviour
|
||||
{
|
||||
[Header("Theme Selection")]
|
||||
// Theme prefab
|
||||
public GameObject themePrefab;
|
||||
// Reference to container holding all theme-buttons
|
||||
public Transform themesContainer;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnButtonClick(string clickedTheme)
|
||||
{
|
||||
PlayerPrefs.SetString("themeName", clickedTheme);
|
||||
SceneManager.LoadScene("Game");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user