//void RecognizeResult(string content) //{ // voiceHint = false; // content = content.TrimEnd('.'); // bool recognizeOK = false; // for (int i = 0; i < dialog.answerIds.Count; i++) // { // Sentence sentence = Sentence.Get(dialog.answerIds[i]); // if (sentence.en.ToUpper().Contains(content.ToUpper())) // { // Debug.Log(sentence.en + " contains " + content); // triggerId = dialog.answerIds[i]; // answerIndex = i; // iPlay.Select(dialog.answerIds[i]); // if (dialog.transfer == 2) // { // index++; // StartCoroutine(Evaluating(0, SUCCESS)); // recognizeOK = true; // break; // } // else // { // DisplayAnswer(answerIndex); // recognizeOK = true; // break; // } // } // else // { // Debug.Log(sentence.en + " not contains " + content); // } // } // if (recognizeOK == false) // { // StartCoroutine(ShowPrompt()); // } //} //IEnumerator ShowPrompt() //{ // yield return new WaitForSeconds(1f); // float time = Audio.GetInstance().Play(AudioType.INTRO, Prompt.Get().Audio); // yield return new WaitForSeconds(time); // agent.StartRecognize(RecognizeResult); // voiceHint = true; // deltaTime = 0f; //} void DisplayAnswer(int aIndex) { Debug.Log("DisplayAnswer:" + aIndex); iPlay.Display(Sentence.Get(dialog.answerIds[aIndex]).itemName); customer.Find("EN").GetComponent <Text>().text = Sentence.Get(dialog.answerIds[aIndex]).en; customer.Find("CN").GetComponent <Text>().text = Role.currentRole.isReview ? "" : Sentence.Get(dialog.answerIds[aIndex]).cn; agent.StartEvaluator(ReceiveEvaluatorResult, Sentence.Get(dialog.answerIds[aIndex]).en); ///测试 //Hint.GetInstance().Show("棒极了!", "Perfect!"); //ShowStar(5); //index++; //StartCoroutine(Evaluating(0.5f, SUCCESS)); voiceHint = true; deltaTime = 0f; Role.AddToReviewByDialog(dialog.answerIds[aIndex]); }
IEnumerator ShowDialog() { DisplayHints(null); customer.Find("EN").GetComponent <Text>().text = ""; customer.Find("CN").GetComponent <Text>().text = ""; Debug.Log("===" + index); if (index >= curriculum.dialogs.Count)//index is greater than dialog‘s count, finish { yield return(new WaitForSeconds(0.5f)); Finish(); yield break; } dialog = curriculum.dialogs[index]; if (dialog.triggerId != 0)//if triggerId is not zero, find the dialog's triggerId equals zero or equals the triggerId { for (; index < curriculum.dialogs.Count; index++) { if ((curriculum.dialogs[index].triggerId != 0 && curriculum.dialogs[index].triggerId == triggerId) || (curriculum.dialogs[index].triggerId == 0)) { triggerId = 0; break; } } } dialog = curriculum.dialogs[index];//reset the dialog to correct one if (dialog.transfer == 1) { yield return(new WaitForSeconds(4f)); iPlay.Transfer(dialog.transfer); yield return(new WaitForSeconds(1f)); } if (dialog.askId >= 0) { waiter.Find("EN").GetComponent <Text>().text = Sentence.Get(dialog.askId).en; waiter.Find("CN").GetComponent <Text>().text = Role.currentRole.isReview ? "" : Sentence.Get(dialog.askId).cn; float waiterTime = Audio.GetInstance().Play(AudioType.INTRO, Sentence.Get(dialog.askId).audio); iPlay.PlayAnimation(Sentence.Get(dialog.askId).anim); yield return(new WaitForSeconds(waiterTime)); Role.AddToReviewByDialog(dialog.askId); } if (dialog.answerIds.Count == 1)//only ont answer { answerIndex = 0; DisplayAnswer(answerIndex); } else if (dialog.answerIds.Count > 1) //multy-answers { if (string.IsNullOrEmpty(dialog.keyword)) //no keyword, random select one { answerIndex = UnityEngine.Random.Range(0, dialog.answerIds.Count); DisplayAnswer(answerIndex); } else//have keyword, display items according to dialog, and waiting for user voice input { iPlay.Process(dialog); //agent.StartRecognize(RecognizeResult); DisplayHints(dialog.answerIds); voiceHint = true; deltaTime = 0f; } } else//no customer dialog, finish { if (index == curriculum.dialogs.Count - 1) { yield return(new WaitForSeconds(0.5f)); Finish(); yield return(null); } else { index += 1; yield return(StartCoroutine(ShowDialog())); } } }