Class Context
Contains functions and properties related to the current game context.
Inherited Members
Namespace: Meta.InstantGames.v8
Assembly: Unity.Meta.InstantGames.Sdk.v8.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 change into that context, and resolve if successful. Otherwise, if the player exits the menu or the client fails to change 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 changed 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 or change into a context between the current player and a specified player. The input must be an array containing a single playerID. The returned WebTask will reject if the player listed is not a Connected Player 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 changed 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 one-element array containing a suggested playerID |
Returns
Type | Description |
---|---|
WebTask | A WebTask that resolves when the game has changed into the new context, or rejects otherwise. |
GetID()
A unique identifier for the current game context. This represents a specific context that the game is being played in (for example, a Facebook post). The identifier will be null if game is being played in a solo context. This function should not be called until FBInstant.startGameAsync has resolved.
Declaration
public string GetID()
Returns
Type | Description |
---|---|
string | A unique identifier for the current game context. |
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 change 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 changed 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 change into a solo context. |
bool | switchSilentlyIfSolo | If changing into a solo context, set this to true to change silently, with no confirmation dialog or toast. This only has an effect when changing into a solo context. |
Returns
Type | Description |
---|---|
WebTask | A WebTask that resolves when the game has changed into the specified context, or rejects otherwise. |