Player manager
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.
Overview
Player manager properties FREE:
- JavaScript
- Unity
// The player is logged in
ss.player.isLoggedIn;
// The player uses one of the login methods (authorization, secret code)
ss.player.hasAnyCredentials;
// Player waiting promise
ss.player.ready;
// The player is logged in
SS_Player.IsLoggedIn();
// The player uses one of the login methods (cookie, authorization, secret code)
SS_Player.HasAnyCredentials();
The player is initialized automatically; you can wait for readiness:
- JavaScript
- Unity
await ss.player.ready;
// The player is ready
// The player is ready
ss.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
ss.player.sync();
// Overwrite the character on the server (local in priority)
ss.player.sync({ override: true });
// The player is synchronized (success === true)
ss.player.on('sync', (success) => {});
// Synchronize player
SS_Player.Sync();
// Overwrite the character on the server (local in priority)
SS_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
ss.player.load();
// The player is loaded (success === true)
ss.player.on('load', (success) => {});
// Load player
SS_Player.Load();
Login
+0-1 RequestShow 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
ss.player.login();
// The player is logged in (success === true)
ss.player.on('login', (success) => {});
// Open login overlay
SS_Player.Login();
// Event subscription
private void OnEnable()
{
SS_Player.OnLoginComplete += OnLoginComplete;
SS_Player.OnLoginError += OnLoginError;
}
// Event unsubscription
private void OnDisable()
{
SS_Player.OnLoginComplete -= OnLoginComplete;
SS_Player.OnLoginError -= OnLoginError;
}
// Event handling
private void OnLoginComplete()
{
Debug.Log("LoginComplete");
}
// Event handling
private void OnLoginError()
{
Debug.Log("LoginError");
}
Logout
+0-1 RequestLogout player. If supported logout on platform.
- JavaScript
- Unity
// Logout, returns the promise
ss.player.logout();
// The player is logged in (success === true)
ss.player.on('logout', (success) => {});
// Logout player
SS_Player.Logout();
// Event subscription
private void OnEnable()
{
SS_Player.OnLogoutComplete += OnLogoutComplete;
SS_Player.OnLogoutError += OnLogoutError;
}
// Event unsubscription
private void OnDisable()
{
SS_Player.OnLogoutComplete -= OnLogoutComplete;
SS_Player.OnLogoutError -= OnLogoutError;
}
// Event handling
private void OnLogoutComplete()
{
Debug.Log("LogoutComplete");
}
// Event handling
private void OnLogoutError()
{
Debug.Log("LogoutError");
}
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
ss.player.fetchFields();
// Fields are fetched (success === true)
ss.player.on('fetchFields', (success) => {});
// Fetch fields list
private Fetch() => SS_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
ss.on('event:connect', () => {});
//Subscribe to event
private void OnEnable()
{
SS_Player.OnConnect += OnConnect;
}
//Unsubscribe from event
private void OnDisable()
{
SS_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.
SpellSync Community Telegram
: @spellsync.
For your suggestions e-mail
: [email protected]
We Wish you Success!