Unity/Firebase/Authentication
提供: 初心者エンジニアの簡易メモ
Firebase設定
unity/Firebase/基本 [ショートカット]
認証プラグインインストール
FirebaseAuth.unitypackageをAssets/Importからインストールする
https://firebase.google.com/download/unity?hl=ja
匿名認証を使う場合
- web側のfirebaseコンソールで匿名認証を有効にする(Authentication/ログイン方法/匿名/有効)
以下を実装
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
auth.SignInAnonymouslyAsync().ContinueWith(task => {
if (task.IsCanceled)
{
Debug.LogError("SignInAnonymouslyAsync was canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("SignInAnonymouslyAsync encountered an error: " + task.Exception); // 匿名が有効になって場合はこちらを通る。
return;
}
Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: ({0}) ({1})",
newUser.DisplayName, newUser.UserId);
Debug.Log("user=" + newUser.DisplayName); // 匿名では空だった
Debug.Log("user=" + newUser.UserId); // こちらはX3TUGaMPQPaN1rmGL2CxhQ4z4712と表示
});
