Giter Club home page Giter Club logo

unity-webgl-signalr's Introduction

Unity WebGL SignalR

Repo Components

  • 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.

Library

The files needed for importing as a 'Plugin' in a Unity3D project are located at:

Unity/Assets/Plugins/SignalR

Client C# Packages

  • 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.

Client JS File

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

Source

Usage

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);
};

Properties

Properties

Hub

  • 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

Successful Result

Result

References

unity-webgl-signalr's People

Contributors

evanlindsey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.