定向消息
Send direct messages between users.
阅读时间3 分钟最后更新于 13 天前
VivoxMessages 可以发送给已登录服务的个人玩家。此功能通常称为定向消息 (DM)。
发送定向消息
您可以使用VivoxService.Instance.SendDirectTextMessageAsync(string playerId, string message)void SendMessageAsync(string playerId){ if (string.IsNullOrEmpty(MessageInputField.text)) { return; } VivoxService.Instance.SendChannelTextMessageAsync(playerId, MessageInputField.text); MessageInputField.text = string.Empty;}
接收定向消息
为了接收来自其他用户的消息,必须订阅VivoxService.Instance.DirectedMessageReceivedVivoxMessage.ChannelNameVivoxMessage.FromSelf//Subscribe to this event at some point in the Vivox initialization process,//preferably before joining any channels.. . .VivoxService.Instance.DirectedMessageReceived += OnDirectedMessageReceived;. . .void OnDirectedMessageReceived(VivoxMessage message){ var senderName = message.SenderDisplayName; var senderId = message.SenderPlayerId; var messageText = message.MessageText; var timeReceived = message.ReceivedTime; var language = message.Language; var messageId = message.MessageId;}
文本私信历史记录
Vivox 还允许用户使用VivoxService.Instance.GetDirectTextMessageHistoryAsync(string playerId, int requestSize = 10, ChatHistoryQueryOptions chatHistoryQueryOptions = null)IReadOnlyCollectionChatHistoryQueryOptionsvoid FetchHistoryAsync(){ var historyMessages = await VivoxService.Instance.GetDirectTextMessageHistoryAsync(LobbyChannelName, 10); //Reversing the messages so they display from oldest to newest var reversedMessages = historyMessages.Reverse(); foreach(VivoxMessage message in reversedMessages) { Debug.Log($"{message.SenderDisplayName}: {message.MessageText}"); }}
编辑私信
Vivox 允许用户使用VivoxService.Instance.EditDirectTextMessageAsync(string messageId, string newMessage)VivoxService.Instance.DirectedMessageEditedpublic async void UpdateDirectedMessageAsync(VivoxMessage messageToUpdate, string updatedMessageText){ await VivoxService.Instance.EditDirectTextMessageAsync(messageToUpdate.MessageId, updatedMessageText);}
删除私信
Vivox 允许用户使用VivoxService.Instance.DeleteDirectTextMessageAsync(string messageId)VivoxService.Instance.DirectedMessageDeletedpublic async void DeleteDirectMessageAsync(VivoxMessage messageToDelete){ await VivoxService.Instance.DeleteDirectTextMessageAsync(messageToDelete.MessageId)}