Multiplayer API Logo

Multiplayer API

Unity SDK for
Multiplayer Games

Unity SDK

Unity SDK Download

View on GitHub
Repository

Unity API Documentation

GameSDK

Main SDK class for Unity multiplayer functionality

Constructor

public GameSDK(string apiToken, string apiPrivateToken, string baseUrl = "https://api.michitai.com/api", 
               ILogger logger = null, HttpClient httpClient = null, bool useUnityFormat = true)

Initializes the SDK with API tokens and optional Unity formatting.

Player Management

Methods for player registration, authentication, and lifecycle management

RegisterPlayer

public Task<PlayerRegisterResponse> RegisterPlayer<T>(string name, T playerData = null, CancellationToken ct = default)

Registers a new player with optional custom data. Uses generic type for player data with JsonUtility serialization.

AuthenticatePlayer

public Task<PlayerAuthResponse<T>> AuthenticatePlayer<T>(string playerToken, CancellationToken ct = default)

Authenticates a player using their private token. Returns player information with typed data support.

SendPlayerHeartbeatAsync

public Task<PlayerHeartbeatResponse> SendPlayerHeartbeatAsync(string playerToken, CancellationToken ct = default)

Sends a heartbeat to maintain the player's connection. Call every 30-60 seconds to prevent timeout.

LogoutPlayerAsync

public Task<PlayerLogoutResponse> LogoutPlayerAsync(string playerToken, CancellationToken ct = default)

Logs out the current player and invalidates their session. Updates last logout timestamp.

GetAllPlayers

public Task<PlayerListResponse> GetAllPlayers(CancellationToken ct = default)

Lists all registered players. Requires private API token. Useful for admin dashboards.

Game Data Management

Methods for managing global and player-specific game data

GetGameData

public Task<GameDataResponse<T>> GetGameData<T>(CancellationToken ct = default)

Retrieves global game data with generic type support. Data is automatically deserialized using JsonUtility.

UpdateGameData

public Task<SuccessResponse> UpdateGameData<T>(T data, CancellationToken ct = default)

Updates global game data. Requires private API token. Uses generic type for type safety.

GetPlayerData

public Task<PlayerDataResponse<T>> GetPlayerData<T>(string playerToken, CancellationToken ct = default)

Retrieves player-specific data with generic type support. Requires player authentication.

UpdatePlayerData

public Task<SuccessResponse> UpdatePlayerData<T>(string playerToken, T data, CancellationToken ct = default)

Updates player-specific data with generic type support. Requires player authentication.

Time Management

Methods for server time synchronization

GetServerTime

public Task<ServerTimeResponse> GetServerTime(CancellationToken ct = default)

Retrieves current server time in UTC and readable formats.

GetServerTimeWithOffset

public Task<ServerTimeWithOffsetResponse> GetServerTimeWithOffset(int utcOffset, CancellationToken ct = default)

Retrieves server time with specified UTC offset. Useful for time synchronization.

Room Management

Methods for creating and managing game rooms

CreateRoomAsync

public Task<RoomCreateResponse> CreateRoomAsync<T>(string playerToken, string roomName, string password = null, int maxPlayers = 4, T rules = null, CancellationToken ct = default)

Creates a new game room with optional password and rules. The creating player becomes the host.

GetRoomsAsync

public Task<RoomListResponse<T>> GetRoomsAsync<T>(CancellationToken ct = default)

Retrieves all available game rooms with typed rules support. Useful for server browser.

JoinRoomAsync

public Task<RoomJoinResponse> JoinRoomAsync(string playerToken, string roomId, string password = null, CancellationToken ct = default)

Joins an existing room. Password required for private rooms.

GetRoomPlayersAsync

public Task<RoomPlayersResponse> GetRoomPlayersAsync(string playerToken, CancellationToken ct = default)

Lists all players in the current room with heartbeat status.

LeaveRoomAsync

public Task<RoomLeaveResponse> LeaveRoomAsync(string playerToken, CancellationToken ct = default)

Leaves the current room and updates player status.

SendRoomHeartbeatAsync

public Task<HeartbeatResponse> SendRoomHeartbeatAsync(string playerToken, CancellationToken ct = default)

Sends heartbeat to maintain room connection. Call every 30-60 seconds while in room.

GetCurrentRoomAsync

public Task<CurrentRoomResponse> GetCurrentRoomAsync(string playerToken, CancellationToken ct = default)

Gets comprehensive room state including player lists and pending actions.

Room Actions

Methods for submitting and processing game actions

SubmitActionAsync

public Task<ActionSubmitResponse> SubmitActionAsync<T>(string playerToken, string actionType, T requestData = null, CancellationToken ct = default)

Submits an action for processing by other players. Uses generic type for request data.

PollActionsAsync

public Task<ActionPollResponse> PollActionsAsync(string playerToken, CancellationToken ct = default)

Polls for completed actions from other players. Call periodically to check for new actions.

GetPendingActionsAsync

public Task<ActionPendingResponse<T>> GetPendingActionsAsync<T>(string playerToken, CancellationToken ct = default)

Gets actions awaiting processing by the current player with typed request data.

CompleteActionAsync

public Task<ActionCompleteResponse> CompleteActionAsync<T>(string actionId, string playerToken, ActionComplete<T> request, CancellationToken ct = default)

Marks an action as completed with processing results using typed response data.

Room Updates

Methods for data synchronization between players

UpdatePlayersAsync

public Task<UpdatePlayersResponse> UpdatePlayersAsync<T>(string playerToken, UpdatePlayers<T> request, CancellationToken ct = default)

Sends updates to specific players or all players. Uses typed UpdatePlayers parameter.

PollUpdatesAsync

public Task<PollUpdatesResponse> PollUpdatesAsync(string playerToken, string lastUpdateId = null, CancellationToken ct = default)

Polls for updates sent by other players. Supports incremental polling with lastUpdateId.

Matchmaking

Methods for matchmaking lobby management and game start

GetMatchmakingLobbiesAsync

public Task<MatchmakingListResponse> GetMatchmakingLobbiesAsync(CancellationToken ct = default)

Lists all available matchmaking lobbies. Useful for lobby browser functionality.

CreateMatchmakingLobbyAsync

public Task<MatchmakingCreateResponse> CreateMatchmakingLobbyAsync<T>(string playerToken, int maxPlayers = 4, bool strictFull = false, bool joinByRequests = false, T rules = null, CancellationToken ct = default)

Creates a new matchmaking lobby with typed rules support. The creating player becomes the host.

RequestToJoinMatchmakingAsync

public Task<MatchmakingJoinRequestResponse> RequestToJoinMatchmakingAsync(string playerToken, string matchmakingId, CancellationToken ct = default)

Requests to join a lobby that requires host approval. Returns request ID for tracking.

RespondToJoinRequestAsync

public Task<MatchmakingPermissionResponse> RespondToJoinRequestAsync(string playerToken, string requestId, MatchmakingRequestAction action, CancellationToken ct = default)

Responds to a join request (approve/reject). Only the lobby host can call this.

CheckJoinRequestStatusAsync

public Task<MatchmakingRequestStatusResponse> CheckJoinRequestStatusAsync(string playerToken, string requestId, CancellationToken ct = default)

Checks the status of a join request. Useful for tracking approval/rejection status.

GetCurrentMatchmakingStatusAsync

public Task<MatchmakingCurrentResponse<T>> GetCurrentMatchmakingStatusAsync<T>(string playerToken, CancellationToken ct = default)

Gets comprehensive lobby state with typed rules including player status and pending requests.

JoinMatchmakingDirectlyAsync

public Task<MatchmakingDirectJoinResponse> JoinMatchmakingDirectlyAsync(string playerToken, string matchmakingId, CancellationToken ct = default)

Joins a matchmaking lobby directly. Only works if lobby allows direct join.

LeaveMatchmakingAsync

public Task<MatchmakingLeaveResponse> LeaveMatchmakingAsync(string playerToken, CancellationToken ct = default)

Leaves the current matchmaking lobby and updates player status.

GetMatchmakingPlayersAsync

public Task<MatchmakingPlayersResponse> GetMatchmakingPlayersAsync(string playerToken, CancellationToken ct = default)

Lists all players in the current matchmaking lobby. Useful for displaying player lists.

SendMatchmakingHeartbeatAsync

public Task<MatchmakingHeartbeatResponse> SendMatchmakingHeartbeatAsync(string playerToken, CancellationToken ct = default)

Sends heartbeat to maintain lobby connection. Call every 30-60 seconds while in lobby.

RemoveMatchmakingLobbyAsync

public Task<MatchmakingRemoveResponse> RemoveMatchmakingLobbyAsync(string playerToken, CancellationToken ct = default)

Removes the matchmaking lobby and kicks all players. Only the lobby host can call this.

StartGameFromMatchmakingAsync

public Task<MatchmakingStartResponse> StartGameFromMatchmakingAsync(string playerToken, CancellationToken ct = default)

Starts a game from matchmaking lobby. Transfers all players to a new game room.

Leaderboard

Methods for competitive rankings and player statistics

GetLeaderboardAsync

public Task<LeaderboardResponse<T>> GetLeaderboardAsync<T>(string[] sortBy, int limit = 10, CancellationToken ct = default)

Retrieves ranked players with configurable sorting criteria and typed player data support.