Subscribe to Channel
Explains how to enter (subscribe to) a specific channel.
Description
Enter a specific channel by calling the ChatManager.Instance.Subscribe() method. After entering, you can receive messages from that channel. Set the prevMessageCount parameter to retrieve previous chat history.
Method Information
| Item | Content |
|---|---|
| Method | ChatManager.Instance.Subscribe(string channel, int prevMessageCount = 0) |
| Callback | OnSubscribed(ChatUserInfo user) - Called when user enters |
Parameters
| Parameter | Type | Description |
|---|---|---|
| channel | string | Channel name to subscribe to |
| prevMessageCount | int | Number of previous messages to fetch (default: 0) |
Unity C# Usage Example
using UnityEngine;
public class ChatExample : MonoBehaviour, IChatListener
{
private string myChannel = "Default Channel";
public void EnterChannel()
{
myChannel = "string";
// Fetch 10 previous messages
ChatManager.Instance.Subscribe(myChannel, 10);
}
public void OnSubscribed(ChatUserInfo user)
{
Debug.Log($"{user.visitorName} entered");
}
// ... Other IChatListener method implementations
}