コード例 #1
0
ファイル: SpeechBox.cs プロジェクト: SaitenHazard/DreamGame
    private void Awake()
    {
        instance = this;

        Speech = instance.gameObject;

        Show(false);
    }
コード例 #2
0
        private void ReadCommands(string result, string status)
        {
            if (Maps.Stop)
            {
                return;
            }

            var    b           = speechSyn.Voice.Gender;
            string CommandName = "";
            string Answer      = "";
            string CommandType = "";

            speechSyn.SelectVoiceByHints(VoiceGender.Female);//female speaks

            if (SpeechBox.InvokeRequired && Maps.IsSleeping == false)
            {
                SpeechBox.Invoke(new MethodInvoker(delegate { SpeechBox.Text = result + "\n" + SpeechBox.Text; }));//shows what user said
            }

            CommandType = common.GetCommandTypeFromAliasInLocal(Conn, result);//get data from db

            if (OldCommandsBox.InvokeRequired && Maps.IsSleeping == false && CommandType != "" && CommandType != null)
            {
                OldCommandsBox.Invoke(new MethodInvoker(delegate { OldCommandsBox.Text = "Type:" + CommandType + "\n" + OldCommandsBox.Text; }));//shows command
            }
            switch (CommandType)
            {
            case "Chat":
                Answer = common.GetAnswersInLocal(Conn, result);

                if (OldCommandsBox.InvokeRequired)
                {
                    OldCommandsBox.Invoke(new MethodInvoker(delegate { OldCommandsBox.Text = ":" + result + "\n" + OldCommandsBox.Text; }));    //shows command
                }
                break;

            case "System":
                CommandName = common.GetCommandNameFromAliasInLocal(Conn, result);

                if (OldCommandsBox.InvokeRequired)
                {
                    OldCommandsBox.Invoke(new MethodInvoker(delegate { OldCommandsBox.Text = ":" + CommandName + "  \n" + OldCommandsBox.Text; }));    //shows command
                }
                Answer = commands.dic[CommandName].Execute();
                break;

            case "C#":
                CommandName = common.GetCommandNameFromAliasInLocal(Conn, result);
                if (OldCommandsBox.InvokeRequired)
                {
                    OldCommandsBox.Invoke(new MethodInvoker(delegate { OldCommandsBox.Text = ":" + CommandName + "  \n" + OldCommandsBox.Text; }));    //shows command
                }
                Answer = commands.dic[CommandName].Execute();
                break;

            default:

                Dictionary <string, List <string> > CommandNameAndParameters = common.GetCommandNameAndParameters(Conn, result);
                List <string> Commands           = new List <string>();
                string        currentCommandName = "";
                string[]      paramArray         = null;
                foreach (var item in CommandNameAndParameters)
                {
                    paramArray = item.Value.ToArray();
                    Commands.AddRange(item.Value);
                    currentCommandName = item.Key;
                }
                string Answ = string.Join(",", Commands.ToArray());
                Answ += currentCommandName;
                if (ResultsBox.InvokeRequired && Maps.IsSleeping == false)
                {
                    ResultsBox.Invoke(new MethodInvoker(delegate { ResultsBox.Text = Answ + "\n" + ResultsBox.Text; }));    //shows answer
                }
                try
                {
                    if (currentCommandName != "")
                    {
                        Answer = commands.dic[currentCommandName].Execute(paramArray);
                    }
                }
                catch (Exception e)
                {
                }

                break;
            }
            if (ResultsBox.InvokeRequired && Maps.IsSleeping == false)
            {
                ResultsBox.Invoke(new MethodInvoker(delegate { ResultsBox.Text = Answer + "\n" + ResultsBox.Text; }));//shows answer
            }
            if (Maps.IsSleeping == false && Maps.Mute == false)
            {
                speechSyn.SpeakAsync(Answer);//speaks..
            }
        }