Пример #1
0
 // Use this for initialization
 void Start()
 {
     gameState  = GameSates.SelfIntroduction;
     speakState = SpeakingStates.AgentSpeakTurn;
     dialogCanvas.GetComponent <Canvas>();
     dialogChoice1           = "DialogChoice_1";
     dialogChoice2           = "DialogChoice_2";
     dialogChoice3           = "DialogChoice_3";
     isDialogScreenActive    = false;
     currentDialogSceneIndex = 0;
     isDialogSceneChanged    = false;
 }
Пример #2
0
    IEnumerator PhrasePause(int num)
    {
        yield return(new WaitForSeconds(num));

        if (gameState == GameSates.SelfIntroduction)
        {
            Debug.Log(phrase);
            gameState  = GameSates.Topics_Culinary;
            speakState = SpeakingStates.UserSpeakTurn;
            phrase     = Phrase.Phrase_S1;
        }
    }
Пример #3
0
    IEnumerator ResultShowTime(int time)
    {
        Debug.Log("showing recognition");
        yield return(new WaitForSeconds(time));

        speakState = SpeakingStates.AgentSpeakTurn;
        if (gameState == GameSates.HelloWorld)
        {
            gameState = GameSates.SelfIntroduction;
        }
        else if (gameState == GameSates.SelfIntroduction)
        {
            if (phrase == Phrase.Phrase_S1)
            {
                phrase = Phrase.Phrase_S2;
            }
        }
        StartCoroutine(SwitchSpeechGUI(false));
    }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        switch (gameState)
        {
        case GameSates.SelfIntroduction:

            if (Input.GetKeyDown(KeyCode.C))    //start selfIntroduction
            {
                ShowDialogScreen(true);
            }

            break;

        case GameSates.DialogScene_1:     //going to chose one topic
        {
            if (!isDialogSceneChanged)
            {
                selfIntroduction.SetActive(false);         // close selfIntroduction
                ChangeDialogScene(currentDialogSceneIndex);
                Debug.Log("back to Scene1" + currentDialogSceneIndex);
                isDialogSceneChanged = true;
                currentButton        = null;
            }
            else if (currentButton != null && currentButton == dialogChoice1)
            {
                //ChoosePiece();
                //gameState = GameSates.Topic_1;
                Debug.Log(currentButton);
                gameState            = GameSates.Topic_1;
                isDialogSceneChanged = false;
            }
            else if (currentButton != null && currentButton == dialogChoice2)
            {
                //ChoosePiece();
                //gameState = GameSates.Topic_1;
                Debug.Log(currentButton);
                gameState            = GameSates.Topic_2;
                isDialogSceneChanged = false;
            }
            else if (currentButton != null && currentButton == dialogChoice3)
            {
                //ChoosePiece();
                //gameState = GameSates.Topic_1;
                Debug.Log(currentButton);
                gameState            = GameSates.Topic_3;
                isDialogSceneChanged = false;
            }
        }
        break;

        case GameSates.Topic_1:
        {
            if (!isDialogSceneChanged)         //enable Scene_Topic1
            {
                Debug.Log("chosen topic1");
                UpdateDialogScene(currentDialogSceneIndex, 1);
            }
            if (currentButton != null && isDialogSceneChanged && currentButton == dialogChoice2)      //back to 1-2 1-3
            {
                dialogScenes[currentDialogSceneIndex].SetActive(false);
                isDialogSceneChanged    = false;
                currentDialogSceneIndex = 0;
                gameState = GameSates.DialogScene_1;
                print("going to 1-2");
            }
            if (currentButton != null && isDialogSceneChanged && currentButton == dialogChoice1)
            {
                dialogScenes[currentDialogSceneIndex].SetActive(false);
                isDialogSceneChanged = false;

                gameState = GameSates.Topic_InvitingScene;
            }
        }
        break;

        case GameSates.Topic_2:
        {
            if (!isDialogSceneChanged)
            {
                // Debug.Log("chosen topic2");
                UpdateDialogScene(currentDialogSceneIndex, 2);
            }
            if (currentButton != null && isDialogSceneChanged)         //Topic2 to InvitingScene
            {
                dialogScenes[currentDialogSceneIndex].SetActive(false);
                isDialogSceneChanged = false;
                gameState            = GameSates.Topic_InvitingScene;
            }
        }
        break;

        case GameSates.Topic_3:
        {
            if (!isDialogSceneChanged)
            {
                //Debug.Log("chosen topic1");
                UpdateDialogScene(currentDialogSceneIndex, 3);
            }
            if (currentButton != null && isDialogSceneChanged)          //Topic2 to InvitingScene
            {
                dialogScenes[currentDialogSceneIndex].SetActive(false);
                isDialogSceneChanged = false;
                gameState            = GameSates.Topic_InvitingScene;
            }
        }
        break;

        case GameSates.Topic_nonCommonTopic:
        {
            Debug.Log("enter noncommonTopic");
            InvertBool(isDialogScreenActive);
            ShowDialogScreen(isDialogScreenActive);          //close dialogWindow
        }
        break;


        case GameSates.Topic_InvitingScene:
        {
            Debug.Log("enter Topic_InvitingScene");
            InvertBool(isDialogScreenActive);
            ShowDialogScreen(isDialogScreenActive);          //close dialogWindow
            //ShowDialogScreen(false);  //close dialogWindow
        }

        break;

        default:
            break;
        }
    }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.X)) ///send feedback report
        {
            //speechRecognitionResultString.text = currentRecognitionResult; //sync text

            /*
             * string url = "http://localhost:3003/script-chat?reply-key=";
             * //string apiKey = "zjvjuxytwh1pkdob";
             * WWWForm form = new WWWForm();
             * //form = feedBackString;
             * Dictionary<string, string> headers = form.headers;
             * headers["Authorization"] = "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(feedBackString + ":"));
             * //Dictionary<string, string> headers = form.headers;
             * //headers["Authorization"] = "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(apiKey + ":"));
             * WWW www = new WWW(url, headers);
             *
             */
            //saving report
            feedBack.AddField("userPreference", userPreference);
            feedBack.AddField("disclosureReply", disclosureReply);
            feedBack.AddField("userHobby", userHobby);
            feedBack.AddField("cousineAsk", cousineAsk);
            feedBack.AddField("askDinner", askDinner);
            feedBack.AddField("sum", point_sum);
            feedBack.AddField("userLineId", userLineID);
            feedBackString = feedBack.Print();
            Debug.Log(feedBackString);

            //send request
            Debug.Log("Http request");
            WebRequest req2 = WebRequest.Create("http://localhost:3003/feedback");
            //HttpWebRequest req2 = (HttpWebRequest)WebRequest.Create("http://localhost:3003/feedback");
            req2.Method = "POST";
            byte[] byteArray = Encoding.UTF8.GetBytes(feedBackString);
            //req2.ContentType = "application/json";
            // Set the ContentLength property of the WebRequest.
            req2.ContentLength = byteArray.Length;
            // Get the request stream.
            Stream dataStream = req2.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            ///

            /*
             * HttpWebResponse res2 = (HttpWebResponse)req2.GetResponse();
             * Stream s2 = res2.GetResponseStream();
             *
             * StreamReader sr2 = new StreamReader(s2);
             * string content2 = sr2.ReadToEnd();
             * JSONObject json = new JSONObject(content2);
             */
        }
        if (_isTooLate)
        {
            StartCoroutine(TooLateReaction());
        }
        if (Input.GetKeyDown(KeyCode.P))
        {
            int num = UnityEngine.Random.Range(0, 4);
            CreateHeartEffect(num);
        }

        if (Input.GetMouseButtonDown(1)) //check connection state
        {
            ws_.Send("<start>");
            //ws_.Send("unity");
            //InvertBool(_isRecongitionFinished);
            Debug.Log("sent");
        }
        switch (gameState)
        {
        case GameSates.Idle:
            if (Input.GetKeyDown(KeyCode.C) || _isGameStarted)
            {
                startCanvas.SetActive(false);
                if (!_isGameStarted)
                {
                    _isGameStarted = true;
                }
                gameState = GameSates.HelloWorld;
            }
            break;

        case GameSates.HelloWorld:

            if (speakState == SpeakingStates.AgentSpeakTurn && !_Speaking)
            //start Hello world
            {
                ShowDialogScreen(true);
                HelloWorld.SetActive(true);

                //StartCoroutine(SwitchSpeechGUI(true, 5));
                agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "2", lineArray[0]));
                int num = UnityEngine.Random.Range(3, 5);
                // facialExpress.StartCoroutine(facialExpress.StartFacialExpress("happy", num));
                StartCoroutine(StartFacialExpress(facial_happy, num));
                // StartCoroutine(agentSpeak.SayVoiceText("happiness", line_Hello));
            }
            else if (speakState == SpeakingStates.UserSpeakTurn && !_Speaking)
            {     //user turn
                if (!_isSpeechGUIon)
                {
                    StartCoroutine(SwitchSpeechGUI(true));
                    speechRecognitionResultString.text = "";
                    // _isSpeechGUIon = true;
                }

                else if (_StartRecognition)
                {
                    speechRecognitionResultString.text = "音声認識中";


                    if (_isRecongitionFinished)     //if speech recongnition finished
                    {
                        speechRecognitionResultString.text = currentRecognitionResult;
                        StartCoroutine("ResultShowTime", 3);
                        isDialogSceneChanged = false;
                        _StartRecognition    = false;
                    }
                }
            }
            break;

        case GameSates.SelfIntroduction:
        {
            string userText = "スポーツとポケモンが好きです";

            if (!isDialogSceneChanged && speakState == SpeakingStates.AgentSpeakTurn && !_Speaking && phrase == Phrase.Phrase_S1)         //only once
            {
                selfIntroduction_2.SetActive(true);
                HelloWorld.SetActive(false);
                agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "2", lineArray[1]));
                int num = UnityEngine.Random.Range(3, 5);
                StartCoroutine(StartFacialExpress(facial_happy, num));
                isDialogSceneChanged = true;
            }

            /*   if (_isSpeechGUIon)
             * {
             *     Debug.Log("change scene");
             *     StartCoroutine(SwitchSpeechGUI(false, 0));
             *     // StartCoroutine(SwitchSpeechGUI(false, 0));
             *     //StartCoroutine(SwitchSelftroduction(6));
             *     isDialogSceneChanged = true;
             *     _isSpeechGUIon = false;
             * }
             */

            else if (speakState == SpeakingStates.UserSpeakTurn && !_Speaking)
            {         //user turn
                if (!_isSpeechGUIon)
                {
                    StartCoroutine(SwitchSpeechGUI(true));
                    ShowDialogScreen(true);
                    speechRecognitionResultString.text = "";
                    // _isSpeechGUIon = true;
                }


                else if (_StartRecognition)
                {
                    speechRecognitionResultString.text = "音声認識中";


                    if (_isRecongitionFinished)         //if speech recongnition finished
                    {
                        speechRecognitionResultString.text = currentRecognitionResult;
                        StartCoroutine("ResultShowTime", 3);

                        _StartRecognition = false;

                        if (phrase == Phrase.Phrase_U_Choice1)
                        {
                            /*  1. #{disclosureが含まれる発言} | 評価+20p @可能なら評価の極性判別
                             *  2. #{相槌}(e.g. そうなんですね、へー) | 評価-10p
                             *  3. #{complement of disclosure} | 評価-10p
                             *  4. 時間制限超過 | 評価-10p
                             */
                            Debug.Log(phrase);
                            JSONObject chatInfo = GetChatInfo("disclosure", currentRecognitionResult);
                            // JSONObject chatInfo = GetChatInfo("preference", currentRecognitionResult);

                            float point = chatInfo.GetField("point").n;
                            CountSumPoint(point);
                            string responsePharse   = System.Text.RegularExpressions.Regex.Unescape(chatInfo.GetField("text").str);
                            string actionDisclosure = System.Text.RegularExpressions.Regex.Unescape(chatInfo.GetField("action").str);
                            Debug.Log(point);
                            Debug.Log(responsePharse);
                            _isTurningSpeaker = false;
                            if (point > 0)
                            {
                                //action1
                                disclosureReply = new JSONObject(JSONObject.Type.OBJECT);
                                disclosureReply.AddField("action", actionDisclosure);
                                disclosureReply.AddField("point", point);
                                agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "3", responsePharse));
                                int num = UnityEngine.Random.Range(3, 6);
                                StartCoroutine(StartFacialExpress(facial_happy, num));
                                int effectNum = UnityEngine.Random.Range(0, 4);
                                CreateHeartEffect(effectNum);
                            }
                            else if (point < 0)
                            {
                                disclosureReply = new JSONObject(JSONObject.Type.OBJECT);
                                disclosureReply.AddField("action", actionDisclosure);
                                disclosureReply.AddField("point", point);
                                agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("anger", "4", responsePharse));
                                int num = UnityEngine.Random.Range(3, 6);
                                StartCoroutine(StartFacialExpress(facial_scorn, num));
                            }
                            else if (_isTooLate)
                            {
                                point           = -10;
                                disclosureReply = new JSONObject(JSONObject.Type.OBJECT);
                                disclosureReply.AddField("action", "action4");
                                disclosureReply.AddField("point", point);
                            }

                            phrase = Phrase.Phrase_S4;
                        }

                        if (phrase == Phrase.Phrase_U_Choice2)
                        {
                            //[hobby]をしています@自由回答/~をしていますというテンプレートを促す
                            Debug.Log(phrase);

                            phrase = Phrase.Phrase_S5;
                        }
                    }
                }
            }

            else if (speakState == SpeakingStates.AgentSpeakTurn && !_Speaking && phrase == Phrase.Phrase_S2)
            {
                //speechRecognitionResultString.text = userText;
                //normal version
                selfIntroduction_2.SetActive(false);
                ShowDialogScreen(false);
                JSONObject chatInfo = GetChatInfo("preference", currentRecognitionResult);
                float      point    = chatInfo.GetField("point").n;
                CountSumPoint(point);
                string keyWord        = System.Text.RegularExpressions.Regex.Unescape(chatInfo.GetField("kword").str);  //key-word
                string responsePharse = System.Text.RegularExpressions.Regex.Unescape(chatInfo.GetField("text").str);

                userPreference = new JSONObject(JSONObject.Type.OBJECT);
                userPreference.AddField("keyword", keyWord);
                userPreference.AddField("point", point);
                Debug.Log(point);
                Debug.Log(responsePharse);
                Debug.Log(keyWord);
                //speechRecognitionResultString.text = currentRecognitionResult +" "+ point+ "点";
                _isTurningSpeaker = false;
                agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "2", responsePharse));

                phrase = Phrase.Phrase_S3;

                /*
                 * ///test version
                 * JSONObject chatInfo = GetChatInfo("preference",userText);
                 * Debug.Log(chatInfo);
                 * float point = chatInfo.GetField("point").n;
                 * Debug.Log(point);
                 * //speechRecognitionResultString.text = currentRecognitionResult + " " + point + "点";
                 * _isTurningSpeaker = false;
                 * agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "2", "ポケモンですか、ポケモンはいいですね"));
                 * phrase = Phrase.Phrase_S3;
                 */
            }
            else if (speakState == SpeakingStates.AgentSpeakTurn && !_Speaking && phrase == Phrase.Phrase_S3)
            {
                ///S: 私は[disclosure]が好きです。他にも[disclosure]に興味があります。
                _isTurningSpeaker = true;
                agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "2", lineArray[3]));
                Debug.Log("Phrase3");
                phrase = Phrase.Phrase_U_Choice1;
            }

            else if (speakState == SpeakingStates.AgentSpeakTurn && !_Speaking && phrase == Phrase.Phrase_S4)
            {
                ///えーと、休日は何をされていますか?
                ShowDialogScreen(false);
                _isTurningSpeaker = true;
                agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "2", lineArray[2]));
                Debug.Log(phrase);
                phrase = Phrase.Phrase_U_Choice2;
            }
            else if (speakState == SpeakingStates.AgentSpeakTurn && !_Speaking && phrase == Phrase.Phrase_S5)
            {
                ///[hobby]ですか、[hobby]には[いい印象があります! +10p~ 20p|いい印象がないです... -20p~ -10p]
                ShowDialogScreen(false);
                Debug.Log(phrase);
                JSONObject chatInfo = GetChatInfo("hobby", currentRecognitionResult);
                float      point    = chatInfo.GetField("point").n;
                CountSumPoint(point);
                string keyWord        = System.Text.RegularExpressions.Regex.Unescape(chatInfo.GetField("kword").str);  //key-word
                string responsePharse = System.Text.RegularExpressions.Regex.Unescape(chatInfo.GetField("text").str);

                userHobby = new JSONObject(JSONObject.Type.OBJECT);
                userHobby.AddField("keyword", keyWord);
                userHobby.AddField("point", point);
                Debug.Log(point);
                Debug.Log(responsePharse);
                Debug.Log(keyWord);
                _isTurningSpeaker = false;
                //S: 上記選択肢/視線情報により表情変化
                if (point == 10)
                {
                    agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "4", responsePharse));
                    int num = UnityEngine.Random.Range(3, 6);
                    StartCoroutine(StartFacialExpress(facial_happy, num));
                    int effectNum = UnityEngine.Random.Range(0, 4);
                    CreateHeartEffect(effectNum);
                }
                else if (point == 5)
                {
                    agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "3", responsePharse));
                    int num = UnityEngine.Random.Range(3, 6);
                    StartCoroutine(StartFacialExpress(facial_happy, num));
                    int effectNum = UnityEngine.Random.Range(0, 4);
                    CreateHeartEffect(effectNum);
                }
                else if (point == 0)
                {
                    agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "1", responsePharse));
                    int num = UnityEngine.Random.Range(3, 6);
                    StartCoroutine(StartFacialExpress(facial_normal, num));
                }
                else if (point == -5)
                {
                    agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("anger", "1", responsePharse));
                    int num = UnityEngine.Random.Range(3, 6);
                    StartCoroutine(StartFacialExpress(facial_scorn, num));
                }
                else if (point == -10)
                {
                    agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("anger", "3", responsePharse));
                    int num = UnityEngine.Random.Range(3, 6);
                    StartCoroutine(StartFacialExpress(facial_scorn, num));
                }
                phrase = Phrase.Phrase_Pause;
            }
            else if (!_Speaking && phrase == Phrase.Phrase_Pause)
            {
                StartCoroutine(PhrasePause(3));
                if (isDialogSceneChanged)
                {
                    isDialogSceneChanged = false;
                }
            }
        }
        break;

        case GameSates.Topics_Culinary:
        {
            if (speakState == SpeakingStates.AgentSpeakTurn && !_Speaking && phrase == Phrase.Phrase_S1)         //only once
            {
                //"日本食が好きですけど少し飽きました";
                ShowDialogScreen(false);
                topics_Culinary.SetActive(false);
                Debug.Log(phrase);
                agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "2", lineArray[4]));
                int num = UnityEngine.Random.Range(3, 5);
                StartCoroutine(StartFacialExpress(facial_happy, num));
                phrase = Phrase.Phrase_U_Choice1;
            }
            else if (speakState == SpeakingStates.UserSpeakTurn && !_Speaking)
            {                              //user turn
                if (!isDialogSceneChanged) //once
                {
                    dialogCanvas.SetActive(true);
                    topics_Culinary.SetActive(true);
                    isDialogSceneChanged = true;
                    _isTurningSpeaker    = true;
                }
                if (!_isSpeechGUIon)
                {
                    StartCoroutine(SwitchSpeechGUI(true));
                    ShowDialogScreen(true);
                    speechRecognitionResultString.text = "";
                    // _isSpeechGUIon = true;
                }


                else if (_StartRecognition)
                {
                    speechRecognitionResultString.text = "音声認識中";

                    if (_isRecongitionFinished)             //if speech recongnition finished
                    {
                        speechRecognitionResultString.text = currentRecognitionResult;
                        StartCoroutine("ResultShowTime", 3);
                        _StartRecognition = false;
                        if (phrase == Phrase.Phrase_U_Choice1)
                        {
                            /*   1. #{日本食} |if 疑問文 ? #{はぐらかす-秘密です} : [あいづち]
                             *   2. #{日本食以外の料理名が含まれる発言=cuisine}は好き?| イタリア料理/フランス料理/ロシア料理 ? [cuisine]も好きです : はあまり食べませんね
                             *   3. #{相槌}(e.g. そうなんですね、へー) | 評価-10p
                             *   4. #{complement of 料理名} | 評価-10p | 疑問文 ? #{はぐらかす-秘密です} : [あいづち]
                             *   5. 時間制限超過 | 気まずいため評価-10p
                             */
                            Debug.Log(phrase);
                            //JSONObject chatInfo = GetChatInfo("disclosure", currentRecognitionResult);
                            JSONObject chatInfo = GetChatInfo("ask-cousine", currentRecognitionResult);
                            float      point    = chatInfo.GetField("point").n;
                            CountSumPoint(point);
                            //Debug.Log(chatInfo);
                            string responsePharse = System.Text.RegularExpressions.Regex.Unescape(chatInfo.GetField("text").str);
                            Debug.Log(point);
                            Debug.Log(responsePharse);

                            if (point >= 0)
                            {
                                //action1
                                cousineAsk = new JSONObject(JSONObject.Type.OBJECT);

                                cousineAsk.AddField("point", point);
                                agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "2", responsePharse));
                                int num2 = UnityEngine.Random.Range(3, 6);
                                StartCoroutine(StartFacialExpress(facial_happy, num2));
                            }
                            else if (point < 0)
                            {
                                cousineAsk = new JSONObject(JSONObject.Type.OBJECT);

                                cousineAsk.AddField("point", point);
                                agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("anger", "3", responsePharse));
                                int num2 = UnityEngine.Random.Range(3, 6);
                                StartCoroutine(StartFacialExpress(facial_scorn, num2));
                            }
                            else if (_isTooLate)
                            {
                                point      = -10;
                                cousineAsk = new JSONObject(JSONObject.Type.OBJECT);
                                cousineAsk.AddField("action", "action5");
                                cousineAsk.AddField("point", point);
                            }

                            /*
                             * agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "3", responsePharse));
                             * int num = UnityEngine.Random.Range(3, 6);
                             * StartCoroutine(StartFacialExpress(facial_happy, num));
                             */
                            //if loop clear
                            isDialogSceneChanged = false;

                            gameState = GameSates.AskDinner;
                        }
                    }
                }
            }
        }
        break;

        case GameSates.AskDinner:
        {
            if (speakState == SpeakingStates.AgentSpeakTurn && !_Speaking && phrase == Phrase.Phrase_S1)         //only once
            {
                ShowDialogScreen(false);
                Debug.Log(phrase);
                JSONObject chatInfo = GetChatInfo("ask-dinner", currentRecognitionResult);
                float      point    = chatInfo.GetField("point").n;
                CountSumPoint(point);
                //Debug.Log(chatInfo);
                string responsePharse = System.Text.RegularExpressions.Regex.Unescape(chatInfo.GetField("text").str);
                if (point == 10)
                {
                    //行きましょう
                    agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "4", lineArray[5]));
                    int num = UnityEngine.Random.Range(3, 7);
                    StartCoroutine(StartFacialExpress(facial_happy, num));
                    int effectNum = UnityEngine.Random.Range(0, 4);
                    CreateHeartEffect(effectNum);
                    CreateHeartEffect(effectNum);
                }
                else
                {
                    //また今度
                    agentSpeak.StartCoroutine(agentSpeak.SayVoiceText("happiness", "2", lineArray[6]));
                    int num = UnityEngine.Random.Range(3, 4);
                    StartCoroutine(StartFacialExpress(facial_normal, num));
                }
                phrase = Phrase.Phrase_S2;
            }
            else if (speakState == SpeakingStates.UserSpeakTurn && !_Speaking)
            {                              //user turn
                if (!isDialogSceneChanged) //once
                {
                    ShowDialogScreen(true);
                    askDinnerCanvas.SetActive(true);
                    topics_Culinary.SetActive(false);

                    isDialogSceneChanged = true;
                }
                if (!_isSpeechGUIon)
                {
                    StartCoroutine(SwitchSpeechGUI(true));
                    ShowDialogScreen(true);
                    speechRecognitionResultString.text = "";
                    // _isSpeechGUIon = true;
                }


                else if (_StartRecognition)
                {
                    speechRecognitionResultString.text = "音声認識中";

                    if (_isRecongitionFinished)         //if speech recongnition finished
                    {
                        speechRecognitionResultString.text = currentRecognitionResult;
                        StartCoroutine("ResultShowTime", 3);
                        phrase            = Phrase.Phrase_S1;
                        _StartRecognition = false;
                    }
                }
            }
        }
        break;

        /*
         *          case GameSates.DialogScene_1: //going to chose one topic
         *              {
         *                  if (!isDialogSceneChanged)
         *                  {
         *                      selfIntroduction.SetActive(false); // close selfIntroduction
         *                      ChangeDialogScene(currentDialogSceneIndex);
         *                      Debug.Log("back to Scene1" + currentDialogSceneIndex);
         *                      isDialogSceneChanged = true;
         *                      currentButton = null;
         *                  }
         *                  else if (currentButton != null && currentButton == dialogChoice1)
         *                  {
         *                      //ChoosePiece();
         *                      //gameState = GameSates.Topic_1;
         *                      Debug.Log(currentButton);
         *                      gameState = GameSates.Topic_1;
         *                      isDialogSceneChanged = false;
         *
         *                  }
         *                  else if (currentButton != null && currentButton == dialogChoice2)
         *                  {
         *                      //ChoosePiece();
         *                      //gameState = GameSates.Topic_1;
         *                      Debug.Log(currentButton);
         *                      gameState = GameSates.Topic_2;
         *                      isDialogSceneChanged = false;
         *                  }
         *                  else if (currentButton != null && currentButton == dialogChoice3)
         *                  {
         *                      //ChoosePiece();
         *                      //gameState = GameSates.Topic_1;
         *                      Debug.Log(currentButton);
         *                      gameState = GameSates.Topic_3;
         *                      isDialogSceneChanged = false;
         *                  }
         *              }
         *              break;
         *
         *          case GameSates.Topic_1:
         *              {
         *                  if (!isDialogSceneChanged) //enable Scene_Topic1
         *                  {
         *                      Debug.Log("chosen topic1");
         *                      UpdateDialogScene(currentDialogSceneIndex, 1);
         *                  }
         *                  if (currentButton != null && isDialogSceneChanged && currentButton == dialogChoice2) //back to 1-2 1-3
         *                  {
         *                      dialogScenes[currentDialogSceneIndex].SetActive(false);
         *                      isDialogSceneChanged = false;
         *                      currentDialogSceneIndex = 0;
         *                      gameState = GameSates.DialogScene_1;
         *                      print("going to 1-2");
         *
         *                  }
         *                  if (currentButton != null && isDialogSceneChanged && currentButton == dialogChoice1)
         *                  {
         *                      dialogScenes[currentDialogSceneIndex].SetActive(false);
         *                      isDialogSceneChanged = false;
         *
         *                      gameState = GameSates.Topic_InvitingScene;
         *
         *                  }
         *              }
         *              break;
         *
         *          case GameSates.Topic_2:
         *              {
         *                  if (!isDialogSceneChanged)
         *                  {
         *                      // Debug.Log("chosen topic2");
         *                      UpdateDialogScene(currentDialogSceneIndex, 2);
         *                  }
         *                  if (currentButton != null && isDialogSceneChanged)  //Topic2 to InvitingScene
         *                  {
         *                      dialogScenes[currentDialogSceneIndex].SetActive(false);
         *                      isDialogSceneChanged = false;
         *                      gameState = GameSates.Topic_InvitingScene;
         *                  }
         *              }
         *              break;
         *
         *          case GameSates.Topic_3:
         *              {
         *                  if (!isDialogSceneChanged)
         *                  {
         *                      //Debug.Log("chosen topic1");
         *                      UpdateDialogScene(currentDialogSceneIndex, 3);
         *                  }
         *                  if (currentButton != null && isDialogSceneChanged)  //Topic2 to InvitingScene
         *                  {
         *                      dialogScenes[currentDialogSceneIndex].SetActive(false);
         *                      isDialogSceneChanged = false;
         *                      gameState = GameSates.Topic_InvitingScene;
         *                  }
         *              }
         *              break;
         *          case GameSates.Topic_nonCommonTopic:
         *              {
         *                  Debug.Log("enter noncommonTopic");
         *                  InvertBool(isDialogScreenActive);
         *                  ShowDialogScreen(isDialogScreenActive);  //close dialogWindow
         *              }
         *              break;
         *
         *
         *          case GameSates.Topic_InvitingScene:
         *              {
         *                  Debug.Log("enter Topic_InvitingScene");
         *                  InvertBool(isDialogScreenActive);
         *                  ShowDialogScreen(isDialogScreenActive);  //close dialogWindow
         *                  //ShowDialogScreen(false);  //close dialogWindow
         *              }
         *
         *              break;
         */

        default:
            break;
        }
    }
Пример #6
0
    void Start()
    {
        //feedBack data
        feedBack = new JSONObject(JSONObject.Type.OBJECT);


        Debug.Log(feedBackString);
        ////
        speechRecognitionResultString = speechRecognitionResultGUI.GetComponent <Text>();
        //speechRecognitionResultString.text = "";
        gameState  = GameSates.Idle;
        speakState = SpeakingStates.AgentSpeakTurn;
        phrase     = Phrase.Phrase_S1;
        agentSpeak = FindObjectOfType <Girl_Speaking>();
        //facialExpress =MainCharacter.GetComponent<Facial_Expression>();
        faceController = MainCharacter.GetComponent <MMD4MFaceController>();
        dialogCanvas.GetComponent <Canvas>();
        dialogChoice1           = "DialogChoice_1";
        dialogChoice2           = "DialogChoice_2";
        dialogChoice3           = "DialogChoice_3";
        isDialogScreenActive    = false;
        currentDialogSceneIndex = 0;
        point_sum              = 50f;
        isDialogSceneChanged   = false;
        _StartRecognition      = false;
        _Speaking              = false;
        _isSpeechGUIon         = false;
        _isRecongitionFinished = true;
        _isTooLate             = false;
        _isTurningSpeaker      = true;
        _isGameStarted         = false;
        inputScript            = FindObjectOfType <InputFieldScript>();
        userLineID             = inputScript.ReturnID();
        Debug.Log(userLineID);
        ////Websocket
        ws_         = new WebSocket("ws://localhost:3000"); //speech recon
        ws_.OnOpen += (sender, e) =>
        {
            Debug.Log("WebSocket Open");
        };

        ws_.OnMessage += (sender, e) => {
            //speechRecognitionResultString.text = e.Data;
            if (e.Data == "<too_late>")
            {
                Debug.Log("too late");
                InvertIsTooLate(_isTooLate);
            }
            else
            {
                currentRecognitionResult = e.Data;
                Debug.Log("message");
                //Debug.Log(sender + speechRecognitionResultString.text);
                Debug.Log(sender + currentRecognitionResult);
                InvertBool(_isRecongitionFinished);
            }
        };
        ws_.OnClose += (sender, e) =>
        {
            Debug.Log("connect close");
            // ws_.Connect();
        };

        ws_.Connect();
    }