- Unity: Unity3D project with Core SignalR library plugin (for editor / WebGL) and example scene
- Server: ASP.NET Core project with a single SignalR hub for connection (CORS enabled)
- Client: Node.js/Express project to serve built WebGL files from Unity
The hub is set to receive and broadcast a global message that invokes the listeners of all connected clients.
This functionality could be greatly extended for actual use in games or applications.
The files needed for importing as a 'Plugin' in a Unity3D project are located at:
- Microsoft.AspNetCore.SignalR.Client - 3.1.2
This and all dependencies were manually imported from NuGet using builds targeting .NET Standard 2.0. For specific versions, see:
Unity/Assets/Plugins/SignalR/Packages/Versions.txt
Note: These packages are only needed for use in the editor.
Once the WebGL project is built, the following must be referenced in the 'head' section of index.html:
https://cdn.jsdelivr.net/npm/@microsoft/[email protected]/dist/browser/signalr.min.js
Attach a script file to a GameObject in your scene and add the following code to your 'Start' method:
srLib = new SignalRLib();
srLib.Init("<SignalRHubURL>", "<HubListenerName>");
srLib.ConnectionStarted += (object sender, MessageEventArgs e) =>
{
Debug.Log(e.message);
srLib.SendMessage("<HubMethodName>", "<MessageToSend>");
};
srLib.MessageReceived += (object sender, MessageEventArgs e) =>
{
Debug.Log(e.message);
};
- SignalR Hub URL: Endpoint for the target SignalR hub
- Hub Listener Name: Name of listener to be invoked by the hub
- Hub Method Name: Name of method in the Hub to receive message
- Message to Send: Message to send to the hub