Lobby Chat Director
Simple chat made simple
Available in the Steamworks Complete asset.
This tool simply exposes features present in the API to the inspector.
This is not required to use these features it is simply a helper tool allowing user's who are more comfortable working with editor inspectors and game object rather than classic C# objects and scripting to make use of the related feature.

Introduction

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

Namespace

1
using HeathenEngineering.SteamworksIntegration;
Copied!

Definition

1
public class LobbyChatDirector : MonoBehaviour
Copied!

Events

evtMessageRecieved

1
public LobbyChatMsgEvent evtMessageRecieved
Copied!
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
1
private void Handler(LobbyChatMsg arg)
2
{
3
//Handle the message
4
}
Copied!

Fields and Attributes

HasLobby

1
public bool HasLobby => get;
Copied!

Methods

Send

1
public bool Send(string message);
Copied!
1
public bool Send(byte[] data);
Copied!
1
public bool Send(object jsonObject);
Copied!
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
1
private void HandleMessage(LobbyChatMsg message)
2
{
3
Debug.Log(message.sender.Name + " sent a message: " + message.Message);
4
}
Copied!
The above simply demonstrates a valid handler; you would of course want to display that message to your users. You can do this with whatever UI system you choose to 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 paramiter.

Advanced Chat

You may have notiiced 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 recieve a message you can fetch that type using the FromJson member.
1
private void HandleMessage(LobbyChatMsg message)
2
{
3
var myObject = message.FromJson<MyCustomType>();
4
}
Copied!
You can get as clever or remain as simple as you like with this system. For example you could use class inheritance to determin 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.