Player manager
Overview
The manager rules over the player state and his synchronization with the server. After SDK initialization, there starts the process of player’s synchronization with the server. Upon completion, the ready
event will be called.
Player manager properties FREE:
- JavaScript
- Unity
// The player is logged in
gp.player.isLoggedIn
// The player uses one of the login methods (cookie, authorization, secret code)
gp.player.hasAnyCredentials
// Player waiting promise
gp.player.ready
// The player is logged in
GP_Player.IsLoggedIn();
// The player uses one of the login methods (cookie, authorization, secret code)
GP_Player.HasAnyCredentials();
The player is initialized automatically; you can wait for readiness:
- JavaScript
- Unity
await gp.player.ready;
// The player is ready
// The player is ready
gp.player.on('ready', () => {});
Initialization in Unity occurs before the game starts
Synchronization
+1 RequestAfter player model changes, they can be sent to the server and saved locally on the device. It is recommended to sync the player after completing a level and receiving rewards, as well as immediately after an important action, for example, purchasing an item.
- JavaScript
- Unity
// Synchronize, returns the promise
gp.player.sync();
// Overwrite the character on the server (local in priority)
gp.player.sync({ override: true });
// The player is synchronized (success === true)
gp.player.on('sync', (success) => {});
// Synchronize player
GP_Player.Sync();
// Overwrite the character on the server (local in priority)
GP_Player.Sync(true);
Storage limit: no more than 1 MB
per player.
Loading
+1 RequestYou can load the player by force from the server (by overwriting the local one).
- JavaScript
- Unity
// Load, returns the promise
gp.player.load();
// The player is loaded (success === true)
gp.player.on('load', (success) => {});
// Load player
GP_Player.Load();
Login
FREEShow the overlay with login options. This is currently the platform login (if it is supported) and login by secret code.
- JavaScript
- Unity
// Login, returns the promise
gp.player.login();
// The player is logged in (success === true)
gp.player.on('login', (success) => {});
// Open login overlay
GP_Player.Login();
Fetching the fields
+1 RequestSee below what player fields are.
You can fetch the player fields using the following method:
- JavaScript
- Unity
// Fetch fields list, returns the promise
gp.player.fetchFields();
// Fields are fetched (success === true)
gp.player.on('fetchFields', (success) => {});
// Fetch fields list
private Fetch() => GP_Player.FetchFields(OnFetchFields);
// Fields are fetched
private OnFetchFields(List<PlayerFetchFieldsData> data){
}
Notification of other windows
FREEIf the player opens another window with the game at the same time as the other open windows of the game - all other windows will receive event:connect
. You can subscribe to it like this:
- JavaScript
- Unity
// will be triggered when the player opens another window with the game
gp.on('event:connect', () => {})
//Subscribe to event
private void OnEnable()
{
GP_Player.OnConnect += OnConnect;
}
//Unsubscribe from event
private void OnDisable()
{
GP_Player.OnConnect -= OnConnect;
}
//On trigger event
private void OnConnect()
{
Debug.Log("Connect");
}
Stay in Touch
Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.
GamePush Community Telegram
: @gs_community.
For your suggestions e-mail
: [email protected]
We Wish you Success!