{"id":23543155,"url":"https://github.com/ehsan-mohammadi/unityr","last_synced_at":"2025-06-30T08:34:47.887Z","repository":{"id":40863047,"uuid":"195639590","full_name":"ehsan-mohammadi/UnityR","owner":"ehsan-mohammadi","description":"Unity3D, SignalR real-time multiplayer game","archived":false,"fork":false,"pushed_at":"2023-07-02T05:37:38.000Z","size":4939,"stargazers_count":58,"open_issues_count":0,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-01T12:59:36.026Z","etag":null,"topics":["game","multiplayer","real-time","realtime","server","signalr","unity","unity3d"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ehsan-mohammadi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-07-07T10:45:51.000Z","updated_at":"2025-05-12T08:29:21.000Z","dependencies_parsed_at":"2025-04-23T22:13:50.442Z","dependency_job_id":null,"html_url":"https://github.com/ehsan-mohammadi/UnityR","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ehsan-mohammadi/UnityR","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsan-mohammadi%2FUnityR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsan-mohammadi%2FUnityR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsan-mohammadi%2FUnityR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsan-mohammadi%2FUnityR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ehsan-mohammadi","download_url":"https://codeload.github.com/ehsan-mohammadi/UnityR/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsan-mohammadi%2FUnityR/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262739533,"owners_count":23356735,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["game","multiplayer","real-time","realtime","server","signalr","unity","unity3d"],"created_at":"2024-12-26T06:18:46.817Z","updated_at":"2025-06-30T08:34:47.877Z","avatar_url":"https://github.com/ehsan-mohammadi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UnityR\n\n\u003e Unity3D, SignalR real-time multiplayer\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://github.com/ehsan-mohammadi/UnityR/blob/master/Images/UnityR_gif.gif\"/\u003e\u003c/p\u003e\n\n**UnityR** is a smaple multiplayer game. This project consist of two main parts: **Server** and **Game**.\n\nServer part made with [SignalR](https://github.com/SignalR/SignalR) technology and Game part is a Unity3D project. Unity game uses [BestHttp](https://assetstore.unity.com/packages/tools/network/best-http-10872) library to connect the SignalR server.\n\n## Server\nThe server consists of two classes: [`Startup.cs`](https://github.com/ehsan-mohammadi/UnityR/blob/master/Server/Server/Startup.cs) and [`GameHub.cs`](https://github.com/ehsan-mohammadi/UnityR/blob/master/Server/Server/Hubs/GameHub.cs).\n\nHere is an overview of `Stratup.cs`:\n\n```csharp\npublic class Startup\n{\n    /// \u003csummary\u003e\n    /// Configure the signalR program\n    /// \u003c/summary\u003e\n    public void Configuration(IAppBuilder app)\n    {\n        // Maps signalR hubs to the app builder pipeline at \"/signalr\"\n        app.MapSignalR();\n    }\n}\n```\n\n`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:\n\n```csharp\npublic class GameHub : Hub\n{\n    // Players list that save the players connection id and group id\n    private static Dictionary\u003cstring, string\u003e players = new Dictionary\u003cstring, string\u003e();\n\n    /// \u003csummary\u003e\n    /// When player join in the game\n    /// \u003c/summary\u003e\n    public override Task OnConnected()\n    {\n        // Add player to the players list and set the group id to -2\n        players.Add(Context.ConnectionId, \"-2\");\n\n        return base.OnConnected();\n    }\n\n    /// \u003csummary\u003e\n    /// When player disconnected\n    /// \u003c/summary\u003e\n    public override Task OnDisconnected(bool stopCalled)\n    {\n        string groupName = players[Context.ConnectionId];\n\n        // Remove player from the players list and send message to other player to tell him the opponent left\n        players.Remove(Context.ConnectionId);\n        Clients.Group(groupName).OpponentLeft();\n\n        return base.OnDisconnected(stopCalled);\n    }\n      \n    // And other methods...\n    ...\n}\n```\n\nFor more information, read [SignalR documentation](https://docs.microsoft.com/en-us/aspnet/signalr/overview/getting-started/introduction-to-signalr).\n\n## Game\nThe game consist of a main class called [`SignalRClient.cs`](https://github.com/ehsan-mohammadi/UnityR/blob/master/Game/Assets/Scripts/SignalRClient.cs). By this class, the game communicate with the server. Here is an overview of `SignalRClient.cs`:\n\n```csharp\npublic class SignalRClient : MonoBehaviour \n{\n    // SignalR variables\n    private static Uri uri = new Uri(\"http://localhost:5000/signalr/\");\n    private static GameHub gameHub;\n    private static Connection signalRConnection;\n    ...\n    public void Connect()\n    {\n        // Initialize the connection\n        gameHub = new GameHub();\n        signalRConnection = new Connection(uri, gameHub);\n        signalRConnection.Open();\n        \n        signalRConnection.OnConnected += (conn) =\u003e \n        {\n            Debug.Log(\"Connect Successfully!\");\n        };\n        ...\n    }\n    ...\n    /// \u003csummary\u003e\n    /// A class for connection with server hub\n    /// \u003c/summary\u003e\n    public class GameHub : Hub\n    {\n        public GameHub() : base(\"GameHub\")\n        {\n            // Register callback functions that received from the server\n            base.On(\"JoinToOpponent\", Joined);\n            ...\n        }\n\n        /// \u003csummary\u003e\n        /// Return the join state from server - -1: Opponent not found, Otherwise: Opponent found\n        /// \u003c/summary\u003e\n        private void Joined(Hub hub, MethodCallMessage msg)\n        {\n            int playerId = int.Parse(msg.Arguments[0].ToString());\n\n            if (playerId == -1)\n                Debug.Log(\"Waiting for an opponent...\");\n            else\n                Debug.Log(\"Player joined!\");\n        }\n        ...\n    }\n}\n```\n\nFor more information, read [BestHttp documentation](https://docs.google.com/document/d/181l8SggPrVF1qRoPMEwobN_1Fn7NXOu-VtfjE6wvokg/edit).\n\n## Getting started\n\n- Clone a copy of the repo: `git clone \"https://github.com/ehsan-mohammadi/UnityR.git\"`\n- Open the server project with Visual Studio 2013 or above; Then run the server.\n- Open the Game project with Unity3D 5.5.1f1 or above and run it.\n\n**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](https://assetstore.unity.com/packages/tools/network/best-http-10872) and extract it in the `Game\\Assets\\Plugins` directory of the game. (Read [`BestHttp.md`](https://github.com/ehsan-mohammadi/UnityR/blob/master/Game/Assets/Plugins/BestHttp.md) Carefully)\n\n**Note 2:** You can build the game, then open two windows of it to test the server.\n\n## License\n\nUnityR is available to anybody free of charge, under the terms of MIT License (See [LICENSE](../master/LICENSE)).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fehsan-mohammadi%2Funityr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fehsan-mohammadi%2Funityr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fehsan-mohammadi%2Funityr/lists"}