All Projects → heroiclabs → Nakama Unity

heroiclabs / Nakama Unity

Licence: other
Unity client for Nakama server.

Projects that are alternatives of or similar to Nakama Unity

Nakama Godot
Godot client for Nakama server written in GDScript.
Stars: ✭ 240 (+8.11%)
Mutual labels:  social, multiplayer, chat, realtime
Nakama
Distributed server for social and realtime games and apps.
Stars: ✭ 5,293 (+2284.23%)
Mutual labels:  social, multiplayer, realtime
Gophergameserver
🏆 Feature packed, easy-to-use game server API for Go back-ends and Javascript clients. Tutorials and examples included!
Stars: ✭ 61 (-72.52%)
Mutual labels:  multiplayer, chat
Janus Server
JanusVR Presence Server
Stars: ✭ 73 (-67.12%)
Mutual labels:  multiplayer, chat
Entitas Sync Framework
Networking framework for Entitas ECS. Targeted at turnbased games or other slow-paced genres.
Stars: ✭ 98 (-55.86%)
Mutual labels:  unity, multiplayer
Kotlin Firebase Group Chat
Group and OneonOne chat using firebase built in Kotlin similar to whatsapp.
Stars: ✭ 44 (-80.18%)
Mutual labels:  chat, realtime
Tiledesk Dashboard
The Tiledesk dashboard. Tiledesk is an Open Source Live Chat platform written in NodeJs, firebase and Angular.
Stars: ✭ 53 (-76.13%)
Mutual labels:  chat, realtime
Forgenetworkingremastered
In short, Forge Networking is a free and open source multiplayer game (multi-user) networking system that has a very good integration with the Unity game engine. You wanna make a multiplayer game or real time multi-user application? This is the library for you.
Stars: ✭ 1,338 (+502.7%)
Mutual labels:  unity, multiplayer
Chat21 Ios Sdk
DEPRECATED
Stars: ✭ 15 (-93.24%)
Mutual labels:  chat, realtime
Chat Realtime
Public & Private message. MySQL & Firebase.
Stars: ✭ 147 (-33.78%)
Mutual labels:  chat, realtime
Chat Ui Kit React
Build your own chat UI with React components in few minutes. Chat UI Kit from chatscope is an open source UI toolkit for developing web chat applications.
Stars: ✭ 131 (-40.99%)
Mutual labels:  social, chat
Unity Fastpacedmultiplayer
Features a Networking Framework to be used on top of Unity Networking, in order to implement an Authoritative Server with Lag Compensation, Client-Side Prediction/Server Reconciliation and Entity Interpolation
Stars: ✭ 162 (-27.03%)
Mutual labels:  unity, multiplayer
Multiplay Grpc Server
gRPC server for Multiplaying in Rust
Stars: ✭ 41 (-81.53%)
Mutual labels:  unity, multiplayer
Nakama Cpp
Generic C/C++ client for Nakama server.
Stars: ✭ 38 (-82.88%)
Mutual labels:  social, multiplayer
Vynchronize
Watch videos with friends online with the new real time video synchronization platform
Stars: ✭ 1,072 (+382.88%)
Mutual labels:  social, realtime
Vuejs Slack Clone Realtime
Slack clone using VueJS and firebase
Stars: ✭ 33 (-85.14%)
Mutual labels:  chat, realtime
Unityrtc
基于webrtc的unity多人游戏实时语音(A Unity Demo for Impl Real-time Game Voice Among Mutiplayers Based On WEBRTC)
Stars: ✭ 74 (-66.67%)
Mutual labels:  unity, realtime
Arenagame
A Unity First Person Shooter game made with Forge networking as an example project.
Stars: ✭ 190 (-14.41%)
Mutual labels:  unity, multiplayer
Com.unity.multiplayer.mlapi
A game networking framework built for the Unity Engine to abstract game networking concepts.
Stars: ✭ 781 (+251.8%)
Mutual labels:  unity, multiplayer
Ubernet
Flexible networking library for Unity
Stars: ✭ 10 (-95.5%)
Mutual labels:  unity, multiplayer

Nakama Unity

Unity client for Nakama server.

Nakama is an open-source server designed to power modern games and apps. Features include user accounts, chat, social, matchmaker, realtime multiplayer, and much more.

This client is built on the .NET client with extensions for Unity Engine. It requires the .NET4.6 scripting runtime version to be set in the editor.

Full documentation is online - https://heroiclabs.com/docs/unity-client-guide

Getting Started

You'll need to setup the server and database before you can connect with the client. The simplest way is to use Docker but have a look at the server documentation for other options.

Installing the SDK

  1. Install and run the servers. Follow these instructions.

  2. Install the Unity SDK. You have three options for this.

    1. To use an official release, you may download either the .unitypackage or .tar from the releases page and import it into your project. If you chose the .tar option, you can import it from a dropdown in the Unity Package Manager window.

    2. Alternatively, if you'd like to checkout a specific release or commit from Github and are using Unity 2019.4.1 or later, you can add the following to the manifest.json file in your project's Packages folder:

          "com.heroiclabs.nakama-unity": "https://github.com/heroiclabs/nakama-unity.git?path=/Packages/Nakama#<commit | tag>"
      
    3. Your final option is to download prebuilt binaries from the Asset Store.

  3. Use the connection credentials to build a client object.

    // using Nakama;
    const string scheme = "http";
    const string host = "127.0.0.1";
    const int port = 7350;
    const string serverKey = "defaultkey";
    var client = new Client(scheme, host, port, serverKey);
    

Usage

The client object has many methods to execute various features in the server or open realtime socket connections with the server.

Authenticate

There's a variety of ways to authenticate with the server. Authentication can create a user if they don't already exist with those credentials. It's also easy to authenticate with a social profile from Google Play Games, Facebook, Game Center, etc.

var deviceId = SystemInfo.deviceUniqueIdentifier;
var session = await client.AuthenticateDeviceAsync(deviceId);
Debug.Log(session);

Sessions

When authenticated the server responds with an auth token (JWT) which contains useful properties and gets deserialized into a Session object.

Debug.Log(session.AuthToken); // raw JWT token
Debug.LogFormat("Session user id: '{0}'", session.UserId);
Debug.LogFormat("Session user username: '{0}'", session.Username);
Debug.LogFormat("Session has expired: {0}", session.IsExpired);
Debug.LogFormat("Session expires at: {0}", session.ExpireTime); // in seconds.

It is recommended to store the auth token from the session and check at startup if it has expired. If the token has expired you must reauthenticate. The expiry time of the token can be changed as a setting in the server.

const string prefKeyName = "nakama.session";
ISession session;
var authToken = PlayerPrefs.GetString(prefKeyName);
if (string.IsNullOrEmpty(authToken) || (session = Session.Restore(authToken)).IsExpired)
{
    Debug.Log("Session has expired. Must reauthenticate!");
};
Debug.Log(session);

Requests

The client includes lots of builtin APIs for various features of the game server. These can be accessed with the async methods. It can also call custom logic as RPC functions on the server. These can also be executed with a socket object.

All requests are sent with a session object which authorizes the client.

var account = await client.GetAccountAsync(session);
Debug.LogFormat("User id: '{0}'", account.User.Id);
Debug.LogFormat("User username: '{0}'", account.User.Username);
Debug.LogFormat("Account virtual wallet: '{0}'", account.Wallet);

Socket

The client can create one or more sockets with the server. Each socket can have it's own event listeners registered for responses received from the server.

var socket = client.NewSocket();
socket.Connected += () => Debug.Log("Socket connected.");
socket.Closed += () => Debug.Log("Socket closed.");
await socket.ConnectAsync(session);

If you'd like socket handlers to execute outside Unity's main thread, pass the useMainThread: false argument:

var socket = client.NewSocket(useMainThread: false);

Unity WebGL

For WebGL builds you should switch the IHttpAdapter to use the UnityWebRequestAdapter and use the NewSocket() extension method to create the socket OR manually set the right ISocketAdapter per platform.

var client = new Client("defaultkey", UnityWebRequestAdapter.Instance);
var socket = client.NewSocket();

// or
#if UNITY_WEBGL && !UNITY_EDITOR
    ISocketAdapter adapter = new JsWebSocketAdapter();
#else
    ISocketAdapter adapter = new WebSocketAdapter();
#endif
var socket = Socket.From(client, adapter);

Errors

You can capture errors when you use await scaffolding with Tasks in C#.

try
{
    var account = await client.GetAccountAsync(session);
    Debug.LogFormat("User id: '{0}'", account.User.Id);
}
catch (ApiResponseException e)
{
    Debug.LogFormat("{0}", e);
}

Error Callbacks

You can avoid the use of await where exceptions will need to be caught and use Task.ContinueWith(...) as a callback style with standard C# if you prefer.

client.GetAccountAsync(session).ContinueWith(t =>
{
    if (t.IsFaulted || t.IsCanceled)
    {
        Debug.LogFormat("{0}", t.Exception);
        return;
    }
    var account = t.Result;
    Debug.LogFormat("User id: '{0}'", account.User.Id);
});

Contribute

The development roadmap is managed as GitHub issues and pull requests are welcome. If you're interested to enhance the code please open an issue to discuss the changes or drop in and discuss it in the community forum.

This project can be opened in Unity to create a ".unitypackage".

License

This project is licensed under the Apache-2 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].