Started implementing TriviaWindow
This commit is contained in:
53
Assets/Scripts/Windows/TriviaWindow.cs
Normal file
53
Assets/Scripts/Windows/TriviaWindow.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace InterfaceOff
|
||||
{
|
||||
[System.Serializable] public struct TriviaQuestion
|
||||
{
|
||||
public string question;
|
||||
public string[] choices;
|
||||
public string answer;
|
||||
}
|
||||
|
||||
[System.Serializable] public struct TriviaSet
|
||||
{
|
||||
public TriviaQuestion[] questions;
|
||||
}
|
||||
|
||||
public class TriviaWindow : WindowBase
|
||||
{
|
||||
private static TriviaSet Trivia;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||
private static void LoadTriviaSet()
|
||||
{
|
||||
string path = Application.dataPath + "/Resources/Trivia.json";
|
||||
string json = File.ReadAllText(path);
|
||||
|
||||
Trivia = JsonUtility.FromJson<TriviaSet>(json);
|
||||
|
||||
string longest = "";
|
||||
int length = 0;
|
||||
|
||||
foreach (TriviaQuestion question in Trivia.questions)
|
||||
{
|
||||
if (length < question.question.Length)
|
||||
{
|
||||
length = question.question.Length;
|
||||
longest = question.question;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log(longest);
|
||||
}
|
||||
|
||||
public override void OnWindowInstantiation()
|
||||
{
|
||||
TriviaQuestion question = Trivia.questions[Random.Range(0, Trivia.questions.Length)];
|
||||
Components.InfoText.text = question.question;
|
||||
|
||||
Components.SetWidth(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user