All Projects → ehsan-mohammadi → UnityR

ehsan-mohammadi / UnityR

Licence: MIT license
Unity3D, SignalR real-time multiplayer game

Programming Languages

javascript
184084 projects - #8 most used programming language
C#
18002 projects

Projects that are alternatives of or similar to UnityR

Nakama Godot
Godot client for Nakama server written in GDScript.
Stars: ✭ 240 (+389.8%)
Mutual labels:  multiplayer, realtime
signalr-client
SignalR client library built on top of @aspnet/signalr. This gives you more features and easier to use.
Stars: ✭ 48 (-2.04%)
Mutual labels:  realtime, signalr
Nakama Unity
Unity client for Nakama server.
Stars: ✭ 222 (+353.06%)
Mutual labels:  multiplayer, realtime
ChatService
ChatService (SignalR).
Stars: ✭ 26 (-46.94%)
Mutual labels:  realtime, signalr
SocketIOUnity
A Wrapper for socket.io-client-csharp to work with Unity.
Stars: ✭ 69 (+40.82%)
Mutual labels:  multiplayer, realtime
Eureca.io
eureca.io : a nodejs bidirectional RPC that can use WebSocket, WebRTC or XHR fallback as transport layers
Stars: ✭ 341 (+595.92%)
Mutual labels:  multiplayer, realtime
dotNetify-react-native-demo
DotNetify + React Native + .NET Core demo
Stars: ✭ 43 (-12.24%)
Mutual labels:  realtime, signalr
Sapphiredb
SapphireDb Server, a self-hosted, easy to use realtime database for Asp.Net Core and EF Core
Stars: ✭ 326 (+565.31%)
Mutual labels:  realtime, signalr
Dotnetify
Simple, lightweight, yet powerful way to build real-time web apps.
Stars: ✭ 927 (+1791.84%)
Mutual labels:  realtime, signalr
mangband
A free online multi-player realtime roguelike game based on Angband
Stars: ✭ 54 (+10.2%)
Mutual labels:  multiplayer, realtime
Nakama
Distributed server for social and realtime games and apps.
Stars: ✭ 5,293 (+10702.04%)
Mutual labels:  multiplayer, realtime
karting
A multiplayer racing example project in Unity using the SocketWeaver SDK
Stars: ✭ 39 (-20.41%)
Mutual labels:  multiplayer
Colyseus.js
⚔ Colyseus Multiplayer SDK for JavaScript/TypeScript
Stars: ✭ 245 (+400%)
Mutual labels:  multiplayer
CoCreate-dashboard
A simple dashboard component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.
Stars: ✭ 20 (-59.18%)
Mutual labels:  realtime
Rustarok
Multiplayer, fast-paced Moba style game
Stars: ✭ 223 (+355.1%)
Mutual labels:  multiplayer
Team-Capture
Team-Capture - A multiplayer FPS game, inspired by games like Quake and TF2. Done in Unity
Stars: ✭ 81 (+65.31%)
Mutual labels:  multiplayer
Logisticspipes
The RS485 take on LogisticsPipes -- ESTḌ 2012
Stars: ✭ 215 (+338.78%)
Mutual labels:  multiplayer
Bzflag
3D multi-player tank battle game
Stars: ✭ 207 (+322.45%)
Mutual labels:  multiplayer
livebook
Automate code & data workflows with interactive Elixir notebooks
Stars: ✭ 3,402 (+6842.86%)
Mutual labels:  realtime
df multiplay
Dwarffortress multiplayer scripts and stuff
Stars: ✭ 13 (-73.47%)
Mutual labels:  multiplayer

UnityR

Unity3D, SignalR real-time multiplayer

UnityR is a smaple multiplayer game. This project consist of two main parts: Server and Game.

Server part made with SignalR technology and Game part is a Unity3D project. Unity game uses BestHttp library to connect the SignalR server.

Server

The server consists of two classes: Startup.cs and GameHub.cs.

Here is an overview of Stratup.cs:

public class Startup
{
    /// <summary>
    /// Configure the signalR program
    /// </summary>
    public void Configuration(IAppBuilder app)
    {
        // Maps signalR hubs to the app builder pipeline at "/signalr"
        app.MapSignalR();
    }
}

GameHub.cs enables you to call methods on connected clients from the server. In this class, you define methods that are called by clients. Here is an overview of this class:

public class GameHub : Hub
{
    // Players list that save the players connection id and group id
    private static Dictionary<string, string> players = new Dictionary<string, string>();

    /// <summary>
    /// When player join in the game
    /// </summary>
    public override Task OnConnected()
    {
        // Add player to the players list and set the group id to -2
        players.Add(Context.ConnectionId, "-2");

        return base.OnConnected();
    }

    /// <summary>
    /// When player disconnected
    /// </summary>
    public override Task OnDisconnected(bool stopCalled)
    {
        string groupName = players[Context.ConnectionId];

        // Remove player from the players list and send message to other player to tell him the opponent left
        players.Remove(Context.ConnectionId);
        Clients.Group(groupName).OpponentLeft();

        return base.OnDisconnected(stopCalled);
    }
      
    // And other methods...
    ...
}

For more information, read SignalR documentation.

Game

The game consist of a main class called SignalRClient.cs. By this class, the game communicate with the server. Here is an overview of SignalRClient.cs:

public class SignalRClient : MonoBehaviour 
{
    // SignalR variables
    private static Uri uri = new Uri("http://localhost:5000/signalr/");
    private static GameHub gameHub;
    private static Connection signalRConnection;
    ...
    public void Connect()
    {
        // Initialize the connection
        gameHub = new GameHub();
        signalRConnection = new Connection(uri, gameHub);
        signalRConnection.Open();
        
        signalRConnection.OnConnected += (conn) => 
        {
            Debug.Log("Connect Successfully!");
        };
        ...
    }
    ...
    /// <summary>
    /// A class for connection with server hub
    /// </summary>
    public class GameHub : Hub
    {
        public GameHub() : base("GameHub")
        {
            // Register callback functions that received from the server
            base.On("JoinToOpponent", Joined);
            ...
        }

        /// <summary>
        /// Return the join state from server - -1: Opponent not found, Otherwise: Opponent found
        /// </summary>
        private void Joined(Hub hub, MethodCallMessage msg)
        {
            int playerId = int.Parse(msg.Arguments[0].ToString());

            if (playerId == -1)
                Debug.Log("Waiting for an opponent...");
            else
                Debug.Log("Player joined!");
        }
        ...
    }
}

For more information, read BestHttp documentation.

Getting started

  • Clone a copy of the repo: git clone "https://github.com/ehsan-mohammadi/UnityR.git"
  • Open the server project with Visual Studio 2013 or above; Then run the server.
  • Open the Game project with Unity3D 5.5.1f1 or above and run it.

Note 1: Because of the BestHttp is a purchased library, I should to ignore this in my repo. So you need to download it from Unity Asset Store and extract it in the Game\Assets\Plugins directory of the game. (Read BestHttp.md Carefully)

Note 2: You can build the game, then open two windows of it to test the server.

License

UnityR is available to anybody free of charge, under the terms of MIT License (See LICENSE).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].