/// <summary> /// 确保私聊消息长度 /// </summary> /// <param name="chat"></param> /// <param name="length"></param> private static void GuaranteedPrivateMessageLength(ref PrivateChatSaveInfo chat, int length) { while (chat.ChatInfos.Count > length) { chat.ChatInfos.RemoveAt(0); } }
/// <summary> /// 插入一条空白私聊信息 /// </summary> /// <param name="playUid"></param> public static void CreationNullPrivateChatMessage(long playUid, int iconId, string iconUrl, string playName, int experience) { var privateChat = _privateChannelMessages.Find((data) => { if (data.PrivateChatRoleUid == playUid) { return(true); } return(false); }); if (privateChat == null) { PrivateChatSaveInfo priChat = new PrivateChatSaveInfo(); priChat.PrivateChatRoleUid = playUid; priChat.iconId = iconId; priChat._iconUrl = iconUrl; priChat._playName = playName; priChat._experience = experience; priChat.LastTimeTicks = TimeHelper.ClientNowSeconds(); priChat.ChatInfos = new List <ChatInfo>(); _privateChannelMessages.Insert(0, priChat); } else { privateChat._playName = playName; privateChat.iconId = iconId; privateChat._iconUrl = iconUrl; privateChat._experience = experience; _privateChannelMessages.Remove(privateChat); _privateChannelMessages.Insert(0, privateChat); } }
/// <summary> /// 设置按钮数据 /// </summary> /// <param name="data"></param> public void SetData(PrivateChatSaveInfo data, ToggleGroup toggleGroup) { if (!_isInitial) { Initial(); } _data = data; _toggle.group = toggleGroup; gameObject.SetActive(true); RefreshDataShow(); }
/// <summary> /// 更新聊天消息是否已经阅读 /// </summary> /// <param name="priChat"></param> private static void UpdatePrivateChatIsRead(ref PrivateChatSaveInfo priChat) { if (priChat.PrivateChatRoleUid == StaticData.Uid) { priChat.IsRead = true; } else { priChat.IsRead = false; } }
/// <summary> /// 清理空白的私聊信息 /// </summary> public static void ClearBlankPrivateChat() { for (int i = 0; i < _privateChannelMessages.Count; i++) { PrivateChatSaveInfo data = _privateChannelMessages[i]; if (data.ChatInfos == null || data.ChatInfos.Count <= 0) { _privateChannelMessages.Remove(data); } } }
/// <summary> /// 根据下标获取世界聊天列表中的数据 /// </summary> /// <param name="index"></param> /// <returns></returns> public static ChatInfo GetPrivateChatData(long uid, int index) { ChatInfo chatInfo = new ChatInfo(); PrivateChatSaveInfo privateChatSaveInfo = FindMessagePrivateChat_UID(uid); if (privateChatSaveInfo != null && index < privateChatSaveInfo.ChatInfos.Count) { chatInfo = privateChatSaveInfo.ChatInfos[index]; } return(chatInfo); }
/// <summary> /// 创建私聊头像按钮 /// </summary> /// <param name="data"></param> void CreatePrivateChatItem(PrivateChatSaveInfo data) { if (_privateChatIconItemControllerDic.ContainsKey(data.PrivateChatRoleUid)) { return; } GameObject obj = GameObject.Instantiate(_privateChatIconItem.gameObject, _topTwoScrollRect.content); PrivateChatIconItemController privateChatIconItemController = obj.GetComponent <PrivateChatIconItemController>(); privateChatIconItemController.SetData(data, _topTwoToggleGroup); _privateChatIconItemControllerDic.Add(data.PrivateChatRoleUid, privateChatIconItemController); }
/// <summary> /// 获取对应私聊消息数据量 /// </summary> /// <param name="uid"></param> /// <returns></returns> public static int GetPrivateChatNumber(long uid) { PrivateChatSaveInfo privateChatSaveInfo = FindMessagePrivateChat_UID(uid); if (privateChatSaveInfo != null) { return(privateChatSaveInfo.ChatInfos.Count); } else { return(0); } }
/// <summary> /// 获取私聊玩家经验 /// </summary> public static int GetPrivateChatExperience(PrivateChatSaveInfo data) { int experience = data._experience; for (int i = 0; i < data.ChatInfos.Count; i++) { ChatInfo ChatInfodata = data.ChatInfos[i]; if (ChatInfodata._playUid == data.PrivateChatRoleUid) { experience = (int)ChatInfodata._experience; } } return(experience); }
/// <summary> /// 获取私聊玩家头像id /// </summary> public static int GetPrivateChatIconId(PrivateChatSaveInfo data) { int iconId = data.iconId; for (int i = 0; i < data.ChatInfos.Count; i++) { ChatInfo ChatInfodata = data.ChatInfos[i]; if (ChatInfodata._playUid == data.PrivateChatRoleUid) { iconId = ChatInfodata._iconId; } } return(iconId); }
/// <summary> /// 获取私聊玩家名字 /// </summary> public static string GetPrivateChatName(PrivateChatSaveInfo data) { string playName = data._playName; for (int i = 0; i < data.ChatInfos.Count; i++) { ChatInfo ChatInfodata = data.ChatInfos[i]; if (ChatInfodata._playUid == data.PrivateChatRoleUid) { playName = ChatInfodata._playName; } } return(playName); }
public void Dispose() { _data = null; Destroy(gameObject); }
/// <summary> /// 接收私聊消息 /// </summary> public static void ReceivePrivateChatMessage(long playUid, ChatInfo chatInfo) { long lastTime = 0; var privateChat = _privateChannelMessages.Find((priChat) => { if (priChat.PrivateChatRoleUid == playUid) { return(true); } return(false); }); //1.判断私聊是否建立过 if (privateChat != null) { //获取上次消息时间 if (privateChat.ChatInfos.Count > 0) { lastTime = privateChat.ChatInfos[privateChat.ChatInfos.Count - 1].TimeTicks; } //间隔时间大于300s if (chatInfo.TimeTicks - lastTime >= StaticData.configExcel.GetVertical().ChatMessageInterval) { ChatInfo timeChatInfo = new ChatInfo(true); privateChat.ChatInfos.Add(timeChatInfo); } //更新时间 privateChat.LastTimeTicks = chatInfo.TimeTicks; //更新是否阅读 //UpdatePrivateChatIsRead(ref privateChat); UpdatePrivateChatIsRead(privateChat.PrivateChatRoleUid, false); privateChat.ChatInfos.Add(chatInfo); privateChat.RefreshData(chatInfo); if ((privateChat.iconId == 0 && chatInfo._playUid == playUid) || (chatInfo._playUid == playUid && privateChat.iconId != chatInfo._iconId)) { privateChat.iconId = chatInfo._iconId; } //判断消息数量是否大于 20 GuaranteedPrivateMessageLength(ref privateChat, StaticData.configExcel.GetVertical().PrivateChatDataNumber); _privateChannelMessages.Remove(privateChat); _privateChannelMessages.Insert(0, privateChat); _receivePrivateInformationAction?.Invoke(privateChat.PrivateChatRoleUid); } else //没有建立过私聊 { PrivateChatSaveInfo priChat = new PrivateChatSaveInfo(); priChat.PrivateChatRoleUid = playUid; priChat.RefreshData(chatInfo); UpdatePrivateChatIsRead(priChat.PrivateChatRoleUid, false); priChat.ChatInfos = new List <ChatInfo>(); priChat.ChatInfos.Add(chatInfo); _privateChannelMessages.Insert(0, priChat); //_privateChannelMessages.Add(priChat); //判断建立聊天人数是否大于规定的上线 GuaranteedPrivateChatNumber(StaticData.configExcel.GetVertical().ChatPrivateRoleMaxNumber); _receivePrivateInformationAction?.Invoke(priChat.PrivateChatRoleUid); } //接收消息就存储 PrivateChatSaveFile(); _chatFtameTakePushDataAction?.Invoke(chatInfo, true); }