private void DoTestAfterShowAnswer() { ExperimentState currentStateData = data.States[currentState]; switch (currentStateData.ContentType) { case ExperimentContentType.Number: case ExperimentContentType.NumberWithRandom: NumberAnswerIndicator.gameObject.SetActive(true); NumberInputPanel.gameObject.SetActive(true); NumberAnswerIndicator.Initialize(currentStateData.AnswerTitle, currentStateData.AnswerCount, currentStateData.AnswerMaxLength); EventLogger.LogTestStart(currentState, currentStateData.ContentType); BeepSound.Play(); break; case ExperimentContentType.NumberWithRandomAndNoGuide: NumberAnswerIndicator.gameObject.SetActive(true); NumberInputPanel.gameObject.SetActive(true); TempAnswerText.ShowText(correctAnswers[0].ToString()); NumberAnswerIndicator.Initialize(currentStateData.AnswerTitle, currentStateData.AnswerCount, currentStateData.AnswerMaxLength); EventLogger.LogTestStart(currentState, currentStateData.ContentType); BeepSound.Play(); break; case ExperimentContentType.MultipleSelection: case ExperimentContentType.MultipleSelectionWithRandom: MultipleChoiceInput.gameObject.SetActive(true); MultipleChoiceInput.Initialize(currentStateData.AnswerSet, currentStateData.AnswerCount); EventLogger.LogTestStart(currentState, currentStateData.ContentType); BeepSound.Play(); break; } }
private void DoTest() { currentState++; isShowingGuideText = false; AnswerGuideText.isOkToProceed = false; if (currentState >= 0 && currentState < data.States.Length) { ExperimentState currentStateData = data.States[currentState]; MainGuideTextUI.text = currentStateData.MainGuideText; //제목 설정 ConfirmButton.interactable = false; ConfirmButton.GetComponentInChildren <Text>().text = "확인"; ShuffleController.SetShuffle(currentState); int answerRange; string answerGuideText; switch (currentStateData.ContentType) { case ExperimentContentType.None: AnswerGuideText.gameObject.SetActive(false); NumberAnswerIndicator.gameObject.SetActive(false); NumberInputPanel.gameObject.SetActive(false); MultipleChoiceInput.gameObject.SetActive(false); ConfirmButton.interactable = true; ConfirmButton.GetComponentInChildren <Text>().text = "실험 재시작"; currentState = -1; break; case ExperimentContentType.Number: DingSound.Play(); AnswerGuideText.gameObject.SetActive(false); MultipleChoiceInput.gameObject.SetActive(false); NumberAnswerIndicator.gameObject.SetActive(false); NumberInputPanel.gameObject.SetActive(false); NumberAnswerIndicator.Initialize(currentStateData.AnswerTitle, currentStateData.AnswerCount, currentStateData.AnswerMaxLength); if (currentState == 0) { DingSound.Stop(); DoTestAfterShowAnswer(); } else { StartCoroutine(WaitUser()); } break; case ExperimentContentType.MultipleSelection: DingSound.Play(); AnswerGuideText.gameObject.SetActive(false); NumberAnswerIndicator.gameObject.SetActive(false); NumberInputPanel.gameObject.SetActive(false); MultipleChoiceInput.gameObject.SetActive(false); StartCoroutine(WaitUser()); break; //랜덤 정답을 생성해야 하는 경우 case ExperimentContentType.NumberWithRandom: DingSound.Play(); AnswerGuideText.gameObject.SetActive(true); NumberAnswerIndicator.gameObject.SetActive(false); NumberInputPanel.gameObject.SetActive(false); MultipleChoiceInput.gameObject.SetActive(false); //정답 랜덤 생성 answerRange = (int)Math.Pow(10, currentStateData.AnswerMaxLength); correctAnswers = GenerateRandomAnswer(answerRange / 10, answerRange, currentStateData.AnswerCount); answerGuideText = GenerateAnswerText(correctAnswers); isShowingGuideText = true; //위험한 코드 ConfirmButton.interactable = false; AnswerGuideText.Initialize(answerGuideText, DoTestAfterShowAnswer); break; //------------------------------------// case ExperimentContentType.NumberWithRandomAndNoGuide: //새로 추가한 것 DingSound.Play(); AnswerGuideText.gameObject.SetActive(false); NumberAnswerIndicator.gameObject.SetActive(false); NumberInputPanel.gameObject.SetActive(false); MultipleChoiceInput.gameObject.SetActive(false); TempAnswerText.gameObject.SetActive(false); //정답 랜덤 생성 answerRange = (int)Math.Pow(10, currentStateData.AnswerMaxLength); correctAnswers = GenerateRandomAnswer(answerRange / 10, answerRange, currentStateData.AnswerCount); answerGuideText = GenerateAnswerText(correctAnswers); ConfirmButton.interactable = false; StartCoroutine(WaitUser()); break; case ExperimentContentType.MultipleSelectionWithRandom: DingSound.Play(); AnswerGuideText.gameObject.SetActive(true); NumberAnswerIndicator.gameObject.SetActive(false); NumberInputPanel.gameObject.SetActive(false); MultipleChoiceInput.gameObject.SetActive(false); //선택지 랜덤 배열 currentStateData.AnswerSet = GenerateRandomAnswerSet(currentStateData.AnswerSet); //정답 랜덤 생성 answerRange = currentStateData.AnswerMaxLength; correctAnswers = GenerateRandomAnswer(0, answerRange, currentStateData.AnswerCount); answerGuideText = GenerateAnswerText(correctAnswers, currentStateData.AnswerSet); isShowingGuideText = true; //위험한 코드 ConfirmButton.interactable = false; AnswerGuideText.Initialize(answerGuideText, DoTestAfterShowAnswer); break; } } }
/// <summary> /// 사용자가 Confrim 누르기 전 입력을 완료했다고 판단 되었을 때 실행되는 이벤트 핸들러 /// </summary> /// <param name="sender">이벤트 발생 객체</param> /// <param name="args">이벤트 발생 정보</param> public void OnAnswerSelected(GameObject sender, ExperimentActionEvent.EventArgs args) { ExperimentState currentStateData = data.States[currentState]; switch (currentStateData.ContentType) { case ExperimentContentType.Number: case ExperimentContentType.MultipleSelection: if (args.Answers.Length >= currentStateData.AnswerCount) { ConfirmButton.interactable = true; //주의: State List가 바뀌면 실제 성별이나 생일을 묻는 질문인지 검토 필요 switch (currentState) { case 0: EventLogger.SetID(args.Answers[0]); break; case 1: EventLogger.LogGender((Gender)args.Answers[0] + 1); break; case 4: case 13: EventLogger.LogBirth(args.Answers[0]); break; case 12: case 14: EventLogger.LogPhoneNumber(args.Answers[0]); break; } } else { ConfirmButton.interactable = false; } break; case ExperimentContentType.NumberWithRandom: case ExperimentContentType.NumberWithRandomAndNoGuide: case ExperimentContentType.MultipleSelectionWithRandom: if (args.Answers.Length < currentStateData.AnswerCount) { ConfirmButton.interactable = false; break; } bool isAllCorrect = true; foreach (int answer in args.Answers) { bool isCorrect = false; foreach (int correctAnswer in correctAnswers) { if (correctAnswer == answer) { isCorrect = true; } } isAllCorrect = isAllCorrect && isCorrect; } ConfirmButton.interactable = isAllCorrect; if (isAllCorrect == false) { StartCoroutine(PlayWrongSound()); } break; } }