Interface IMultiplayerService
Facade for session browsing, session management and matchmaking.
Namespace: Unity.Services.Multiplayer
Syntax
public interface IMultiplayerService
Properties
Sessions
The list of active sessions
Declaration
IReadOnlyDictionary<string, ISession> Sessions { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyDictionary<System.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 |
---|---|---|
System.String | sessionId | The Session ID |
SessionOptions | sessionOptions | The options for the resulting session |
Returns
Type | Description |
---|---|
System.Threading.Tasks.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 |
---|---|
System.Threading.Tasks.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 |
---|---|
System.Threading.Tasks.Task<System.Collections.Generic.List<System.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 |
---|---|---|
System.String | sessionCode | The join code for the session |
JoinSessionOptions | sessionOptions | The options for the resulting session |
Returns
Type | Description |
---|---|
System.Threading.Tasks.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 |
---|---|---|
System.String | sessionId | The ID for the session |
JoinSessionOptions | sessionOptions | The options for the resulting session |
Returns
Type | Description |
---|---|
System.Threading.Tasks.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(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
MatchmakerOptions | matchOptions | The matchmaking queue options to join the Session |
SessionOptions | sessionOptions | The options for the resulting session |
System.Threading.CancellationToken | cancellationToken | Cancellation Token to cancel the request |
Returns
Type | Description |
---|---|
System.Threading.Tasks.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 |
---|---|
System.Threading.Tasks.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 |
---|---|
System.Threading.Tasks.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 |
---|---|---|
System.String | sessionId | The ID for the session. |
ReconnectSessionOptions | options | The reconnection options. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.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 |
---|---|
System.Action<ISession> |
SessionRemoved
Raised when an active session is removed from Sessions.
Declaration
event Action<ISession> SessionRemoved
Event Type
Type | Description |
---|---|
System.Action<ISession> |