public void AddMessage(BroadcastMessageData data) { var tf = GetNewMessageItem(); var channelColor = GetChannelColor(data); var channelName = GetChannelNamePrefix(data, channelColor); var messageText = string.Empty; var textComponent = tf.GetComponent <Text>(); var channelRoot = textComponent.transform.GetChild(0); var channelTextComponent = channelRoot != null?channelRoot.GetComponent <Text>() : null; if (tf != null && data != null && data.ChatMessage != null) { if (TargetIdDict != null) { if (!TargetIdDict.ContainsKey(data.SendRoleId)) { TargetIdDict[data.SendRoleId] = string.Empty; } TargetIdDict[data.SendRoleId] = data.SendRoleName; } if (IsFromSystem(data)) { var color = ColorUtility.ToHtmlStringRGB(UiCommonColor.SystemMessageColor); messageText = string.Format(commonMessageWithColorFormat, color, data.ChatMessage.Message); } else if (data.ChatType == (int)ChatType.PrivateChat) { var color = ColorUtility.ToHtmlStringRGB( UiCommonColor.GetChatColorByChatChannel(ChatChannel.PrivateChat)); messageText = string.Format(commonMessageWithColorFormat, color, messageText); long privateChatId = 0; if (data.SendRoleId == _chatState.MyselfId) { privateChatId = data.TargetId; messageText = string.Format(ScriptLocalization.hall_chat.word231, TargetIdDict[privateChatId]) + data.ChatMessage.Message; } else { privateChatId = data.SendRoleId; var name = string.Format(ScriptLocalization.hall_chat.PlayerNameFormat, data.SendRoleName); messageText = name + data.ChatMessage.Message; } PrivateChatRecentUseQueueUpdate(privateChatId); messageText = string.Format(commonMessageWithColorFormat, color, messageText); if (ChatListState != EUIChatListState.Send) { _curChannel = ChatChannel.PrivateChat; SetPrivateTarget(privateChatId); UpdateChannel(); } } else { var color = ColorUtility.ToHtmlStringRGB(UiCommonColor.ChatSenderColor); var name = string.Format(ScriptLocalization.hall_chat.PlayerNameFormat, data.SendRoleName); messageText = string.Format(commonMessageWithColorFormat, color, name) + data.ChatMessage.Message; } if (channelTextComponent != null) { channelTextComponent.text = channelName; } textComponent.text = messageText; } else { Logger.Error("Null object,can't addMessage"); } if (ChatListState == EUIChatListState.None) { ChatListState = EUIChatListState.Receive; } ResetTime(); //_closeViewAnim.Rewind(); }
public void AddMessage(BroadcastMessageData data) { var tf = GetNewMessageItem(); if (tf != null && data != null && data.ChatMessage != null) { if (TargetIdDict != null) { if (!TargetIdDict.ContainsKey(data.SendRoleId)) { TargetIdDict[data.SendRoleId] = string.Empty; } TargetIdDict[data.SendRoleId] = data.SendRoleName; } if (data.SendRoleId == 0) { tf.GetComponent <Text>().text = data.ChatMessage.Message; } else { tf.GetComponent <Text>().text = data.SendRoleName + ":" + data.ChatMessage.Message; } if (data.ChatType == (int)ChatType.PrivateChat) { long privateChatId = 0; if (data.SendRoleId == _chatState.MyselfId) { privateChatId = data.TargetId; tf.GetComponent <Text>().text = string.Format(ScriptLocalization.hall_chat.word231, TargetIdDict[privateChatId]) + data.ChatMessage.Message; PrivateChatRecentUseQueueUpdate(privateChatId); } else { privateChatId = data.SendRoleId; PrivateChatRecentUseQueueUpdate(privateChatId); } if (ChatListState != EUIChatListState.Send) { _curChannel = ChatChannel.PrivateChat; SetPrivateTarget(privateChatId); UpdateChannel(); } } if (data.SendRoleId > 0) { tf.GetComponent <Text>().color = UiCommonColor.GetChatChannelColor(ChatTypeToChannel((ChatType)data.ChatType)); } else { tf.GetComponent <Text>().color = Color.red; } } else { Logger.Error("Null object,can't addMessage"); } ResetTime(); _closeViewAnim.Rewind(); if (messageDict != null) { if (ChatListState == EUIChatListState.None) { ChatListState = EUIChatListState.Receive; } messageDict.Add(tf, data); } }