/// <summary> /// Adds a chat message to the specified tab. /// </summary> /// <param name="tabId">The tab id.</param> /// <param name="text">The message.</param> public void ReceiveChatMessage(ChatTabType tabType, string text, LobbyData senderData) { TabInfo tabInfo = this.GetTabInfo(tabType); // Make sure we have tab info if (tabInfo == null || tabInfo.content == null) { return; } // Create the text line GameObject obj = new GameObject("Text " + tabInfo.content.childCount.ToString(), typeof(RectTransform)); // Prepare the game object obj.layer = this.gameObject.layer; // Get the rect transform RectTransform rectTransform = (obj.transform as RectTransform); // Prepare the rect transform rectTransform.localScale = new Vector3(1f, 1f, 1f); rectTransform.pivot = new Vector2(0f, 1f); rectTransform.anchorMin = new Vector2(0f, 1f); rectTransform.anchorMax = new Vector2(0f, 1f); // Set the parent rectTransform.SetParent(tabInfo.content, false); // Add the text component Text textComp = obj.AddComponent <Text>(); // Prepare the text component textComp.font = this.m_TextFont; textComp.fontSize = this.m_TextFontSize; textComp.lineSpacing = this.m_TextLineSpacing; textComp.color = this.m_TextColor; textComp.text = string.Format("<b><color=#{0}>{1}</color></b> <color=#59524bff>said:</color> {2}", ColorUtility.ToHtmlStringRGB(senderData.Color), senderData.Name, text); // Scroll to bottom this.OnScrollToBottomClick(); if (tabType != ChatTabType.CHAT_TAB_TYPE_ALL) { // Add the same msg to All tab ReceiveChatMessage(ChatTabType.CHAT_TAB_TYPE_ALL, text, senderData); } }
/// <summary> /// Gets the tab info for the specified tab by id. /// </summary> /// <param name="tabId">Tab id.</param> /// <returns></returns> public TabInfo GetTabInfo(ChatTabType type) { // If we have tabs if (this.m_Tabs != null && this.m_Tabs.Count > 0) { foreach (TabInfo info in this.m_Tabs) { // If this is the tab we are looking for if (info.type == type) { return(info); } } } return(null); }