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 |
---|---|
IReadOnlyDictionary<string, ISession> |
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 |
SessionOptions | sessionOptions | The options for the resulting session |
Returns
Type | Description |
---|---|
Task<ISession> | The created or joined session. |
Exceptions
Type | Condition |
---|---|
SessionException | Provides a specific session error type and error message. |
CreateSessionAsync(SessionOptions)
Creates a Session.
Declaration
Task<IHostSession> CreateSessionAsync(SessionOptions sessionOptions)
Parameters
Type | Name | Description |
---|---|---|
SessionOptions | sessionOptions | The options for the resulting session |
Returns
Type | Description |
---|---|
Task<IHostSession> | The created session |
Exceptions
Type | Condition |
---|---|
SessionException | 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
Type | Description |
---|---|
Task<List<string>> | A list of sessions. |
Exceptions
Type | Condition |
---|---|
SessionException | 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 |
JoinSessionOptions | sessionOptions | The options for the resulting session |
Returns
Type | Description |
---|---|
Task<ISession> | The joined session. |
Exceptions
Type | Condition |
---|---|
SessionException | 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 |
JoinSessionOptions | sessionOptions | The options for the resulting session |
Returns
Type | Description |
---|---|
Task<ISession> | The joined session. |
Exceptions
Type | Condition |
---|---|
SessionException | 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 |
---|---|---|
MatchmakerOptions | matchOptions | The matchmaking queue options to join the Session |
SessionOptions | sessionOptions | The options for the resulting session |
CancellationToken | cancellationToken | Cancellation Token to cancel the request |
Returns
Type | Description |
---|---|
Task<ISession> | The created or joined session. |
Exceptions
Type | Condition |
---|---|
SessionException | 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 |
---|---|---|
QuickJoinOptions | quickJoinOptions | The quick join options used to find, join or create session |
SessionOptions | sessionOptions | The options for the resulting session |
Returns
Type | Description |
---|---|
Task<ISession> | The matchmade session. |
Exceptions
Type | Condition |
---|---|
SessionException | Provides a specific session error type and error message. |
QuerySessionsAsync(QuerySessionsOptions)
Query available sessions
Declaration
Task<QuerySessionsResults> QuerySessionsAsync(QuerySessionsOptions queryOptions)
Parameters
Type | Name | Description |
---|---|---|
QuerySessionsOptions | queryOptions | The query options for the search |
Returns
Type | Description |
---|---|
Task<QuerySessionsResults> | The result of the query with a list of sessions |
Exceptions
Type | Condition |
---|---|
SessionException | 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. |
ReconnectSessionOptions | options | The reconnection options. |
Returns
Type | Description |
---|---|
Task<ISession> | The reconnected session. |
Exceptions
Type | Condition |
---|---|
SessionException | 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
Type | Description |
---|---|
Action<ISession> |
SessionRemoved
Raised when an active session is removed from Sessions.
Declaration
event Action<ISession> SessionRemoved
Event Type
Type | Description |
---|---|
Action<ISession> |