Page cover

Lobby Chat Director

Simple chat made simple

Like what you're seeing?

Introduction

This tool exposes features present in the API to the inspector.

This is not required to use these features it is simply a helper tool allowing users who are more comfortable working with editor inspectors and game objects rather than classic C# objects and scripting to make use of the related feature.

The Lobby Chat Director must be attached to a Lobby Manager. The director simply exposes lobby chat features to the Steam Inspector.

Namespace

using HeathenEngineering.SteamworksIntegration;

Definition

public class LobbyChatDirector : MonoBehaviour

Events

evtMessageRecieved

public LobbyChatMsgEvent evtMessageRecieved

Occurs when a chat message is received on this lobby, The handler for this event would take a form similar to.

Uses the LobbyChatMsg object

private void Handler(LobbyChatMsg arg)
{
    //Handle the message
}

Fields and Attributes

HasLobby

public bool HasLobby => get;

Methods

Send

public bool Send(string message);
public bool Send(byte[] data);
public bool Send(object jsonObject);

Sends the related data to the lobby chat.

The total length of the message regardless of datatype must be less than 4kb in size. When sending a jsonobject Heathen will use Unity's JsonUtility to convert the object to a JSON string and then use UTF8 encoding to convert that to a byte[] before sending.

Use

Simple Chat

The most common use case for Lobby Chat is as a simple text-based chat system. In this model, your users would typically if not always be sending string data. You would simply listen on the evtMessageRecieved such as

private void HandleMessage(LobbyChatMsg message)
{
    Debug.Log(message.sender.Name + " sent a message: " + message.Message);
}

The above demonstrates a valid handler; you would want to display that message to your users. You can do this with whatever UI system you use that part is up to you.

See the Lobby Chat Msg object article for more information on what you can find in the message parameter.

Advanced Chat

You may have noticed that the Lobby Chat Director can send an object over the chat channel. This object must be serializable by UnityEngine.JsonUtility. What happens is that Heathen's system will use the JsonUtility and the UTF8 encoding tool in .NET to convert your object to a byte[] for sending.

You can create your own serializable object type such as a class or struct and send that via the Send method. When you receive a message you can fetch that type using the FromJson member.

private void HandleMessage(LobbyChatMsg message)
{
    var myObject = message.FromJson<MyCustomType>();
}

You can get as clever or remain as simple as you like with this system. For example, you could use class inheritance to determine the data type of a message or you could simply assume that any message that starts with the { character is a JSON string and so should be read via the FromJson.

You can see more examples and sample code in the Samples section of the asset.

Last updated