Main SDK class for Unity multiplayer functionality
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.
Methods for player registration, authentication, and lifecycle management
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.
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.
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.
public Task<PlayerLogoutResponse> LogoutPlayerAsync(string playerToken, CancellationToken ct = default)
Logs out the current player and invalidates their session. Updates last logout timestamp.
public Task<PlayerListResponse> GetAllPlayers(CancellationToken ct = default)
Lists all registered players. Requires private API token. Useful for admin dashboards.
Methods for managing global and player-specific game data
public Task<GameDataResponse<T>> GetGameData<T>(CancellationToken ct = default)
Retrieves global game data with generic type support. Data is automatically deserialized using JsonUtility.
public Task<SuccessResponse> UpdateGameData<T>(T data, CancellationToken ct = default)
Updates global game data. Requires private API token. Uses generic type for type safety.
public Task<PlayerDataResponse<T>> GetPlayerData<T>(string playerToken, CancellationToken ct = default)
Retrieves player-specific data with generic type support. Requires player authentication.
public Task<SuccessResponse> UpdatePlayerData<T>(string playerToken, T data, CancellationToken ct = default)
Updates player-specific data with generic type support. Requires player authentication.
Methods for server time synchronization
public Task<ServerTimeResponse> GetServerTime(CancellationToken ct = default)
Retrieves current server time in UTC and readable formats.
public Task<ServerTimeWithOffsetResponse> GetServerTimeWithOffset(int utcOffset, CancellationToken ct = default)
Retrieves server time with specified UTC offset. Useful for time synchronization.
Methods for creating and managing game rooms
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.
public Task<RoomListResponse<T>> GetRoomsAsync<T>(CancellationToken ct = default)
Retrieves all available game rooms with typed rules support. Useful for server browser.
public Task<RoomJoinResponse> JoinRoomAsync(string playerToken, string roomId, string password = null, CancellationToken ct = default)
Joins an existing room. Password required for private rooms.
public Task<RoomPlayersResponse> GetRoomPlayersAsync(string playerToken, CancellationToken ct = default)
Lists all players in the current room with heartbeat status.
public Task<RoomLeaveResponse> LeaveRoomAsync(string playerToken, CancellationToken ct = default)
Leaves the current room and updates player status.
public Task<HeartbeatResponse> SendRoomHeartbeatAsync(string playerToken, CancellationToken ct = default)
Sends heartbeat to maintain room connection. Call every 30-60 seconds while in room.
public Task<CurrentRoomResponse> GetCurrentRoomAsync(string playerToken, CancellationToken ct = default)
Gets comprehensive room state including player lists and pending actions.
Methods for submitting and processing game actions
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.
public Task<ActionPollResponse> PollActionsAsync(string playerToken, CancellationToken ct = default)
Polls for completed actions from other players. Call periodically to check for new actions.
public Task<ActionPendingResponse<T>> GetPendingActionsAsync<T>(string playerToken, CancellationToken ct = default)
Gets actions awaiting processing by the current player with typed request data.
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.
Methods for data synchronization between players
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.
public Task<PollUpdatesResponse> PollUpdatesAsync(string playerToken, string lastUpdateId = null, CancellationToken ct = default)
Polls for updates sent by other players. Supports incremental polling with lastUpdateId.
Methods for matchmaking lobby management and game start
public Task<MatchmakingListResponse> GetMatchmakingLobbiesAsync(CancellationToken ct = default)
Lists all available matchmaking lobbies. Useful for lobby browser functionality.
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.
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.
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.
public Task<MatchmakingRequestStatusResponse> CheckJoinRequestStatusAsync(string playerToken, string requestId, CancellationToken ct = default)
Checks the status of a join request. Useful for tracking approval/rejection status.
public Task<MatchmakingCurrentResponse<T>> GetCurrentMatchmakingStatusAsync<T>(string playerToken, CancellationToken ct = default)
Gets comprehensive lobby state with typed rules including player status and pending requests.
public Task<MatchmakingDirectJoinResponse> JoinMatchmakingDirectlyAsync(string playerToken, string matchmakingId, CancellationToken ct = default)
Joins a matchmaking lobby directly. Only works if lobby allows direct join.
public Task<MatchmakingLeaveResponse> LeaveMatchmakingAsync(string playerToken, CancellationToken ct = default)
Leaves the current matchmaking lobby and updates player status.
public Task<MatchmakingPlayersResponse> GetMatchmakingPlayersAsync(string playerToken, CancellationToken ct = default)
Lists all players in the current matchmaking lobby. Useful for displaying player lists.
public Task<MatchmakingHeartbeatResponse> SendMatchmakingHeartbeatAsync(string playerToken, CancellationToken ct = default)
Sends heartbeat to maintain lobby connection. Call every 30-60 seconds while in lobby.
public Task<MatchmakingRemoveResponse> RemoveMatchmakingLobbyAsync(string playerToken, CancellationToken ct = default)
Removes the matchmaking lobby and kicks all players. Only the lobby host can call this.
public Task<MatchmakingStartResponse> StartGameFromMatchmakingAsync(string playerToken, CancellationToken ct = default)
Starts a game from matchmaking lobby. Transfers all players to a new game room.
Methods for competitive rankings and player statistics
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.