87 lines
2.3 KiB
C#
87 lines
2.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class UntangleManager : MonoBehaviour
|
|
{
|
|
public int gameMode = 0;
|
|
public List<UntangleQuestion> questions = new List<UntangleQuestion>();
|
|
public static UntangleManager instance;
|
|
public UntangleDrop dropTrans;
|
|
public Transform answerOrganizer;
|
|
public GameObject answerPrefab;
|
|
public Animator anim;
|
|
private int currentIndex;
|
|
|
|
void Awake()
|
|
{
|
|
instance = this;
|
|
BreakupAnswer();
|
|
SetupQuestion();
|
|
GameControl.instance.StartedGame();
|
|
}
|
|
|
|
public void BreakupAnswer()
|
|
{
|
|
for (int i = 0; i < questions.Count;i++)
|
|
{
|
|
string[] splittedAnswers = questions[i].questionStr.Split('%');
|
|
for (int n = 0; n < splittedAnswers.Length; n++)
|
|
{
|
|
questions[i].answers.Add(new UntangleQuestion.UntangleAnswer(splittedAnswers[n], n));
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OrganizeAnswer()
|
|
{
|
|
List<int> avaliable = new List<int>();
|
|
for (int n = 0; n < questions[currentIndex].answers.Count;n++)
|
|
{
|
|
avaliable.Add(n);
|
|
}
|
|
if (answerOrganizer.childCount > 0)
|
|
{
|
|
RemoveAnswers();
|
|
}
|
|
for (int i = 0; i < questions[currentIndex].answers.Count; i++)
|
|
{
|
|
int pickedR = Random.Range(0, avaliable.Count);
|
|
int pickedN = avaliable[pickedR];
|
|
Instantiate(answerPrefab, answerOrganizer, false).GetComponent<UntangleDrag>().SetupAnswer(questions[currentIndex].answers[pickedN],gameMode);
|
|
avaliable.RemoveAt(pickedR);
|
|
}
|
|
}
|
|
|
|
public void SetupQuestion()
|
|
{
|
|
dropTrans.ReceiveQuestion(questions[currentIndex]);
|
|
OrganizeAnswer();
|
|
}
|
|
|
|
public void RemoveAnswers()
|
|
{
|
|
int startN = answerOrganizer.childCount;
|
|
for(int i = 0; i < startN; i++)
|
|
{
|
|
Destroy(answerOrganizer.GetComponentsInChildren<UntangleDrag>()[i].gameObject);
|
|
}
|
|
}
|
|
|
|
public void NextQuestion()
|
|
{
|
|
anim.SetTrigger("Correct");
|
|
A10D1AudioSystem.instance.Correct();
|
|
currentIndex++;
|
|
if (currentIndex == questions.Count)
|
|
{
|
|
GameControl.instance.FinishGame();
|
|
}
|
|
else
|
|
{
|
|
SetupQuestion();
|
|
}
|
|
}
|
|
|
|
}
|