Beamable SDK
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Properties | Events | List of all members
Beamable.BeamContext Class Reference

More...

Inheritance diagram for Beamable.BeamContext:
Inheritance graph
[legend]
Collaboration diagram for Beamable.BeamContext:
Collaboration graph
[legend]

Public Member Functions

async Promise< BeamContextChangeAuthorizedPlayer (TokenResponse token)
 A BeamContext is configured for one authorized user. If you wish to change the user, you need to give it a new token. You can get TokenResponse values from the IAuthService by calling various log in methods. More...
 
IObservedPlayer ObservePlayer (long otherPlayerId)
 Using the authorization associated with the current context, observe the public data of another player More...
 
BeamContext Start ()
 After a context has been Stopped with the Stop method, this method can restart the instance. More...
 
async Promise Stop ()
 This method will tear down a BeamContext and notify all internal services that the context should be destroyed. All coroutines associated with the context will stop. No notifications will be received internal to the context. No services will be accessible from the ServiceProvider after Stop has been called. More...
 
async Promise ClearPlayerAndStop ()
 Clear the authorization token for the PlayerCode, then internally calls Stop
 
void ChangeTime ()
 
Promise OnDispose ()
 Used as a way to allow services attached to a IDependencyProvider to clean up their state when the IDependencyProviderScope.Dispose method is called More...
 

Static Public Member Functions

static BeamContext Instantiate (BeamableBehaviour beamable=null, string playerCode=null, IDependencyBuilder dependencyBuilder=null)
 Create or retrieve a BeamContext for the given PlayerCode. There is only one instance of a context per PlayerCode. A BeamableBehaviour is required because the context needs to attach specific Unity components to a GameObject, and the given BeamableBehaviour's GameObject will be used. If no BeamableBehaviour is given, then a new GameObject will be instantiated at the root transform level named, "Beamable (playerCode)" More...
 
static BeamContext InParent (Component c)
 Find the first BeamableBehaviour.Context in the parent lineage of the current component, or BeamContext.Default if no BeamableBehaviour components exist
 
static BeamContext ForPlayer (string playerCode="")
 Finds or creates the first BeamContext that matches the given BeamContext.PlayerCode value
 

Public Attributes

ObservableUser AuthorizedUser = new ObservableUser()
 The User that this context is authenticated with. Any web-calls that are made from this BeamContext are made by this User
 

Protected Member Functions

void Init (string cid, string pid, string playerCode, BeamableBehaviour behaviour, IDependencyBuilder builder)
 
virtual void RegisterServices (IDependencyBuilder builder)
 
virtual void InitServices (string cid, string pid)
 

Properties

string PlayerCode [get]
 The PlayerCode is the name of a player's slot on the device. The Default context uses an empty string, but you could use values like "player1" and "player2" to enable a feature like couch-coop.
 
IDependencyProvider ServiceProvider [get]
 The IDependencyProvider is a collection of all services required to provide a Beamable SDK full funcitonality
 
bool IsStopped [get]
 If the Stop method has been run, this property will return true. Once a context is disposed, you shouldn't use it anymore, and the ServiceProvider will throw exceptions if you do. You can re-initialize the context by using InParent
 
GameObject GameObject [get]
 Each BeamContext has a set of components that need to live on a gameObject in the scene.
 
bool IsInitialized [get]
 
bool IsDefault [get]
 
long???? PlayerId [get]
 
string Cid [get]
 
string Pid [get]
 
AccessToken AccessToken [get]
 
IBeamableRequester Requester [get]
 
CoroutineService CoroutineService [get]
 
PlayerAnnouncements Announcements [get]
 
PlayerStats Stats [get]
 
PlayerLobby Lobby [get]
 Access the PlayerLobby for this context.
 
PlayerInventory Inventory [get]
 
IContentApi Content [get]
 Access the IContentApi for this player.
 
ApiServices Api [get]
 Access the IBeamableAPI for this player.
 
string?? TimeOverride [getset]
 
static BeamContext Default [get]
 A static BeamContext that uses a PlayerCode of an empty string. By default, the default context will persist between scene reloads. If you need to dispose it, you'll need to manually invoke Stop
 
static IEnumerable< BeamContextAll [get]
 Finds all BeamContexts that have been created. This may include disposed contexts.
 
Promise< UnitOnReady [get]
 
- Properties inherited from Beamable.Api.IPlatformService
User User [get]
 The User for this player instance.
 
Promise< UnitOnReady [get]
 A Promise that completes once the user has initialized for this player instance.
 
INotificationService Notification [get]
 Access to the INotificationService for this player instance.
 
IPubnubNotificationService PubnubNotificationService [get]
 Access to the IPubnubNotificationService for this player instance.
 
IHeartbeatService Heartbeat [get]
 Access to the IHeartbeatService for this player instance.
 
string Cid [get]
 The current Customer ID for this player instance.
 
string Pid [get]
 The current Realm ID for this player instance.
 
string TimeOverride [getset]
 A time override that can be used to fake the current Beamable known time. This can be useful to checking Listing or Announcement times.
 
IConnectivityService ConnectivityService [get]
 Access to the IConnectivityService for this player instance.
 
CoroutineService CoroutineService [get]
 Access to the CoroutineService for this player instance.
 
- Properties inherited from Beamable.Common.Api.IUserContext
long UserId [get]
 The current gamertag of this context
 
- Properties inherited from Beamable.IGameObjectContext
GameObject GameObject [get]
 
- Properties inherited from Beamable.IObservedPlayer
PlayerStats Stats [get]
 
PlayerLobby Lobby [get]
 

Events

Action OnShutdown
 
Action OnShutdownComplete
 
Action OnReloadUser
 
Action TimeOverrideChanged
 
Action< UserOnUserLoggingOut
 
Action< UserOnUserLoggedIn
 
- Events inherited from Beamable.Api.IPlatformService
Action OnShutdown
 An event that will trigger when the player instance is shut down
 
Action OnReloadUser
 An event that will trigger when the player instance changes
 
Action TimeOverrideChanged
 An event that will trigger when a time override has been applied on the TimeOverride property.
 

Detailed Description

The BeamContext represents a player's session and is equipped with all required services. BeamContext instances are not tied to scene memory. Instead, BeamContext instances live in a static way. However, if a BeamableBehaviour is connected to a BeamContext, then the BeamableBehaviour's lifecycle will control the `BeamContext's lifecycle. Additionally, the PlayerCode variable is the unique id of the BeamContext.

From Monobehaviours or Unity components, you should use the InParent method to access a BeamContext. The InParent will give you the closest context in the Unity object heirarchy from your script's location, or give you Default if no context exists. You can add BeamableBehaviour components to add a context to a GameObject.

If you want to access an instance without using a context sensitive approach, you should use the Instantiate method. Finally, you can always use Default.

Remember, there will only ever be one instance of BeamContext per PlayerCode value. The Default context has a PlayerCode value of an empty string.

Member Function Documentation

◆ ChangeAuthorizedPlayer()

async Promise< BeamContext > Beamable.BeamContext.ChangeAuthorizedPlayer ( TokenResponse  token)
inline

A BeamContext is configured for one authorized user. If you wish to change the user, you need to give it a new token. You can get TokenResponse values from the IAuthService by calling various log in methods.

This method will mutate the current BeamContext instance itself, and returned the mutated object.

Parameters
token
Returns
The same instance, but now mutated for the new authorized user

◆ Instantiate()

static BeamContext Beamable.BeamContext.Instantiate ( BeamableBehaviour  beamable = null,
string  playerCode = null,
IDependencyBuilder  dependencyBuilder = null 
)
inlinestatic

Create or retrieve a BeamContext for the given PlayerCode. There is only one instance of a context per PlayerCode. A BeamableBehaviour is required because the context needs to attach specific Unity components to a GameObject, and the given BeamableBehaviour's GameObject will be used. If no BeamableBehaviour is given, then a new GameObject will be instantiated at the root transform level named, "Beamable (playerCode)"

Parameters
beamableA component that will invite other Beamable components to exist on its GameObject
playerCodeA named code that represents a player slot on the device. The Default context uses an empty string.
Returns

◆ ObservePlayer()

IObservedPlayer Beamable.BeamContext.ObservePlayer ( long  otherPlayerId)
inline

Using the authorization associated with the current context, observe the public data of another player

Parameters
otherPlayerId

◆ OnDispose()

Promise Beamable.BeamContext.OnDispose ( )
inline

Used as a way to allow services attached to a IDependencyProvider to clean up their state when the IDependencyProviderScope.Dispose method is called

Returns
A promise that represents when the service's clean up is complete. This promise will hang the entire disposal process of the IDependencyProviderScope

Implements Beamable.Common.Dependencies.IBeamableDisposable.

◆ Start()

BeamContext Beamable.BeamContext.Start ( )

After a context has been Stopped with the Stop method, this method can restart the instance.

If the context hasn't been stopped, this method won't do anything meaningful.

Returns
The same context instance

◆ Stop()

async Promise Beamable.BeamContext.Stop ( )
inline

This method will tear down a BeamContext and notify all internal services that the context should be destroyed. All coroutines associated with the context will stop. No notifications will be received internal to the context. No services will be accessible from the ServiceProvider after Stop has been called.

After a context has been disposed, if a call is made to Start or Instantiate with the disposed context's PlayerCode, then the disposed instance will be reinitialized and rehydrated and returned to the Instantiate's callsite.

Property Documentation

◆ Inventory

PlayerInventory Beamable.BeamContext.Inventory
get

Access the player's inventory


The documentation for this class was generated from the following file: