Class Context
Contains functions and properties related to the current game context.
Inherited Members
Namespace: Meta.InstantGames
Assembly: Unity.Meta.InstantGames.Sdk.dll
Syntax
public class Context : JsObject
Constructors
Context()
Construct an instance of Context
Declaration
public Context()
Methods
ChooseAsync(ContextOptions)
Opens a context selection dialog for the player. If the player selects an available context, the client will attempt to switch into that context, and resolve if successful. Otherwise, if the player exits the menu or the client fails to switch into the new context, this function will reject. Exceptions: INVALID_PARAM, SAME_CONTEXT, NETWORK_FAILURE, USER_INPUT, PENDING_REQUEST, CLIENT_UNSUPPORTED_OPERATION
Declaration
public WebTask ChooseAsync(ContextOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
ContextOptions | options | An object specifying conditions on the contexts that should be offered. |
Returns
Type | Description |
---|---|
WebTask | A WebTask that resolves when the game has switched into the context chosen by the user. Otherwise, the promise will reject (if the user cancels out of the dialog, for example). |
CreateAsync(string[])
Attempts to create a context between the current player and a specified player or a list of players. This API supports 3 use cases:1) When the input is a single playerID, it attempts to create or switch into a context between a specified player and the current player 2) When the input is a list of connected playerIDs, it attempts to create a context containing all the players 3) When there's no input, a friend picker will be loaded to ask the player to create a context with friends to play with For each of these cases, the returned WebTask will reject if any of the players listed are not Connected Players of the current player, or if the player denies the request to enter the new context. Otherwise, the WebTask will resolve when the game has switched into the new context. Exceptions: INVALID_PARAM, SAME_CONTEXT, NETWORK_FAILURE, USER_INPUT, PENDING_REQUEST, CLIENT_UNSUPPORTED_OPERATION
Declaration
public WebTask CreateAsync(string[] suggestedPlayerIds = null)
Parameters
Type | Name | Description |
---|---|---|
string[] | suggestedPlayerIds | A list of game suggested playerIDs or a single suggested playerID or no input |
Returns
Type | Description |
---|---|
WebTask | A WebTask that resolves when the game has switched into the new context, or rejects otherwise. |
GetPlayersAsync()
Gets an array of ContextPlayer objects containing information about active players in the current context (people who played the game in the current context in the last 90 days). This may include the current player. Exceptions: NETWORK_FAILURE, CLIENT_UNSUPPORTED_OPERATION, INVALID_OPERATION
Declaration
public WebTask<ContextPlayer[]> GetPlayersAsync()
Returns
Type | Description |
---|---|
WebTask<ContextPlayer[]> | A WebTask<T> containing an array of ContextPlayer. |
SwitchAsync(string, bool)
Request a switch into a specific context. If the player does not have permission to enter that context, or if the player does not provide permission for the game to enter that context, this will reject. Otherwise, the promise will resolve when the game has switched into the specified context. Exceptions: INVALID_PARAM, SAME_CONTEXT, NETWORK_FAILURE, USER_INPUT, PENDING_REQUEST, CLIENT_UNSUPPORTED_OPERATION
Declaration
public WebTask SwitchAsync(string id, bool switchSilentlyIfSolo = false)
Parameters
Type | Name | Description |
---|---|---|
string | id | ID of the desired context or the string SOLO to switch into a solo context. |
bool | switchSilentlyIfSolo | If switching into a solo context, set this to true to switch silently, with no confirmation dialog or toast. This only has an effect when switching into a solo context. |
Returns
Type | Description |
---|---|
WebTask | A WebTask that resolves when the game has switched into the specified context, or rejects otherwise. |