GUALoginResultObservers
[MSDK and Player Network SDK] Callback for the registration and login module. The game needs to handle this callback.For more information on the callback data structure, see GUALoginResult.
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 events | Common | [Player Network SDK only] | [MSD only] |
|---|---|---|---|
| LoginResultEvents | Login, Bind, AutoLogin, SwitchUser, QueryUserInfo, LoginWithConfirmCode | Register, LoginWithMappedChannel, BuildMapWithLoggedinChannel, QueryLegalDocumentsAcceptedVersion, LoginWithPassword, LoginWithVerifyCode | BindUI, Check, CheckLogin, BindWithConfirmCode |
event OnResultHandler<GUALoginResult> LoginResultEvents;
List of methods used to handle the callback
| Callback events | Common | [Player Network SDK only] | [MSD only] |
|---|---|---|---|
| OnLoginResultNotify | Login, Bind, AutoLogin, SwitchUser, QueryUserInfo, LoginWithConfirmCode | Register, LoginWithMappedChannel, BuildMapWithLoggedinChannel, QueryLegalDocumentsAcceptedVersion, LoginWithPassword, LoginWithVerifyCode | BindUI, Check, CheckLogin, BindWithConfirmCode |
class GUA_EXTERN GUAAccountObserver
{
public:
virtual ~GUAAccountObserver() {};
virtual void OnLoginResultNotify(const GUALoginResult &auth_result) {};
};
Code Example
- Unity
- Unreal Engine
// Add callback
UnionAdapterAPI.GetAccountService().LoginResultEvents += OnLoginResultEvent;
// Remove callback
UnionAdapterAPI.GetAccountService().LoginResultEvents -= OnLoginResultEvent;
// Callback handler for LoginResultEvents
public void OnLoginResultEvent(GUALoginResult loginRet)
{
Debug.Log("OnLoginResultEvent");
string methodTag = "";
if (loginRet.MethodId == (int)GUAMethodID.GUA_ACCOUNT_LOGIN)
{
methodTag = "Login";
}
else if (loginRet.MethodId == (int)GUAMethodID.GUA_ACCOUNT_BIND)
{
methodTag = "Bind";
}
else if (loginRet.MethodId == (int)GUAMethodID.GUA_ACCOUNT_AUTOLOGIN)
{
methodTag = "AutoLogin";
}
else if (loginRet.MethodId == (int)GUAMethodID.GUA_ACCOUNT_SWITCH_USER)
{
methodTag = "SwitchUser";
}
else if (loginRet.MethodId == (int)GUAMethodID.GUA_ACCOUNT_QUERY_USER_INFO)
{
methodTag = "QueryUserInfo";
}
Debug.Log("OnLoginResultEvent start format json");
Debug.Log(methodTag + loginRet);
}
// 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., OnLoginResultNotify)
class FGUAAccountObserver : public GUA_NAMESPACE::GUAAccountObserver {
public:
static FGUAAccountObserver Instance;
void OnLoginResultNotify(const GUA_NAMESPACE::GUALoginResult &auth_result)
{
}
}
FGUAAccountObserver FGUAAccountObserver::Instance;
// Set callback
GUA_NAMESPACE::GUAAccountService::SetAccountObserver(&FGUAAccountObserver::Instance);