private void AddMessageToChat(ChatMessagePacket msgPacket) { //Creates a new message and adds it to the list GameObject newMessageObject = Instantiate(m_messagePrefab, m_ViewContent); ChatMessage newCM = newMessageObject.GetComponent <ChatMessage>(); if (newCM == null) { Debug.LogError("Chat message prefab does not have a ChatMessage component, cannot add the recived message: " + msgPacket.Message); Destroy(newMessageObject); return; } //Init the message newCM.InitMessage(msgPacket.SenderID, msgPacket.Message); m_messagesList.AddLast(newCM); //If the chat history is full delete the last one if (m_messagesList.Count > m_maxChatHistoryLenght) { //Get the first message in the list, then remove it form the list and remvoe it from the ui LinkedListNode <ChatMessage> firstMessageNode = m_messagesList.First; ChatMessage cm = firstMessageNode.Value; m_messagesList.Remove(firstMessageNode); Destroy(cm.gameObject); } //Autoscroll Canvas.ForceUpdateCanvases(); StartCoroutine(CoroutineUtilities.DoOnNextFrame(() => { GetComponent <ScrollRect>().verticalScrollbar.value = 0.0f; })); }
private void OnClientStopped() { //IF there is a disconected task execute it as the network manager just stopped StartCoroutine(CoroutineUtilities.DoOnNextFrame(() => { if (m_DisconectedTask != null) { m_DisconectedTask.Invoke(); m_DisconectedTask = null; } })); }