Me gustaría agregar la autenticación de GameCenter con Firebase a mi juego Unity. Pero en la documentación no está la parte de GameCenter (solo la de Play Games). Ya logré la "parte de la Unidad":
public static void GameCenterAuth() { GameCenterPlatform.ShowDefaultAchievementCompletionBanner(true); Social.localUser.Authenticate (GameCenterProcessAuth); } static void GameCenterProcessAuth(bool success) { if (success) { Social.ReportProgress("Achievement01", 100, (result) => { Debug.Log(result ? "Reported achievement" : "Failed to report achievement"); }); } else { Debug.Log ("Failed to authenticate"); } }Pero pierde el vínculo con Firebase. Para esto necesito obtener el token de acceso de GameCenter pero como el doc no existe, no se como lograrlo.
Con suerte, no hay muchos agujeros en la documentación de Unity, pero cuando encuentra uno, a menudo puede encontrar un código de muestra en los inicios rápidos de Unity (ya que también se usan para validar los cambios en el SDK de Unity).
Desde UIHandler.cs en el inicio rápido de autenticación:
public Task SignInWithGameCenterAsync() { var credentialTask = Firebase.Auth.GameCenterAuthProvider.GetCredentialAsync(); var continueTask = credentialTask.ContinueWithOnMainThread(task => { if(!task.IsCompleted) return null; if(task.Exception != null) Debug.Log("GC Credential Task - Exception: " + task.Exception.Message); var credential = task.Result; var loginTask = auth.SignInWithCredentialAsync(credential); return loginTask.ContinueWithOnMainThread(HandleSignInWithUser); }); return continueTask; } Lo extraño de GameCenter es que no administra la credencial directamente, sino que la solicita desde GameCenter ( Aquí está PlayGames en comparación, que tiene que almacenar en caché el resultado de Authenticate manualmente ).
Entonces, en su código, iría al bloque if (success) y agregaría:
GameCenterAuthProvider.GetCredentialAsync().ContinueWith(task => { // I used ContinueWith // be careful, I'm on a background thread here. // If this is a problem, use ContinueWithOnMainThread if (task.Exception != null) { FirebaseAuth.GetInstance.SignInWithCredentialAsync(task.Result).ContinueWithOnMainThread(task => { // I used ContinueWithOnMainThread // You're on the Unity main thread here, so you can add or change scene objects // If you're comfortable with threading, you can change this to ContinueWith }); } });https://firebase.google.com/docs/auth/ios/game-center Esto podría responder a su pregunta. Es posible que deba implementar esta característica en XCode cuando exporte el proyecto desde la unidad
Para completar la respuesta de Patrick, encontré el repositorio de GitHub de machahamster donde usan Game Center Auth con Firebase en Unity. Si puede ayudar a alguien: https://github.com/google/mechahamster/blob/b5ab9762cc95a2a36156d0cbd1dc08fb767c4080/Assets/Hamster/Scripts/Menus/GameCenterSignIn.cs#L45