Send Message
Explains how to send messages to channels.
Send Public Message
Send a message to a specific channel by calling the ChatManager.Instance.SendPublicMessage() method. The sent message is delivered to all subscribers of that channel.
Method Information
| Item | Content |
|---|---|
| Method | ChatManager.Instance.SendPublicMessage(string channel, string text) |
| Callback | OnPublicMessage(ChatUserInfo sender, string message) - Called when message is received |
Parameters
| Parameter | Type | Description |
|---|---|---|
| channel | string | Channel name to send message to |
| text | string | Message content to send |
Usage Example
using UnityEngine;
using UnityEngine.UI;
public class ChatExample : MonoBehaviour, IChatListener
{
public InputField _inputChat;
public Text _textView;
private string myChannel = "Default Channel";
public void SendMessage()
{
ChatManager.Instance.SendPublicMessage(myChannel, _inputChat.text);
_inputChat.text = "";
}
public void OnPublicMessage(ChatUserInfo sender, string message)
{
// Apply prohibited word filter to received message
Debug.Log($"[{sender.visitorName}] {ChatManager.Instance.Filter(message)}");
_textView.text += $"\n[{sender.visitorName}] {ChatManager.Instance.Filter(message)}";
}
// ... Other IChatListener method implementations
}
Send Private Message (Whisper)
Send a message only to a specific user by calling the ChatManager.Instance.SendPrivateMessage() method.
Method Information
| Item | Content |
|---|---|
| Method | ChatManager.Instance.SendPrivateMessage(string targetUserId, string text) |
| Callback | OnPrivateMessage(ChatUserInfo sender, string message) - Called when message is received |
Parameters
| Parameter | Type | Description |
|---|---|---|
| targetUserId | string | User ID to receive message |
| text | string | Message content to send |
Usage Example
using UnityEngine;
using UnityEngine.UI;
public class ChatExample : MonoBehaviour, IChatListener
{
public InputField _inputChat;
public void SendPrivateMessage()
{
string targetUserId = "string";
ChatManager.Instance.SendPrivateMessage(targetUserId, _inputChat.text);
}
public void OnPrivateMessage(ChatUserInfo sender, string message)
{
// Apply prohibited word filter to received whisper
Debug.Log($"[Whisper from {sender.visitorName}] {ChatManager.Instance.Filter(message)}");
}
// ... Other IChatListener method implementations
}