MotaForSwitch/Assets/Scripts/AxiNSApi/AxiNSUser.cs

90 lines
1.9 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.

using nn.account;
public class AxiNSUser
{
bool m_bInit = false;
bool m_bGotOpenPreselectedUser = false;
Uid m_UserId;
nn.account.UserHandle mUserHandle;
nn.account.Nickname m_NickName;
#region
public bool GetUserID(out Uid uid)
{
InitPreselectedUserInfo();
if (!m_bGotOpenPreselectedUser)
{
uid = Uid.Invalid;
return false;
}
uid = m_UserId;
return true;
}
public bool GetNickName(out string NickName)
{
InitPreselectedUserInfo();
if (!m_bGotOpenPreselectedUser)
{
NickName = string.Empty;
return false;
}
NickName = m_NickName.ToString();
return true;
}
#endregion
/// <summary>
/// 初始化Account模块儿
/// </summary>
void InitNSAccount()
{
if (m_bInit)
return;
//必须先初始化NS的Account 不然调用即崩
nn.account.Account.Initialize();
m_bInit = true;
}
/// <summary>
/// 获取预选用户
/// </summary>
void InitPreselectedUserInfo()
{
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;
}
}