← Back to home

Unity SDK

Integrate Asobi into your Unity project. Supports Unity 2021.3 and later.

View on GitHub

Installation

Add the SDK via Unity Package Manager using the git URL:

https://github.com/widgrensit/asobi-unity.git

In Unity: Window → Package Manager → + → Add package from git URL.

Setup

Create a client and connect to your Asobi server:

using Asobi;

var client = new AsobiClient("localhost", 8080);

// Or with SSL
var client = new AsobiClient("api.mygame.com", 443, useSsl: true);

Authentication

// Register a new player
var auth = await client.Auth.RegisterAsync(
    "player1", "secret123", "Player One");

// Login
var auth = await client.Auth.LoginAsync("player1", "secret123");

// Session is stored automatically
Debug.Log($"Logged in as {client.PlayerId}");

Real-Time Connection

Connect via WebSocket for matchmaking, match state, and chat:

// Connect
client.Realtime.OnConnected += () => Debug.Log("Connected!");
await client.Realtime.ConnectAsync();

// Listen for match state updates
client.Realtime.OnMatchState += (state) => {
    // Update game objects from server state
};

// Listen for matchmaker results
client.Realtime.OnMatchmakerMatched += (data) => {
    Debug.Log("Match found!");
};

Matchmaking

// Queue for a match via WebSocket
await client.Realtime.AddToMatchmakerAsync("arena");

// Or via REST API
var ticket = await client.Matchmaker.AddAsync("arena");
var status = await client.Matchmaker.StatusAsync(ticket.Id);

Match Input

Send player input to the server-authoritative game loop:

// Join a match
await client.Realtime.JoinMatchAsync(matchId);

// Send input (fire-and-forget for low latency)
await client.Realtime.SendMatchInputAsync(
    "{\"action\":\"move\",\"x\":1,\"y\":0}");

// Leave match
await client.Realtime.LeaveMatchAsync();

Leaderboards

// Submit a score
await client.Leaderboards.SubmitScoreAsync("weekly", 1500);

// Get top scores
var top = await client.Leaderboards.GetTopAsync("weekly", limit: 10);

// Get scores around current player
var around = await client.Leaderboards.GetAroundSelfAsync("weekly");

Economy

// Check wallet balance
var wallets = await client.Economy.GetWalletsAsync();

// Browse store
var store = await client.Economy.GetStoreAsync();

// Purchase item
await client.Economy.PurchaseAsync(listingId);

Demo Project

Check out the full multiplayer arena shooter demo built with this SDK:

Unity Demo Project