/// <summary> /// 点击好友列表页面的发送消息按钮 /// </summary> /// <param name="param"></param> private void ClickSendToFriend(object param) { button.clip = sendMsg; button.Play(); var chatMsg = new mmopb.sendMessageToOnlineFriend_req(); friendView.chatPanle.SetActive(true); GameObject friend = (GameObject)param; FriendDetail friendDetail = friend.GetComponentInChildren <FriendDetail>(); roleId_chat = friendDetail.friendId; friendDetail.messageNotice.SetActive(false); //加载预制体 GameObject _message = Resources.Load("MessageFriend") as GameObject; LinkedList <Message> friendMsg; if (messages.TryGetValue(roleId_chat, out friendMsg)) { foreach (Message friend_message in friendMsg) { // 对象初始化 GameObject message = Instantiate(_message, friendView.chatParentTransForm); MessageDetail messageDetail = message.GetComponent <MessageDetail>(); DateTime dt = DateTime.Parse("1970-01-01 00:00:00").AddSeconds(friend_message.Time); dt = dt.AddSeconds(8 * 60 * 60); // +8h的时差 string time = dt.ToString("HH:mm:ss"); messageDetail.time.text = "【" + time + "】"; messageDetail.name.text = friend_message.Name; messageDetail.content.text = ":" + friend_message.Content; } } }
/// <summary> /// 在聊天框点击发送按钮 /// </summary> /// <param name="param"></param> private void ClickSendToTargetFriend(object param) { button.clip = sendMsg; button.Play(); var sendMessageToOnlineFriend_req = new mmopb.sendMessageToOnlineFriend_req(); sendMessageToOnlineFriend_req.content = friendView.chatMsg.text; sendMessageToOnlineFriend_req.roleId = roleId_chat; ClientNet.Instance.Send(ProtoHelper.EncodeWithName(sendMessageToOnlineFriend_req)); //加载预制体 GameObject _message = Resources.Load("MessageMe") as GameObject; // 对象初始化 GameObject message = Instantiate(_message, friendView.chatParentTransForm); Text myContent = message.GetComponentInChildren <Text>(); myContent.text = friendView.chatMsg.text; //清空聊天框 friendView.chatMsg.text = ""; }