文档

​
​

Development

User Acquisition

Monetization

工业

Authentication

Open Unity Dashboard

Authentication

LiveOps
​
​
Authentication
  • Overview
  • Get started
  • Concepts
  • Tutorials
    • Anonymous sign-in
    • Google Play Games
    • Apple Game Center
    • Steam
    • Facebook
    • Unity Player Accounts
    • Oculus
    • Username and Password
    • Code-Link
    • Google
    • Apple
    • Custom OpenID Connect
    • Custom ID
  • Reference
  • Privacy and consent
  1. Unity Authentication

使用匿名登录

Implement anonymous sign-in to create new players without requiring any sign-in credentials or player input.
阅读时间2 分钟
最后更新于 9 个月前

匿名登录会为游戏创建一个新玩家,而无需玩家输入任何信息。玩家可以通过这种方法快速开启游戏。
如果会话令牌已经缓存到 SDK 上,请使用
SignInAnonymouslyAsync()
方法恢复缓存玩家的已有凭据,无论之前是匿名登录还是通过平台帐户登录。如果没有玩家登录信息,此方法会创建新的匿名玩家。
注意:如果是匿名帐户且未关联到平台特定帐户,则无法恢复该帐户。例如,如果玩家卸载并重新安装游戏,则无法再登录其匿名帐户。
以下代码示例展示如何为玩家设置匿名登录功能并获取访问令牌。
async Task SignInAnonymouslyAsync(){ try { await AuthenticationService.Instance.SignInAnonymouslyAsync(); Debug.Log("Sign in anonymously succeeded!"); // Shows how to get the playerID Debug.Log($"PlayerID: {AuthenticationService.Instance.PlayerId}"); } catch (AuthenticationException ex) { // Compare error code to AuthenticationErrorCodes // Notify the player with the proper error message Debug.LogException(ex); } catch (RequestFailedException ex) { // Compare error code to CommonErrorCodes // Notify the player with the proper error message Debug.LogException(ex); }}
成功执行匿名登录后,建议将其关联到至少一家受支持的身份提供商,让您的玩家能够在需要时使用其他设备继续游戏或恢复其帐户。

Copyright © 2026 Unity Technologies
法律信息隐私政策CookiesDocumentation Terms of Use请勿出售或分享我的个人信息您的隐私选择(Cookie 设置)

“Unity”、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属公司在美国和其他地方的商标或注册商标(此处查看更多信息)。其他名称或品牌是其各自所有者的商标。

为方便起见,一些页面是机器翻译的,可能包含不准确的内容。如有信息不一致的情况,以英文版本为准。


    报告此页面的问题