JsonUtility-compatible SDK designed specifically for Unity developers. Full serialization support, coroutines, and seamless integration with your Unity projects.
Built with Unity developers in mind
Full compatibility with Unity's JsonUtility serialization system. No reflection or complex JSON handling needed.
Uses Unity coroutines for async operations, perfect for game loops and frame-based updates.
Arrays instead of Lists, no reflection, and IL2CPP-compatible serialization for mobile builds.
Complete JsonUtility-compatible SDK for Unity developers
Complete JsonUtility-compatible SDK designed specifically for Unity developers. Includes comprehensive multiplayer functionality with coroutines, authentication, and proper serialization for mobile builds.
Full compatibility with Unity's JsonUtility serialization system
Uses Unity coroutines for async operations and game loops
Arrays instead of Lists, no reflection for mobile builds
Complete player management and matchmaking system
Real-time room management with actions and updates
Competitive rankings and player statistics
SDK.csTip: Create a "Scripts" folder to organize your files
Tip: Place this GameObject in your main scene for persistence
YOUR_API_TOKEN and YOUR_PRIVATE_API_TOKEN with actual tokensTip: Store API token in ScriptableObject for production
Compilation Errors:
Ensure .NET Framework compatibility in Player Settings
API Timeouts:
Check internet connection and API token validity
JsonUtility Issues:
Use [Serializable] classes and proper field names
Coroutine Problems:
Start coroutines from MonoBehaviour instances
Complete Unity-compatible API documentation for multiplayer games
Main SDK class for Unity multiplayer functionality
The MultiplayerSDK class provides complete multiplayer functionality for Unity games. It handles player management, matchmaking, game rooms, real-time actions, and leaderboards with full JsonUtility compatibility for Unity serialization.
Sets the API authentication token for all requests
Sets the player authentication token for player-specific operations
Serializes object to JSON using Unity's JsonUtility
Deserializes JSON to object using Unity's JsonUtility
Methods for player registration, authentication, and lifecycle management
void RegisterPlayer(string playerName, string playerDataJson, Action<RegisterPlayerResponse> callback)
Registers a new player account. The playerDataJson should contain initial player data as a JSON string for Unity compatibility.
void LoginPlayer(Action<LoginResponse> callback)
Authenticates the player using the currently set game player token. Returns complete player information.
void SendPlayerHeartbeat(Action<HeartbeatResponse> callback)
Sends a heartbeat to maintain the player's connection. Call every 30-60 seconds to prevent timeout.
void LogoutPlayer(Action<LogoutResponse> callback)
Logs out the current player and invalidates their session. Updates last logout timestamp.
void ListPlayers(Action<ListPlayersResponse> callback)
Lists all registered players. Useful for admin dashboards or player discovery systems.
Methods for managing global and player-specific game data
void GetGameData(Action<GameDataResponse> callback)
Retrieves global game data and settings. Data is returned as JSON string for Unity compatibility.
void UpdateGameData(string dataJson, Action<UpdateDataResponse> callback)
Updates global game data. The dataJson should contain the fields to update as JSON string.
void GetPlayerData(Action<PlayerDataResponse> callback)
Retrieves player-specific data. Requires player authentication token to be set.
void UpdatePlayerData(string dataJson, Action<UpdateDataResponse> callback)
Updates player-specific data. The dataJson should contain fields to update as JSON string.
Methods for server time synchronization
void GetServerTime(Action<TimeResponse> callback, int utcOffset = 0)
Retrieves server time with optional UTC offset. Useful for time synchronization and anti-cheat measures.
Methods for creating and managing game rooms
void CreateRoom(string roomName, string password, int maxPlayers, Action<CreateRoomResponse> callback)
Creates a new game room. The creating player becomes the room host.
void ListRooms(Action<ListRoomsResponse> callback)
Retrieves all available game rooms. Useful for server browser functionality.
void JoinRoom(string roomId, string password, Action<JoinRoomResponse> callback)
Joins an existing room. Password required for private rooms.
void ListRoomPlayers(Action<ListRoomPlayersResponse> callback)
Lists all players in the current room. Useful for displaying player lists and checking occupancy.
void LeaveRoom(Action<BaseResponse> callback)
Leaves the current room and updates player status.
void SendRoomHeartbeat(Action<BaseResponse> callback)
Sends heartbeat to maintain room connection. Call every 30-60 seconds while in room.
void GetCurrentRoomStatus(Action<CurrentRoomStatusResponse> callback)
Gets comprehensive room state including player lists and pending actions.
Methods for submitting and processing game actions
void SubmitAction(string actionType, string requestDataJson, Action<SubmitActionResponse> callback)
Submits an action for processing by other players. Actions are processed asynchronously.
void PollActions(Action<PollActionsResponse> callback)
Polls for completed actions from other players. Call periodically to check for new actions.
void GetPendingActions(Action<GetPendingActionsResponse> callback)
Gets actions awaiting processing by the current player. Call to find actions to complete.
void CompleteAction(string actionId, string status, string responseDataJson, Action<CompleteActionResponse> callback)
Marks an action as completed with processing results. Used after processing pending actions.
Methods for real-time data synchronization between players
void SendUpdate(string targetPlayerIds, string type, string dataJson, Action<SendUpdateResponse> callback)
Sends real-time updates to specific players or all players. Target can be "all" or JSON array of IDs.
void PollUpdates(string lastUpdateId, Action<PollUpdatesResponse> callback)
Polls for updates sent by other players. Supports incremental polling with lastUpdateId.
Methods for matchmaking lobby management and game start
void ListMatchmaking(Action<ListMatchmakingResponse> callback)
Lists all available matchmaking lobbies. Useful for lobby browser functionality.
void CreateMatchmaking(int maxPlayers, bool strictFull, bool joinByRequests, string extraJsonString, Action<CreateMatchmakingResponse> callback)
Creates a new matchmaking lobby. The creating player becomes the lobby host.
void RequestJoinMatchmaking(string matchmakingId, Action<JoinRequestResponse> callback)
Requests to join a lobby that requires host approval. Returns request ID for tracking.
void JoinMatchmaking(string matchmakingId, Action<JoinMatchmakingResponse> callback)
Joins a matchmaking lobby directly. Only works if lobby allows direct join.
void LeaveMatchmaking(Action<LeaveMatchmakingResponse> callback)
Leaves the current matchmaking lobby and updates player status.
void GetMatchmakingPlayers(Action<GetMatchmakingPlayersResponse> callback)
Lists all players in the current matchmaking lobby. Useful for displaying player lists.
void SendMatchmakingHeartbeat(Action<BaseResponse> callback)
Sends heartbeat to maintain lobby connection. Call every 30-60 seconds while in lobby.
void RemoveMatchmaking(Action<BaseResponse> callback)
Removes the matchmaking lobby and kicks all players. Only the lobby host can call this.
void StartMatchmaking(Action<StartMatchmakingResponse> callback)
Starts a game from matchmaking lobby. Transfers all players to a new game room.
void GetCurrentMatchmakingStatus(Action<CurrentMatchmakingStatusResponse> callback)
Gets comprehensive lobby state including player status and pending requests.
void CheckRequestStatus(string requestId, Action<CheckRequestStatusResponse> callback)
Checks the status of a join request. Useful for tracking approval/rejection status.
void RespondToRequest(string requestId, string action, Action<RespondToRequestResponse> callback)
Responds to a join request (approve/reject). Only the lobby host can call this.
Methods for competitive rankings and player statistics
void GetLeaderboard(string[] sortBy, int limit, Action<LeaderboardResponse> callback)
Retrieves ranked players with configurable sorting criteria. Supports multiple sort fields.
Internal HTTP request handling methods
private void SendRequest<T>(string url, string method, string bodyJson, Action<T> callback)
Internal method for sending HTTP requests with authentication and error handling.
private IEnumerator SendRequestCoroutine<T>(string url, string method, string bodyJson, Action<T> callback)
Internal coroutine for async HTTP requests with comprehensive error handling.
Helper methods for JSON serialization and token management
public void SetApiToken(string token)
Sets the API authentication token. Required for all API calls.
public void SetGamePlayerToken(string token)
Sets the player authentication token. Required for player-specific operations.
public string SerializeToJson<T>(T obj)
Serializes object to JSON using Unity's JsonUtility. Ensures Unity compatibility.
public T DeserializeFromJson<T>(string json)
Deserializes JSON to object using Unity's JsonUtility. For parsing API responses.
Data classes for API responses with JsonUtility compatibility
Base class for all API responses with success/error fields
Response from player registration with player credentials
Response from player login with complete player info
Response from room creation with room details
Response from matchmaking lobby creation
Response from leaderboard with ranked players
Response from server time with timezone information
Response from game data retrieval
Response from player data retrieval
Response from data update operations