Add the SDK via Unity Package Manager using the git URL:
https://github.com/widgrensit/asobi-unity.gitIn Unity: Window → Package Manager → + → Add package from git URL.
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);// 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}");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!");
};// 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);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();// 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");// Check wallet balance
var wallets = await client.Economy.GetWalletsAsync();
// Browse store
var store = await client.Economy.GetStoreAsync();
// Purchase item
await client.Economy.PurchaseAsync(listingId);Check out the full multiplayer arena shooter demo built with this SDK:
Unity Demo Project