该包为使用 Game Frame X 框架的 Unity 项目提供 Apple 登录功能。
要安装此包,请将以下行添加到 Unity 项目 Packages 目录下的 manifest.json 文件中:
{
"dependencies": {
"com.gameframex.unity.login.apple": "https://github.com/gameframex/com.gameframex.unity.login.apple.git#1.0.0",
"com.gameframex.unity": "1.1.1",
"com.lupidan.apple-signin-unity": "1.5.0"
}
}
AppleLoginComponent 添加到场景中的 GameObject。AppleLoginComponent 实例并调用 Init() 方法初始化 Apple 登录管理器。Login() 方法以启动 Apple 登录流程。此方法接受两个操作作为参数:loginSuccess 和 loginFail。AppleLoginSuccess 对象调用 loginSuccess 操作。loginFail 操作。LogOut() 方法以注销用户。using GameFrameX.Login.Apple.Runtime;
using UnityEngine;
public class AppleLoginExample : MonoBehaviour
{
private AppleLoginComponent _appleLoginComponent;
void Start()
{
_appleLoginComponent = GetComponent<AppleLoginComponent>();
_appleLoginComponent.Init();
}
public void OnLoginButtonClick()
{
_appleLoginComponent.Login(
(appleLoginSuccess) =>
{
Debug.Log("Apple 登录成功!");
Debug.Log($"玩家 ID: {appleLoginSuccess.PlayerId}");
Debug.Log($"电子邮件: {appleLoginSuccess.Email}");
Debug.Log($"显示名称: {appleLoginSuccess.DisplayName}");
Debug.Log($"ID 令牌: {appleLoginSuccess.IdToken}");
Debug.Log($"授权码: {appleLoginSuccess.AuthorizationCode}");
},
(errorCode) =>
{
Debug.LogError($"Apple 登录失败,错误码: {errorCode}");
}
);
}
public void OnLogoutButtonClick()
{
_appleLoginComponent.LogOut();
}
}
该包具有以下依赖项: