Resolve WES-76 "87 themeselection"

This commit is contained in:
Lukas Van Rossem
2023-03-13 21:49:40 +00:00
parent 94ec7e0359
commit a267301ab6
23 changed files with 141 additions and 893 deletions

View File

@@ -125,7 +125,6 @@ public class GameController : MonoBehaviour
/// </summary>
private DateTime startTime;
/// <summary>
/// Reference to the user list to access the current user
/// </summary>

View File

@@ -4,17 +4,32 @@ using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class SpellingBeeWebcam : MonoBehaviour
{
{
/// <summary>
/// Index of the current camera
/// </summary>
int camdex = 0;
/// <summary>
/// Texture to paste on the display
/// </summary>
WebCamTexture tex;
/// <summary>
/// Display for the video feed
/// </summary>
public RawImage display;
/// <summary>
/// For later use
/// </summary>
public TextMeshProUGUI dynamic;
/// <summary>
/// Initialize the camera view
/// </summary>
void Awake()
{
//popup.SetActive(false);
WebCamDevice device = WebCamTexture.devices[camdex];
tex = new WebCamTexture(device.name);
display.texture = tex;
@@ -22,6 +37,9 @@ public class SpellingBeeWebcam : MonoBehaviour
tex.Play();
}
/// <summary>
/// Switch to a different webcam
/// </summary>
public void SwapCam()
{
if (WebCamTexture.devices.Length > 0)
@@ -44,7 +62,9 @@ public class SpellingBeeWebcam : MonoBehaviour
}
}
// Scene changing is implemented here to avoid problems with webcam
/// <summary>
/// Scene changing is implemented here to avoid problems with webcam
/// </summary>
public void LoadScene(string sceneName)
{
display.texture = null;
@@ -53,24 +73,4 @@ public class SpellingBeeWebcam : MonoBehaviour
SceneManager.LoadScene(sceneName);
}
/*
public void Show_feedback(){
if(popup.activeSelf){
dynamic.text = "";
popup.SetActive(false);
return;
}
double index = UnityEngine.Random.value;
if(index < 0.5){
dynamic.text = "Poor";
}
else if(index > 0.8){
dynamic.text = "Excellent";
}
else{
dynamic.text = "Good";
}
popup.SetActive(true);
}
*/
}

View File

@@ -1,65 +0,0 @@
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
/// <summary>
/// Handles the display of themes in the ThemeSelectionController scene
/// </summary>
public class ThemeItem : MonoBehaviour
{
/// <summary>
/// The theme title
/// </summary>
public string themeTitle;
/// <summary>
/// A short description of the theme
/// </summary>
public string themeDescription;
/// <summary>
/// The callback function to start the game with the correct theme loaded
/// </summary>
public UnityAction startGameCallback;
/// <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 = themeTitle;
// TODO: make description only visible when hovering
description.text = themeDescription;
// Add click functionality
button.onClick.AddListener(startGameCallback);
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 4446e36fb27e24d4781dc866e8487e6b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,27 +0,0 @@
using UnityEngine;
// JSON structure containing all themes/words
[System.Serializable]
public class ThemeList
{
public Theme[] themes;
}
// Object representing part of the JSON containing word data
[System.Serializable]
public class Theme
{
public string name;
public string description;
public string[] words;
}
public class ThemeLoader : MonoBehaviour
{
// Loads the JSON file containing all of the themes
public static ThemeList LoadJson()
{
TextAsset themeJson = Resources.Load<TextAsset>("SpellingBee/words");
return JsonUtility.FromJson<ThemeList>(themeJson.text);
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 3e90cb50d2bd06aa382940db9c8c2810
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,38 +0,0 @@
using UnityEngine;
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");
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 68caaa5508a4d40448b47630ff86f035
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: