GUABaseResultObservers
[Shared by Player Network SDK & MSDK] Callback for the registration and login module. The game needs to handle this callback.For more details on the callback data structure, see the data structure GUABaseResult.
note
It is strongly recommended that the game registers the callback in the application startup function.
Function Definition
- Unity
- Unreal Engine
List of methods used to handle the callback
| Callback event | Common | [Player Network SDK only] | [MSD only] |
|---|---|---|---|
| LoginBaseResultEvents | Logout, ResetGuest | ModifyLegalDocumentsAcceptedVersion, Unbind, CancelAccountDeletion | CheckUniversalLink, ChannelPermissionAuth |
event OnResultHandler<GUABaseResult> LoginBaseResultEvents;
List of methods used to handle the callback
| Callback event | Common | [Player Network SDK only] | [MSD only] |
|---|---|---|---|
| OnBaseResultNotify | Logout, ResetGuest | ModifyLegalDocumentsAcceptedVersion, Unbind, CancelAccountDeletion | CheckUniversalLink, ChannelPermissionAuth |
class GUA_EXTERN GUAAccountObserver
{
public:
virtual ~GUAAccountObserver() {};
virtual void OnBaseResultNotify(const GUABaseResult &base_result) {};
};
Code Example
- Unity
- Unreal Engine
// Add callback
UnionAdapterAPI.GetAccountService().LoginBaseResultEvents += OnLoginBaseResultEvent;
// Remove callback
UnionAdapterAPI.GetAccountService().LoginBaseResultEvents -= OnLoginBaseResultEvent;
// Handling the callback of LoginBaseResultEvents
public void OnLoginBaseResultEvent(GUABaseResult baseRet)
{
Debug.Log("OnLoginBaseResultEvent in Login");
string methodTag = "";
if (baseRet.MethodId == (int)GUAMethodID.GUA_ACCOUNT_LOGOUT)
{
methodTag = "Logout";
}
else if (baseRet.MethodId == (int)GUAMethodID.GUA_ACCOUNT_WAKEUP) // [MSD only]
{
handleDiifAccount(baseRet);
}
else if (baseRet.MethodId == (int)GUAMethodID.GUA_ACCOUNT_UNBIND) // [Player Network SDK only]
{
methodTag = "Unbind";
}
else if (baseRet.MethodId == (int)GUAMethodID.GUA_ACCOUNT_MODIFY_LEGAL_DOCUMENTS) // [Player Network SDK only]
{
methodTag = "ModifyLegalDocument";
}
Debug.Log(methodTag + baseRet);
}
/// <summary>
/// Handle alternate accounts
/// </summary>
/// <param name="baseRet">Base ret.</param>
private void handleDiifAccount(GUABaseResult baseRet)
{
string methodTag = "WAKEUP";
switch (baseRet.RetCode)
{
case GUAErrorCode.SUCCESS:
{ // The existing local ticket is valid, use the original ticket to log in
Debug.Log(methodTag + "Use the original ticket to log in, the game does not need to be processed");
break;
}
case GUAErrorCode.LOGIN_ACCOUNT_REFRESH:
{ // Old and new openid are the same, but the tickets are different. Refresh the login ticket
Debug.Log(methodTag + "The old and new openid is the same, but the ticket is different. Refresh the login ticket, the game does not need to process");
break;
}
case GUAErrorCode.LOGIN_URL_USER_LOGIN:
{// No local openid, pop up with a ticket, use the new ticket to log in
Debug.Log(methodTag + "The old and new openid is the same, but the ticket is different. Refresh the login ticket, the game does not need to process");
break;
}
case GUAErrorCode.LOGIN_NEED_SELECT_ACCOUNT:
{
Debug.Log(methodTag + "Need select account");
break;
}
case GUAErrorCode.LOGIN_NEED_LOGIN:
{
Debug.Log(methodTag + "Tickets are invalid, enter the login page");
}
break;
default:
break;
}
}
// 1. Define an observer class in the engine layer that inherits from GUA_NAMESPACE::GUAAccountObserver
// 2. Implement callback interfaces with the same method names (e.g., OnBaseResultNotify)
class FGUAAccountObserver : public GUA_NAMESPACE::GUAAccountObserver {
public:
static FGUAAccountObserver Instance;
void OnBaseResultNotify(const GUA_NAMESPACE::GUABaseResult &base_result)
{
}
}
FGUAAccountObserver FGUAAccountObserver::Instance;
// Set callback
GUA_NAMESPACE::GUAAccountService::SetAccountObserver(&FGUAAccountObserver::Instance);