Gamebase SDK for Unity 2.76.0 Toast Gamebase Platform

Loading...
Searching...
No Matches

## ◆ AddEventHandler()

static void AddEventHandler | ( | GamebaseCallback.DataDelegate< GamebaseResponse.Event.GamebaseEventMessage > | eventHandler | ) |
| static

Add a Gamebase event handler to be called when every events are arrived.

You have to convert the message data to VO below according to the category value.

- GamebaseEventCategory.LOGGED_OUT : GamebaseEventLoggedOutData
- GamebaseEventCategory.IDP_REVOKED : GamebaseEventIdPRevokedData
- GamebaseEventCategory.SERVER_PUSH_APP_KICKOUT : GamebaseEventServerPushData
- GamebaseEventCategory.SERVER_PUSH_APP_KICKOUT_MESSAGE_RECEIVED : GamebaseEventServerPushData
- GamebaseEventCategory.SERVER_PUSH_TRANSFER_KICKOUT : GamebaseEventServerPushData
- GamebaseEventCategory.OBSERVER_LAUNCHING : GamebaseEventObserverData
- GamebaseEventCategory.OBSERVER_HEARTBEAT : GamebaseEventObserverData
- GamebaseEventCategory.OBSERVER_NETWORK : GamebaseEventObserverData
- GamebaseEventCategory.OBSERVER_WEBVIEW : GamebaseEventObserverData
- GamebaseEventCategory.OBSERVER_INTROSPECT : GamebaseEventObserverData
- GamebaseEventCategory.PURCHASE_UPDATED : PurchasableReceipt
- GamebaseEventCategory.PUSH_RECEIVED_MESSAGE : PushMessage
- GamebaseEventCategory.PUSH_CLICK_MESSAGE : PushMessage
- GamebaseEventCategory.PUSH_CLICK_ACTION : PushAction

SERVER_PUSH : Receive messages from the Gamebase server. OBSERVER : This is an event that fires when the launch, login account(hearbeat), or network connection 'status changes', webview event, introspect fail event. PURCHASE_UPDATED : Promotion payment events can be received. PUSH_RECEIVED_MESSAGE : This event operates when a Push message is received. PUSH_CLICK_MESSAGE : This event is executed when the Push message is clicked. PUSH_CLICK_ACTION : This is an event that is triggered when the action button added through the rich message function is clicked.

Since
  Added 2.10.0

Parameters

  eventHandler | The callback that will run.

Example Usage :

public void AddEventHandlerSample()
{
Gamebase.AddEventHandler(GamebaseEventHandler);
}
private void GamebaseEventHandler(GamebaseResponse.Event.GamebaseEventMessage message)
{
switch (message.category)
{
case GamebaseEventCategory.LOGGED_OUT:
{
GamebaseResponse.Event.GamebaseEventLoggedOutData loggedData = GamebaseResponse.Event.GamebaseEventLoggedOutData.From(message.data);
if (loggedData != null)
{
// There was a problem with the access token.
// Call login again.
}
break;
}
case GamebaseEventCategory.IDP_REVOKED:
{
GamebaseResponse.Event.GamebaseEventIdPRevokedData idPRevokedData = GamebaseResponse.Event.GamebaseEventIdPRevokedData.From(message.data);
if (idPRevokedData != null)
{
CheckIdpRevoked(idPRevokedData);
}
break;
}
case GamebaseEventCategory.SERVER_PUSH_APP_KICKOUT:
case GamebaseEventCategory.SERVER_PUSH_APP_KICKOUT_MESSAGE_RECEIVED:
case GamebaseEventCategory.SERVER_PUSH_TRANSFER_KICKOUT:
{
GamebaseResponse.Event.GamebaseEventServerPushData serverPushData = GamebaseResponse.Event.GamebaseEventServerPushData.From(message.data);
if (serverPushData != null)
{
CheckServerPush(message.category, serverPushData);
}
break;
}
case GamebaseEventCategory.OBSERVER_LAUNCHING:
{
GamebaseResponse.Event.GamebaseEventObserverData observerData = GamebaseResponse.Event.GamebaseEventObserverData.From(message.data);
if(observerData != null)
{
CheckLaunchingStatus(observerData);
}
break;
}
case GamebaseEventCategory.OBSERVER_NETWORK:
{
GamebaseResponse.Event.GamebaseEventObserverData observerData = GamebaseResponse.Event.GamebaseEventObserverData.From(message.data);
if (observerData != null)
{
CheckNetwork(observerData);
}
break;
}
case GamebaseEventCategory.OBSERVER_HEARTBEAT:
{
GamebaseResponse.Event.GamebaseEventObserverData observerData = GamebaseResponse.Event.GamebaseEventObserverData.From(message.data);
if (observerData != null)
{
CheckHeartbeat(observerData);
}
break;
}
case GamebaseEventCategory.OBSERVER_WEBVIEW:
{
GamebaseResponse.Event.GamebaseEventObserverData observerData = GamebaseResponse.Event.GamebaseEventObserverData.From(message.data);
if (observerData != null)
{
CheckWebView(observerData);
}
break;
}
case GamebaseEventCategory.OBSERVER_INTROSPECT:
{
// Introspect error
GamebaseResponse.Event.GamebaseEventObserverData observerData = GamebaseResponse.Event.GamebaseEventObserverData.From(message.data);
int errorCode = observerData.code;
string errorMessage = observerData.message;
break;
}
case GamebaseEventCategory.PURCHASE_UPDATED:
{
GamebaseResponse.Event.PurchasableReceipt purchasableReceipt = GamebaseResponse.Event.PurchasableReceipt.From(message.data);
if (purchasableReceipt != null)
{
// If the user got item by 'Promotion Code',
// this event will be occurred.
}
break;
}
case GamebaseEventCategory.PUSH_RECEIVED_MESSAGE:
{
GamebaseResponse.Event.PushMessage pushMessage = GamebaseResponse.Event.PushMessage.From(message.data);
if (pushMessage != null)
{
// When you received push message.
// By converting the extras field of the push message to JSON,
// you can get the custom information added by the user when sending the push.
// (For Android, an 'isForeground' field is included so that you can check if received in the foreground state.
}
break;
}
case GamebaseEventCategory.PUSH_CLICK_MESSAGE:
{
GamebaseResponse.Event.PushMessage pushMessage = GamebaseResponse.Event.PushMessage.From(message.data);
if (pushMessage != null)
{
// When you clicked push message.
}
break;
}
case GamebaseEventCategory.PUSH_CLICK_ACTION:
{
GamebaseResponse.Event.PushAction pushAction = GamebaseResponse.Event.PushAction.From(message.data);
if (pushAction != null)
{
// When you clicked action button by 'Rich Message'.
}
break;
}
}
}
private void CheckIdpRevoked(GamebaseResponse.Event.GamebaseEventIdPRevokedData idPRevokedData)
{
switch (idPRevokedData.code)
{
case GamebaseIdPRevokedCode.WITHDRAW:
{
// Call Withdraw API.
Gamebase.Withdraw((error) => { });
break;
}
case GamebaseIdPRevokedCode.OVERWRITE_LOGIN_AND_REMOVE_MAPPING:
{
// You must call RemoveMapping after calling overwrite login.
foreach (var idp in idPRevokedData.authMappingList)
{
var additional = new Dictionary<string, object>();
additional.Add(GamebaseAuthProviderCredential.IGNORE_ALREADY_LOGGED_IN, true);
Gamebase.Login(idp, additional, (authToken, loginError) =>
{
if (Gamebase.IsSuccess(loginError) == true)
{
Gamebase.RemoveMapping(idPRevokedData.idPType, (mappingError) => { });
}
});
}
break;
}
case GamebaseIdPRevokedCode.REMOVE_MAPPING:
{
// Call RemoveMapping API.
Gamebase.RemoveMapping(idPRevokedData.idPType, (error) => { });
break;
}
}
}
private void CheckServerPush(string category, GamebaseResponse.Event.GamebaseEventServerPushData data)
{
if (category.Equals(GamebaseEventCategory.SERVER_PUSH_APP_KICKOUT) == true)
{
// Kicked out from Gamebase server.(Maintenance, banned or etc.)
// And the game user closes the kickout pop-up.
// Return to title and initialize Gamebase again.
}
else if (category.Equals(GamebaseEventCategory.SERVER_PUSH_APP_KICKOUT_MESSAGE_RECEIVED) == true)
{
// Currently, the kickout pop-up is displayed.
// If your game is running, stop it.
}
else if (category.Equals(GamebaseEventCategory.SERVER_PUSH_TRANSFER_KICKOUT) == true)
{
// If the user wants to move the guest account to another device,
// if the account transfer is successful,
// the login of the previous device is released,
// so go back to the title and try to log in again.
}
}
private void CheckLaunchingStatus(GamebaseResponse.Event.GamebaseEventObserverData observerData)
{
switch (observerData.code)
{
case GamebaseLaunchingStatus.IN_SERVICE:
{
// Service is now normally provided.
break;
}
// ...
case GamebaseLaunchingStatus.INTERNAL_SERVER_ERROR:
{
// Error in internal server.
break;
}
}
}
private void CheckNetwork(GamebaseResponse.Event.GamebaseEventObserverData observerData)
{
switch ((GamebaseNetworkType)observerData.code)
{
case GamebaseNetworkType.TYPE_NOT:
{
// Network disconnected.
break;
}
case GamebaseNetworkType.TYPE_MOBILE:
case GamebaseNetworkType.TYPE_WIFI:
case GamebaseNetworkType.TYPE_ANY:
{
// Network connected.
break;
}
}
}
private void CheckHeartbeat(GamebaseResponse.Event.GamebaseEventObserverData observerData)
{
switch (observerData.code)
{
case GamebaseErrorCode.INVALID_MEMBER:
{
// You can check the invalid user session in here.
// ex) After transferred account to another device.
break;
}
case GamebaseErrorCode.BANNED_MEMBER:
{
// You can check the banned user session in here.
break;
}
}
}
private void CheckWebView(GamebaseResponse.Event.GamebaseEventObserverData observerData)
{
switch (observerData.code)
{
case GamebaseWebViewEventType.OPENED:
{
// WebView opened.
break;
}
case GamebaseWebViewEventType.CLOSED:
{
// WebView closed.
break;
}
}
}
Toast.Gamebase.Gamebase.AddEventHandler
static void AddEventHandler(GamebaseCallback.DataDelegate< GamebaseResponse.Event.GamebaseEventMessage > eventHandler)
Add a Gamebase event handler to be called when every events are arrived.
Definition Gamebase.cs:526
Toast.Gamebase.Gamebase
The Gamebase class is core of Gamebase service.
Definition Gamebase.cs:11