GUALoginResultObservers
[MSDK and Player Network SDK] 注册登录模块的回调,游戏需要对回调函数进行处理。更多关于回调数据结构,请参见 GUALoginResult。
注意
强烈建议游戏在应用启动函数中进行注册。
函数定义
- Unity
- Unreal Engine
回调事件用于处理的方法列表
回调事件 | Common | [仅限 Player Network SDK] | [仅限 MSD] |
---|---|---|---|
LoginResultEvents | Login, Bind, AutoLogin, SwitchUser, QueryUserInfo, LoginWithConfirmCode | Register, LoginWithMappedChannel, BuildMapWithLoggedinChannel, QueryLegalDocumentsAcceptedVersion, LoginWithPassword, LoginWithVerifyCode | BindUI, Check, CheckLogin, BindWithConfirmCode |
event OnResultHandler<GUALoginResult> LoginResultEvents;
回调事件用于处理的方法列表
回调事件 | Common | [仅限 Player Network SDK] | [仅限 MSD] |
---|---|---|---|
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) {};
};
代码示例
- Unity
- Unreal Engine
// 增加回调
UnionAdapterAPI.GetAccountService().LoginResultEvents += OnLoginResultEvent;
// 移除回调
UnionAdapterAPI.GetAccountService().LoginResultEvents -= OnLoginResultEvent;
// 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.在引擎层定义继承自 GUA_NAMESPACE::GUAAccountObserver 的观察者类
// 2.实现方法名一样的回调接口(如:OnLoginResultNotify)
class FGUAAccountObserver : public GUA_NAMESPACE::GUAAccountObserver {
public:
static FGUAAccountObserver Instance;
void OnLoginResultNotify(const GUA_NAMESPACE::GUALoginResult &auth_result)
{
}
}
FGUAAccountObserver FGUAAccountObserver::Instance;
// 设置回调
GUA_NAMESPACE::GUAAccountService::SetAccountObserver(&FGUAAccountObserver::Instance);