Interface IMultiplayerService
Facade for session browsing, session management and matchmaking.
Namespace: Unity.Services.Multiplayer
Assembly: Unity.Services.Multiplayer.dll
Syntax
public interface IMultiplayerService
Properties
Sessions
The list of active sessions
Declaration
IReadOnlyDictionary<string, ISession> Sessions { get; }
Property Value
Type | Description |
---|---|
IRead |
Methods
CreateOrJoinSessionAsync(string, SessionOptions)
Tries to join a Session, creates it if no Session associated to the provided ID exists.
Declaration
Task<ISession> CreateOrJoinSessionAsync(string sessionId, SessionOptions sessionOptions)
Parameters
Type | Name | Description |
---|---|---|
string | sessionId | The Session ID |
Session |
sessionOptions | The options for the resulting session |
Returns
Exceptions
Type | Condition |
---|---|
Session |
Provides a specific session error type and error message. |
CreateSessionAsync(SessionOptions)
Creates a Session.
Declaration
Task<IHostSession> CreateSessionAsync(SessionOptions sessionOptions)
Parameters
Type | Name | Description |
---|---|---|
Session |
sessionOptions | The options for the resulting session |
Returns
Type | Description |
---|---|
Task<IHost |
The created session |
Exceptions
Type | Condition |
---|---|
Session |
Provides a specific session error type and error message. |
GetJoinedSessionIdsAsync()
Get a list of session IDs that the current player is part of.
Declaration
Task<List<string>> GetJoinedSessionIdsAsync()
Returns
Exceptions
Type | Condition |
---|---|
Session |
Provides a specific session error type and error message. |
JoinSessionByCodeAsync(string, JoinSessionOptions)
Joins a Session through a join code.
Declaration
Task<ISession> JoinSessionByCodeAsync(string sessionCode, JoinSessionOptions sessionOptions = null)
Parameters
Type | Name | Description |
---|---|---|
string | sessionCode | The join code for the session |
Join |
sessionOptions | The options for the resulting session |
Returns
Exceptions
Type | Condition |
---|---|
Session |
Provides a specific session error type and error message. |
JoinSessionByIdAsync(string, JoinSessionOptions)
Joins a Session by the session ID.
Declaration
Task<ISession> JoinSessionByIdAsync(string sessionId, JoinSessionOptions sessionOptions = null)
Parameters
Type | Name | Description |
---|---|---|
string | sessionId | The ID for the session |
Join |
sessionOptions | The options for the resulting session |
Returns
Exceptions
Type | Condition |
---|---|
Session |
Provides a specific session error type and error message. |
MatchmakeSessionAsync(MatchmakerOptions, SessionOptions, CancellationToken)
Find and join a Session with Unity matchmaker.
Declaration
Task<ISession> MatchmakeSessionAsync(MatchmakerOptions matchOptions, SessionOptions sessionOptions, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
Matchmaker |
matchOptions | The matchmaking queue options to join the Session |
Session |
sessionOptions | The options for the resulting session |
Cancellation |
cancellationToken | Cancellation Token to cancel the request |
Returns
Exceptions
Type | Condition |
---|---|
Session |
Provides a specific session error type and error message. |
MatchmakeSessionAsync(QuickJoinOptions, SessionOptions)
Find and join a Session using session filters. This operation will be retried at an interval up to a timeout specified in the options. Optionally creates a session if none is found after a timeout.
Declaration
Task<ISession> MatchmakeSessionAsync(QuickJoinOptions quickJoinOptions, SessionOptions sessionOptions)
Parameters
Type | Name | Description |
---|---|---|
Quick |
quickJoinOptions | The quick join options used to find, join or create session |
Session |
sessionOptions | The options for the resulting session |
Returns
Exceptions
Type | Condition |
---|---|
Session |
Provides a specific session error type and error message. |
QuerySessionsAsync(QuerySessionsOptions)
Query available sessions
Declaration
Task<QuerySessionsResults> QuerySessionsAsync(QuerySessionsOptions queryOptions)
Parameters
Type | Name | Description |
---|---|---|
Query |
queryOptions | The query options for the search |
Returns
Type | Description |
---|---|
Task<Query |
The result of the query with a list of sessions |
Exceptions
Type | Condition |
---|---|
Session |
Provides a specific session error type and error message. |
ReconnectToSessionAsync(string, ReconnectSessionOptions)
Attempts to reconnect to an existing already joined session following a disconnect.
Declaration
Task<ISession> ReconnectToSessionAsync(string sessionId, ReconnectSessionOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
string | sessionId | The ID for the session. |
Reconnect |
options | The reconnection options. |
Returns
Exceptions
Type | Condition |
---|---|
Session |
Provides a specific session error type and error message. |
Events
SessionAdded
Raised when a new session is added to Sessions.
Declaration
event Action<ISession> SessionAdded
Event Type
SessionRemoved
Raised when an active session is removed from Sessions.
Declaration
event Action<ISession> SessionRemoved