AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Plugins/AxiNSApi/AxiNSUser.cs

107 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#if UNITY_SWITCH
using nn.account;
#endif
public class AxiNSUser
{
bool m_bInit = false;
bool m_bGotOpenPreselectedUser = false;
#if UNITY_SWITCH
Uid m_UserId;
nn.account.UserHandle mUserHandle;
nn.account.Nickname m_NickName;
#endif
#region
#if UNITY_SWITCH
public bool GetUserID(out Uid uid)
{
InitPreselectedUserInfo();
if (!m_bGotOpenPreselectedUser)
{
uid = Uid.Invalid;
return false;
}
uid = m_UserId;
return true;
}
#endif
public bool GetNickName(out string NickName)
{
#if !UNITY_SWITCH
NickName = "";
return true;
#else
InitPreselectedUserInfo();
if (!m_bGotOpenPreselectedUser)
{
NickName = string.Empty;
return false;
}
NickName = m_NickName.ToString();
return true;
#endif
}
#endregion
/// <summary>
/// 初始化Account模块儿
/// </summary>
void InitNSAccount()
{
#if UNITY_SWITCH
if (m_bInit)
return;
//必须先初始化NS的Account 不然调用即崩
nn.account.Account.Initialize();
m_bInit = true;
#endif
}
/// <summary>
/// 获取预选用户
/// </summary>
void InitPreselectedUserInfo()
{
#if UNITY_SWITCH
if (m_bGotOpenPreselectedUser)
return;
InitNSAccount();
nn.Result result;
mUserHandle = new nn.account.UserHandle();
if (!nn.account.Account.TryOpenPreselectedUser(ref mUserHandle))
{
UnityEngine.Debug.LogError("打开预选的用户失败.");
return;
}
UnityEngine.Debug.Log("打开预选用户成功.");
result = nn.account.Account.GetUserId(ref m_UserId, mUserHandle);
//result.abortUnlessSuccess();
if (!result.IsSuccess())
{
UnityEngine.Debug.LogError($"GetUserId失败: {result.ToString()}");
return;
}
if (m_UserId == Uid.Invalid)
{
UnityEngine.Debug.LogError("无法获取用户 ID");
return;
}
UnityEngine.Debug.Log($"获取用户 ID:{m_UserId.ToString()}");
result = nn.account.Account.GetNickname(ref m_NickName, m_UserId);
//result.abortUnlessSuccess();
if (!result.IsSuccess())
{
UnityEngine.Debug.LogError($"GetNickname失败: {result.ToString()}");
return;
}
UnityEngine.Debug.Log($"获取用户 NickName ID:{m_NickName.ToString()}");
m_bGotOpenPreselectedUser = true;
#endif
}
}