v1.0.0
Latest
2022.3+

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
TypeDescription
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
TypeNameDescription
System.StringsessionId

The Session ID

SessionOptionssessionOptions

The options for the resulting session

Returns
TypeDescription
System.Threading.Tasks.Task<ISession>

The created or joined session.

Exceptions
TypeCondition
SessionException

Provides a specific session error type and error message.

CreateSessionAsync(SessionOptions)

Creates a Session.

Declaration
Task<IHostSession> CreateSessionAsync(SessionOptions sessionOptions)
Parameters
TypeNameDescription
SessionOptionssessionOptions

The options for the resulting session

Returns
TypeDescription
System.Threading.Tasks.Task<IHostSession>

The created session

Exceptions
TypeCondition
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
TypeDescription
System.Threading.Tasks.Task<System.Collections.Generic.List<System.String>>

A list of sessions.

Exceptions
TypeCondition
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
TypeNameDescription
System.StringsessionCode

The join code for the session

JoinSessionOptionssessionOptions

The options for the resulting session

Returns
TypeDescription
System.Threading.Tasks.Task<ISession>

The joined session.

Exceptions
TypeCondition
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
TypeNameDescription
System.StringsessionId

The ID for the session

JoinSessionOptionssessionOptions

The options for the resulting session

Returns
TypeDescription
System.Threading.Tasks.Task<ISession>

The joined session.

Exceptions
TypeCondition
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
TypeNameDescription
MatchmakerOptionsmatchOptions

The matchmaking queue options to join the Session

SessionOptionssessionOptions

The options for the resulting session

System.Threading.CancellationTokencancellationToken

Cancellation Token to cancel the request

Returns
TypeDescription
System.Threading.Tasks.Task<ISession>

The created or joined session.

Exceptions
TypeCondition
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
TypeNameDescription
QuickJoinOptionsquickJoinOptions

The quick join options used to find, join or create session

SessionOptionssessionOptions

The options for the resulting session

Returns
TypeDescription
System.Threading.Tasks.Task<ISession>

The matchmade session.

Exceptions
TypeCondition
SessionException

Provides a specific session error type and error message.

QuerySessionsAsync(QuerySessionsOptions)

Query available sessions

Declaration
Task<QuerySessionsResults> QuerySessionsAsync(QuerySessionsOptions queryOptions)
Parameters
TypeNameDescription
QuerySessionsOptionsqueryOptions

The query options for the search

Returns
TypeDescription
System.Threading.Tasks.Task<QuerySessionsResults>

The result of the query with a list of sessions

Exceptions
TypeCondition
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
TypeNameDescription
System.StringsessionId

The ID for the session.

ReconnectSessionOptionsoptions

The reconnection options.

Returns
TypeDescription
System.Threading.Tasks.Task<ISession>

The reconnected session.

Exceptions
TypeCondition
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
TypeDescription
System.Action<ISession>

SessionRemoved

Raised when an active session is removed from Sessions.

Declaration
event Action<ISession> SessionRemoved
Event Type
TypeDescription
System.Action<ISession>