示例#1
0
    void ParseAndSetModeFromNode(VD.NodeData node)
    {
        if (node.extraVars.ContainsKey("mode"))
        {
            object obj = node.extraVars["mode"];
            string s   = (string)obj;

            try {
                DialogueMode prevmode = mode;

                mode = (DialogueMode)System.Enum.Parse(typeof(DialogueMode), s);

                if (prevmode == DialogueMode.Ambient && mode == DialogueMode.Dialogue)
                {
                    nextButton.gameObject.SetActive(false);
                }
            }
            catch
            {
                Debug.LogError("Dialogue Mode couldn't be parsed. Spelling error? " + s + " in node " + node.nodeID);
            }
        }
        else
        {
            return; //no change. keep as is.
        }
    }
示例#2
0
    void ParseAndSetModeFromNode(string modeChange)
    {
        if (modeChange.Contains("%%Ambient%%") || modeChange.Contains("%%Dialogue%%"))
        {
            string s = modeChange.Trim(new char[] { '%', '\n' });

            try
            {
                DialogueMode prevmode = mode;

                mode = (DialogueMode)System.Enum.Parse(typeof(DialogueMode), s);

                if (prevmode == DialogueMode.Ambient && mode == DialogueMode.Dialogue)
                {
                    nextButton.gameObject.SetActive(false);
                }
            }
            catch
            {
                Debug.LogError("Dialogue Mode couldn't be parsed. Spelling error? " + modeChange);
            }
        }
    }
示例#3
0
        /// <summary>
        /// 対話をおこなうAPI
        /// </summary>
        /// <param name="sentence">ユーザーの発話(255文字以下)</param>
        /// <param name="user">ユーザーの情報(オプション)</param>
        /// <param name="mode">対話モード(対話・しりとり)</param>
        /// <param name="id">対話ID(対話を続ける場合はResultSetに含まれるidを渡してください</param>
        /// <param name="characterId">0:デフォルト 20:関西風 30:赤ちゃん風</param>
        /// <returns>システムからの応答</returns>
        public async Task <ResultSet> ExecAsync(String sentence, UserInfo user = null, DialogueMode mode = DialogueMode.DIALOG, String id = null, int characterId = 0)
        {
            var client = new HttpClient();

            //対話APIのエンドポイントURL
            var uri = "https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue?APIKEY=" + APIKey;


            //要求するメッセージを作成
            Dictionary <string, object> request = new Dictionary <string, object>();

            request["utt"]     = sentence;
            request["context"] = id;
            if (user != null)
            {
                request["nickname"]       = user.NickName;
                request["nickname_y"]     = user.NickNameYomi;
                request["sex"]            = user.Sex.ToJapanese();
                request["bloodtype"]      = user.BloodType.ToString();
                request["birthdateY"]     = user.BirthDay.Year;
                request["birthdateM"]     = user.BirthDay.Month;
                request["birthdateD"]     = user.BirthDay.Day;
                request["age"]            = user.Age;
                request["constellations"] = user.Constellations.ToJapanese();
                request["place"]          = user.Place;
            }
            request["mode"] = mode.ToString().ToLower();
            request["t"]    = characterId;

            //JSONへ変換(Newtonsoft Json.NETライブラリ使用)
            string json = JsonConvert.SerializeObject(request);

            //要求を送信
            StringContent content = new StringContent(json);

            content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
            HttpResponseMessage response = await client.PostAsync(uri, content);

            //エラー確認
            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                string err_resp = await response.Content.ReadAsStringAsync();

                throw new Exception("ERROR" + err_resp);
            }

            //サーバーからの応答(Json)を文字列として取り出す
            string response_json = await response.Content.ReadAsStringAsync();

            //jsonをパース(Newtonsoft Json.NETライブラリ使用)
            var result = JsonConvert.DeserializeObject <dynamic>(response_json);

            //変換結果を取り出す(convertedに変換結果が入っている)
            ResultSet r = new ResultSet();

            r.Result     = result["utt"];
            r.ResultYomi = result["yomi"];
            r.ID         = result["context"];
            return(r);
        }