104 lines
3.5 KiB
C#
104 lines
3.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class RQNA_Manager : MonoBehaviour
|
|
{
|
|
public static RQNA_Manager instance;
|
|
public GameObject answerPrefab, questionPrefab;
|
|
public Transform answerPanel, questionPanel;
|
|
public List<RQNA_QuestionClass> questions = new List<RQNA_QuestionClass>();
|
|
public int answered = 0;
|
|
|
|
public void Awake()
|
|
{
|
|
instance = this;
|
|
answerPanel = GameObject.Find("AnswerPanel").transform;
|
|
questionPanel = GameObject.Find("QuestionPanel").transform;
|
|
SetupQuestion();
|
|
SetupAnswer();
|
|
GameControl.instance.StartedGame();
|
|
}
|
|
|
|
public void SetupQuestion()
|
|
{
|
|
List<int> usableNumbers = new List<int>();
|
|
for (int n = 0; n < questions.Count; n++)
|
|
{
|
|
usableNumbers.Add(n);
|
|
}
|
|
for(int i = 0; i < questions.Count; i++)
|
|
{
|
|
int rng = Random.Range(0,usableNumbers.Count);
|
|
int toUse = usableNumbers[rng];
|
|
RQNA_Dropper temp = Instantiate(questionPrefab, questionPanel, false).GetComponent<RQNA_Dropper>();
|
|
temp.Setup(questions[toUse].questionStr,toUse,questions[i].answer.Count);
|
|
usableNumbers.RemoveAt(rng);
|
|
}
|
|
}
|
|
|
|
public void SetupAnswer()
|
|
{
|
|
List<int> usableNumbers = new List<int>();
|
|
if (questions[0].answer.Count > 1)
|
|
{
|
|
List<List<int>> questionNumbers = new List<List<int>>();
|
|
for (int n = 0; n < questions.Count; n++)
|
|
{
|
|
List<int> empty = new List<int>();
|
|
questionNumbers.Add(empty);
|
|
for (int a = 0; a < questions[n].answer.Count; a++)
|
|
{
|
|
questionNumbers[n].Add(a);
|
|
}
|
|
}
|
|
List<int> usableIndex = new List<int>();
|
|
for (int i = 0; i < questionNumbers.Count; i++)
|
|
{
|
|
usableIndex.Add(i);
|
|
}
|
|
for (int b = 0; b < questions[0].answer.Count * questions.Count; b++)
|
|
{
|
|
int rng = Random.Range(0, usableIndex.Count);
|
|
int usedInd = usableIndex[rng];
|
|
List<int> toUse = questionNumbers[usedInd];
|
|
int rng2 = Random.Range(0, toUse.Count);
|
|
int toUse2 = toUse[rng2];
|
|
RQNA_Dragger temp = Instantiate(answerPrefab, answerPanel, false).GetComponent<RQNA_Dragger>();
|
|
temp.Setup(questions[usedInd].answer[toUse2], usedInd);
|
|
questionNumbers[usedInd].RemoveAt(rng2);
|
|
Debug.Log("Spawned " + toUse2 + " answer from group " + usedInd);
|
|
if(questionNumbers[usedInd].Count == 0)
|
|
{
|
|
usableIndex.RemoveAt(rng);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int n = 0; n < questions.Count; n++)
|
|
{
|
|
usableNumbers.Add(n);
|
|
}
|
|
for (int n = 0; n < questions.Count; n++)
|
|
{
|
|
int rng = Random.Range(0, usableNumbers.Count);
|
|
int toUse = usableNumbers[rng];
|
|
RQNA_Dragger temp = Instantiate(answerPrefab, answerPanel, false).GetComponent<RQNA_Dragger>();
|
|
temp.Setup(questions[toUse].answer[0], toUse);
|
|
usableNumbers.RemoveAt(rng);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void CorrectAnswer()
|
|
{
|
|
answered++;
|
|
if (answered == questions.Count * questions[0].answer.Count)
|
|
{
|
|
GameControl.instance.FinishGame();
|
|
}
|
|
}
|
|
}
|