public void InitializePlayUI() { if (totalQuestions == null) { totalQuestions = GetTotalQuestions(); currentFigure = DatabaseHandler.FiguresWithQuestionsAndAnswers.Keys.First(); } questionPanel.SetActive(true); currentQuestion = DatabaseHandler.FiguresWithQuestionsAndAnswers[currentFigure].Keys.First(); currentAnswers = GetAnswers(currentQuestion); ARInteraction.AREnabled = false; translator.SetQuestionText(currentQuestion.Question_Text); translator.ShowAnswers(currentAnswers.Count, currentAnswers); }
/// <summary> /// Adds a new ScenarioFigure to the current scenario, adding all required info to it /// </summary> /// <param name="hiddenFigureId">ID of the Figure this ScenarioFigure is based on</param> /// <param name="figure">Existing ScenarioFigure to copy into the scenario</param> /// <returns></returns> public GameObject AddFigure(string hiddenFigureId, ScenarioFigure figure = null) { ScenarioFigure temp = null; string image = ""; // Get values from the Figure to add to this ScenarioFigure foreach (Figure f in Figure.FigureList) { if (f.Id == int.Parse(hiddenFigureId)) { if (figure != null) { temp = figure; } else { temp = new ScenarioFigure(f.Id); } image = f.Image; } } Scenario.CurrentScenarioFigures.Add(FigurePanel.currentIndex, temp); GameObject newPanel = figurePanelRef.InstantiatePanel(); if (figure != null) { newPanel.GetComponentInChildren <Slider>().GetComponent <Text>().text = figure.Id.ToString(); newPanel.GetComponent <FigurePanel>().hiddenScenarioFigureId = figure.Id; } newPanel.GetComponent <FigurePanel>().hiddenIndex = FigurePanel.currentIndex + 1; FigurePanel.currentIndex++; Image[] images = newPanel.GetComponentsInChildren <Image>(); foreach (Image i in images) { if (i.tag == "FigureImage") { i.sprite = Resources.Load <Sprite>(image); } } propertiesPanels.Add(newPanel, newPanel.GetComponent <FigurePanel>()); return(newPanel); }
private void NextQuestion() { ScenarioQuestion nextQuestion = null; try { nextQuestion = DatabaseHandler.FiguresWithQuestionsAndAnswers[currentFigure].Keys.SkipWhile(k => k != currentQuestion).Skip(1).First(); Debug.Log(currentFigure.Id); } catch { } if (nextQuestion != null) { currentQuestion = nextQuestion; currentAnswers = GetAnswers(currentQuestion); translator.SetQuestionText(currentQuestion.Question_Text); translator.ShowAnswers(currentAnswers.Count, currentAnswers); } else { try { currentFigure = DatabaseHandler.FiguresWithQuestionsAndAnswers.Keys.SkipWhile(k => k != currentFigure).Skip(1).First(); } catch { currentFigure = null; } if (currentFigure == null) { ShowResults(); } else { panelHandler.OpenPlayPopUp(); Destroy(GameObject.FindGameObjectWithTag("ARContent")); arTap.contentToPlace = GetNextFigureById(currentFigure.Figure_Id); arTap.isPlaced = false; ARInteraction.AREnabled = true; questionPanel.SetActive(false); currentQuestion = DatabaseHandler.FiguresWithQuestionsAndAnswers[currentFigure].Keys.First(); } } }
/// <summary> /// Initializes a figures and then its questions and answers /// </summary> /// <param name="figure">Figure to instantiate</param> /// <param name="QuestionsAndAnswers">Dictionary of questions and answers to instantiate</param> private void InitializeScenarioFigure(ScenarioFigure figure, Dictionary <ScenarioQuestion, List <ScenarioAnswer> > QuestionsAndAnswers) { GameObject newPanel = AddFigure(figure.Figure_Id.ToString(), figure); FigurePanel fp = newPanel.GetComponent <FigurePanel>(); foreach (var QnA in QuestionsAndAnswers) { GameObject questionTemp = fp.InstantiateQuestion(QnA.Key.Question_Text, QnA.Key.Scenario_Figure_Id, QnA.Key.Id); Dictionary <GameObject, ScenarioAnswer> answers = new Dictionary <GameObject, ScenarioAnswer>(); foreach (var answer in QnA.Value) { answers.Add(fp.InstantiateAnswer(questionTemp.transform, answer.Answer_Text, answer.Scenario_Question_Id, answer.Id), answer); } foreach (var answerGOPair in answers) { if (answerGOPair.Value.Correct_Answer == 1) { answerGOPair.Key.GetComponentInChildren <Toggle>().isOn = true; } } } figurePanelRef.resetPanelsFunc(); }
/// <summary> /// Load an existing scenario /// </summary> /// <param name="hiddenScenarioId">ID of the scenario to load (found in each scenario list item prefab)</param> public void LoadScenarioDetails(Text hiddenScenarioId) { Clear(); hiddenScenarioIdField.text = hiddenScenarioId.text; if (hiddenScenarioId.text == "" || hiddenScenarioId == null) { scenarioAvailableToggle.isOn = true; scenarioNameInputField.text = ""; scenarioStoryTypeDropDown.value = (int)StoryType.Scavenger; } else { Scenario temp = null; foreach (Scenario s in Scenario.Scenarios) { if (s.Id == int.Parse(hiddenScenarioIdField.text)) { temp = s; } } if (temp != null) { if (temp.Available == 0) { scenarioAvailableToggle.isOn = false; } scenarioNameInputField.text = temp.Name; scenarioStoryTypeDropDown.value = (int)temp.StoryType; DBConnector.GetScenarioFigureData((callback) => { foreach (object figure in callback) { Dictionary <ScenarioQuestion, List <ScenarioAnswer> > QuestionsAndAnswers = new Dictionary <ScenarioQuestion, List <ScenarioAnswer> >(); PropertyInfo[] info = figure.GetType().GetProperties(); ScenarioFigure tempFigure = (ScenarioFigure)figure; DBConnector.GetQuestionData((questionCallback) => { foreach (object question in questionCallback) { ScenarioQuestion tempQuestion = (ScenarioQuestion)question; DBConnector.GetAnswerData((answerCallback) => { List <ScenarioAnswer> answers = new List <ScenarioAnswer>(); foreach (object answer in answerCallback) { ScenarioAnswer tempAnswer = (ScenarioAnswer)answer; answers.Add(tempAnswer); } QuestionsAndAnswers.Add(tempQuestion, answers); InitializeScenarioFigure(tempFigure, QuestionsAndAnswers); }, scenario_question_id: tempQuestion.Id); } figuresWithQnA.Add(tempFigure, QuestionsAndAnswers); }, scenario_figure_id: tempFigure.Id); } }, scenario_id: int.Parse(hiddenScenarioId.text)); } else { Debug.LogError("Something went wrong while trying to load scenario details of scenario id: " + hiddenScenarioIdField.text); } } }