72 lines
1.9 KiB
C#
72 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class QuestionHandler : MonoBehaviour
|
|
{
|
|
public GameObject managers;
|
|
private GameManager gameManager;
|
|
public TextMeshProUGUI explainText;
|
|
public PromptList promptList;
|
|
private List<Question> player2questions;
|
|
private int currentQuestion = 1;
|
|
|
|
void OnEnable()
|
|
{
|
|
gameManager = managers.GetComponent<GameManager>();
|
|
player2questions = gameManager.myRoom.GetQuestionsByPlayer(gameManager.currentPlayer);
|
|
Redraw(currentQuestion);
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
player2questions = null;
|
|
currentQuestion = 1;
|
|
}
|
|
|
|
void Redraw(int currentQuestion)
|
|
{
|
|
Prompt prompt = promptList.prompts.Find(x => x.id == player2questions[currentQuestion - 1].promptId);
|
|
Debug.Log(JsonUtility.ToJson(prompt));
|
|
explainText.SetText(prompt.en);
|
|
|
|
CameraManager cameraManager = gameObject.GetComponent<CameraManager>();
|
|
cameraManager.WebcamResume();
|
|
}
|
|
|
|
int GetPropRef(Player player)
|
|
{
|
|
return gameManager.myRoom.questions[currentQuestion - 1].propositions.First(x => x.Value.owner.id == player.id).Key;
|
|
}
|
|
|
|
public void OnSubmitButton()
|
|
{
|
|
StorageManager storageManager = managers.GetComponent<StorageManager>();
|
|
storageManager.UploadPhoto(
|
|
gameManager.myRoom.code,
|
|
gameManager.currentPlayer.id,
|
|
currentQuestion -1,
|
|
GetPropRef(gameManager.currentPlayer));
|
|
|
|
if (currentQuestion < 2) {
|
|
currentQuestion++;
|
|
Redraw(currentQuestion);
|
|
} else {
|
|
gameManager.myRoom.currentState = (int) GameState.PropositionsSent;
|
|
}
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|