/// <summary> /// This method updates the UI object with bot response /// </summary> /// <param name="response">response json recieved from the bot</param> public void RecieveMessage(string response) { // Deserialize response recieved from the bot RootMessages recieveMessages = JsonUtility.FromJson <RootMessages>("{\"messages\":" + response + "}"); // show message based on message type on UI foreach (RecieveData message in recieveMessages.messages) { FieldInfo[] fields = typeof(RecieveData).GetFields(); foreach (FieldInfo field in fields) { string data = null; // extract data from response in try-catch for handling null exceptions try { data = field.GetValue(message).ToString(); } catch (NullReferenceException) { } // print data if (data != null && field.Name != "recipient_id") { botUI.UpdateDisplay("bot", data, field.Name); } } } }
public SeriPort(string portName, int BaundRate, byte bits) { this.State = 1; this.myPort = new SerialPort(portName, BaundRate, Parity.None, bits, StopBits.One); this.log = LogManager.GetCurrentClassLogger(); this.allMessage = AllMessage.getObject(); this.rootMessages = new RootMessages(); }
/// <summary> /// This method updates the UI object with bot response /// </summary> /// <param name="response">response json recieved from the bot</param> public void RecieveMessage(string response) { // Deserialize response recieved from the bot RootMessages recieveMessages = JsonUtility.FromJson <RootMessages>("{\"messages\":" + response + "}"); //Debug.Log(response[response.IndexOf("buttons")+9]); // show message based on message type on UI foreach (RecieveData message in recieveMessages.messages) { FieldInfo[] fields = typeof(RecieveData).GetFields(); foreach (FieldInfo field in fields) { String data = null; // extract data from response in try-catch for handling null exceptions try { data = field.GetValue(message).ToString(); } catch (NullReferenceException) { } // print data if (data != null && field.Name != "recipient_id") { if (field.Name == "buttons" && response.Contains("buttons")) { int i = response.IndexOf("buttons") + 9; //Debug.Log(response[response.IndexOf("]")]); response = response.Substring(i); int j = response.IndexOf("]") + 1; response = response.Substring(0, j); RootMessagesButtons recieveMessagesButtons = JsonUtility.FromJson <RootMessagesButtons>("{\"messages\":" + response + "}"); foreach (RecieveDataButtons msg in recieveMessagesButtons.messages) { FieldInfo[] fields_2 = typeof(RecieveDataButtons).GetFields(); data = ""; foreach (FieldInfo field_2 in fields_2) { data += field_2.GetValue(msg).ToString(); } botUI.UpdateDisplay("bot", data, field.Name); } } else { botUI.UpdateDisplay("bot", data, field.Name); } } } } }
/// <summary> /// This method updates the UI object with bot response /// </summary> /// <param name="response">response json recieved from the bot</param> public void RecieveMessage(string response) { try { // Deserialize response recieved from the bot RootMessages recieveMessages = JsonUtility.FromJson <RootMessages>("{\"messages\":" + response + "}"); StartCoroutine(botUI.UnpackMessagesAfterDelay(recieveMessages)); } catch (Exception e) { Debug.Log("Error while deserializing json due to " + e); } }
private int allMessagesHeight = messagePadding; // int to keep track of where next message should be rendered /// <summary> /// This method recieves the array of messages from <see cref="NetworkManager.RecieveMessage(string)"> /// and prints them on botUI with an animation. /// </summary> /// <param name="recieveMessages">A list of messages received from the bot</param> /// <returns></returns> public IEnumerator UnpackMessagesAfterDelay(RootMessages recieveMessages) { // show message based on message type on UI foreach (RecieveData message in recieveMessages.messages) { FieldInfo[] fields = typeof(RecieveData).GetFields(); foreach (FieldInfo field in fields) { string data = null; // extract data from response in try-catch for handling null exceptions try { data = field.GetValue(message).ToString(); } catch (NullReferenceException) { } // print data if (data != null && field.Name != "recipient_id") { // Create chat bubble, add animator and reposition GameObject chatBubbleChild = CreateChatBubble("bot"); AddChatComponent(chatBubbleChild, "", "animation"); StartCoroutine(SetChatBubblePosition(chatBubbleChild.transform.parent.GetComponent <RectTransform>(), "bot")); // Add delay then remove animator and update message height counter yield return(new WaitForSeconds(2f)); allMessagesHeight -= messagePadding + (int)chatBubbleChild.transform.parent.GetComponent <RectTransform>().sizeDelta.y; if (chatBubbleChild.GetComponent <Animator>() != null) { Destroy(chatBubbleChild.GetComponent <Animator>()); Destroy(chatBubbleChild.GetComponent <Image>()); } yield return(new WaitForEndOfFrame()); // Add message to the chat bubble UpdateDisplay(data, field.Name, chatBubbleChild); } } } }
// Parse the response received from the bot public void RecieveMessage(String response) { // Debug.Log(response); // Deserialize response recieved from the bot RootMessages recieveMessages = JsonUtility.FromJson <RootMessages>("{\"messages\":" + response + "}"); // show message based on message type on UI foreach (RecieveData message in recieveMessages.messages) { FieldInfo[] fields = typeof(RecieveData).GetFields(); foreach (FieldInfo field in fields) { // Debug.Log(field); string data = null; // extract data from response in try-catch for handling null exceptions try { data = field.GetValue(message).ToString(); } catch (NullReferenceException) { } // print data if (data != null && field.Name != "recipient_id" && once == 0) { foreach (AudioClip clip in bedroomClips) { if (data == clip.name) { SoundEffect.PlayOneShot(clip); } Debug.Log("Bot said \"" + data + "\""); } once = 1; } } } }
public void RecieveMessage(string response) { RootMessages recieveMessages = JsonUtility.FromJson <RootMessages>("{\"messages\":" + response + "}"); foreach (RecieveData message in recieveMessages.messages) { FieldInfo[] fields = typeof(RecieveData).GetFields(); foreach (FieldInfo field in fields) { string data = null; try { data = field.GetValue(message).ToString(); //ESTA ES LA RESPUESTA } catch (NullReferenceException) { } if (data != null && field.Name != "recipient_id") { respuesta = data; } } } }
public ITDMA() { this.root = new RootMessages(); this.log = LogManager.GetCurrentClassLogger(); }
public OverallDimension() { this.log = LogManager.GetCurrentClassLogger(); this.root = new RootMessages(); }