GameService.Sdk.Core
1.0.8
dotnet add package GameService.Sdk.Core --version 1.0.8
NuGet\Install-Package GameService.Sdk.Core -Version 1.0.8
<PackageReference Include="GameService.Sdk.Core" Version="1.0.8" />
<PackageVersion Include="GameService.Sdk.Core" Version="1.0.8" />
<PackageReference Include="GameService.Sdk.Core" />
paket add GameService.Sdk.Core --version 1.0.8
#r "nuget: GameService.Sdk.Core, 1.0.8"
#:package GameService.Sdk.Core@1.0.8
#addin nuget:?package=GameService.Sdk.Core&version=1.0.8
#tool nuget:?package=GameService.Sdk.Core&version=1.0.8
GameService SDK for Unity & .NET
This SDK provides a clean, strongly-typed client for connecting to the GameService backend. It is designed to be compatible with Unity 2021.3+ and standard .NET applications.
Compatibility
- Target Framework: .NET Standard 2.1
- Dependencies:
Microsoft.AspNetCore.SignalR.Clientprotobuf-netNewtonsoft.Json(Optional, internal use mostly)
Installation in Unity
- NuGet Packages: You need the DLLs for the dependencies. The easiest way is to use NuGetForUnity.
- Install Packages:
Microsoft.AspNetCore.SignalR.Clientprotobuf-netSystem.Text.Json(If not present in newer Unity versions)
- Copy SDK: Copy the source files from
GameService.Sdk.Core,GameService.Sdk.Auth, etc., into your UnityAssets/Scripts/Sdkfolder.
Usage
1. Authentication
// Initialize Auth Client
var auth = new AuthClient("http://localhost:5525");
// Login (Guest or Email)
var result = await auth.GuestLoginAsync();
if (result.Success) {
Debug.Log($"Logged in! Token: {result.Session.AccessToken}");
}
2. Connect to Game Hub
// Connect using the session from auth
var gameClient = await result.Session.ConnectToGameAsync();
// Listen for events
gameClient.OnPlayerJoined += async (player) => {
Debug.Log($"{player.UserName} joined seat {player.SeatIndex}");
};
3. Play a Game (e.g., Ludo)
// Create or Join
var ludo = await LudoClientFactory.CreateOnlineGameAsync(gameClient);
// Handle Game State
ludo.OnStateUpdated += (state) => {
Debug.Log($"Current Player: {state.CurrentPlayer}");
};
// Actions
if (ludo.IsMyTurn) {
await ludo.RollDiceAsync();
}
Architecture
- Transport: SignalR (WebSockets)
- Serialization: Protobuf (Binary) for game actions, JSON for metadata.
- Thread Safety: Use
WithSynchronizationContext(true)when building the client in Unity to ensure callbacks run on the main thread.
Get Started with Unity
The Core SDK handles SignalR connections and real-time communication.
Key Classes
GameClient: Main connection to GameService HubGameSession: Authentication session with token managementConnectionState: Connection status tracking
Basic Connection
using GameService.Sdk.Core;
public class GameManager : MonoBehaviour
{
private GameClient gameClient;
private async void Start()
{
// Connect with access token
gameClient = await GameClient.Create("https://your-server.com")
.WithAccessToken(accessToken)
.WithSynchronizationContext(true) // Unity main thread
.ConnectAsync();
// Listen for connection events
gameClient.OnConnectionStateChanged += OnConnectionChanged;
gameClient.OnLatencyUpdate += OnLatencyUpdate;
}
private async void OnConnectionChanged(ConnectionState state)
{
Debug.Log($"Connection: {state}");
}
private async void OnLatencyUpdate(int ms)
{
Debug.Log($"Latency: {ms}ms");
}
private async void OnDestroy()
{
if (gameClient != null)
await gameClient.DisposeAsync();
}
}
Room Management
// Create a new game room
var createResult = await gameClient.CreateRoomAsync("StandardLudo");
if (createResult.Success)
{
Debug.Log($"Room created: {createResult.RoomId}");
Debug.Log($"Short code: {createResult.ShortCode}");
}
// Join existing room
var joinResult = await gameClient.JoinRoomAsync("ABCDE"); // Short code or Room ID
if (joinResult.Success)
{
Debug.Log($"Joined as seat {joinResult.SeatIndex}");
}
// Create or join a room (matchmaking)
// Searches for existing rooms sorted by player count, joins if available, otherwise creates a new room
var matchResult = await gameClient.CreateOrJoinRoomAsync("StandardLudo");
if (matchResult.Success)
{
Debug.Log($"Joined as seat {matchResult.SeatIndex}");
}
// Leave room
await gameClient.LeaveRoomAsync();
Game Events
// Player events
gameClient.OnPlayerJoined += async (player) =>
{
Debug.Log($"{player.UserName} joined seat {player.SeatIndex}");
};
gameClient.OnPlayerLeft += async (player) =>
{
Debug.Log($"{player.UserName} left the game");
};
// Game state updates
gameClient.OnGameState += async (state) =>
{
Debug.Log($"Game state updated: {state.PlayerCount} players");
};
// Chat messages
gameClient.OnChatMessage += async (message) =>
{
Debug.Log($"{message.UserName}: {message.Message}");
};
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.AspNetCore.SignalR.Client (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection (>= 10.0.1)
- Microsoft.Extensions.Http (>= 10.0.1)
- Newtonsoft.Json (>= 13.0.4)
- protobuf-net (>= 3.2.56)
- System.Net.Http.Json (>= 10.0.1)
-
net8.0
- Microsoft.AspNetCore.SignalR.Client (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection (>= 10.0.1)
- Microsoft.Extensions.Http (>= 10.0.1)
- Newtonsoft.Json (>= 13.0.4)
- protobuf-net (>= 3.2.56)
- System.Net.Http.Json (>= 10.0.1)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on GameService.Sdk.Core:
| Package | Downloads |
|---|---|
|
GameService.Sdk.Ludo
Ludo game SDK for GameService - Type-safe Ludo game client with all game actions |
|
|
GameService.Sdk.Auth
Authentication SDK for GameService - Login, register, token management |
|
|
GameService.Sdk.LuckyMine
LuckyMine game SDK for GameService - Minesweeper-style betting game |
|
|
GameService.Sdk.LudoDoubles
DoubleDice relay game SDK for GameService - client-authoritative multiplayer game |
GitHub repositories
This package is not used by any popular GitHub repositories.