/// <summary> /// Receive a message that was sent by another player and instantiate a new line /// in the chatbox with this information. Then trigger to display the chat icon. /// </summary> /// <param name="incoming">SentChatMessage type, consists of a player name and the message</param> public virtual void ReceiveNewMessage(SentChatMessage incoming) { GameObject newMessage = null; if (incoming.playerName == chatClient.UserId) { newMessage = Instantiate(yourChatMessage, messagesObj.transform.position, messagesObj.transform.rotation); } else { newMessage = Instantiate(otherChatMessage, messagesObj.transform.position, messagesObj.transform.rotation); ReceivedOtherPlayerChatMessage.Invoke(incoming); } newMessage.GetComponent <ChatMessage>().SetMessage(incoming); newMessage.transform.SetParent(messagesObj.transform); newMessage.transform.localScale = new Vector3(1, 1, 1); if (autoScroll == true) { AutoScrollToBottom(); } DisplayNewChatIcon(true); ReceivedAnyChatMessage.Invoke(incoming); if (OnRecieveMessage != null) { OnRecieveMessage.Invoke(incoming); } }
/// <summary> /// Sets the `playerName` and `message` text values based on the /// values in the `SentChatMessage` object. /// </summary> /// <param name="incoming">SentChatMessage type, this contains the player name and message</param> public virtual void SetMessage(SentChatMessage incoming) { userId = incoming.playerName; playerName.text = incoming.playerName.Split(':')[0]; message.text = incoming.message; }