Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

828
Visualizações
How to Access Auth Token in Unity with GameCenter Firebase Authentication

I would like to add the GameCenter Authentication with Firebase to my Unity Game. But in the documentation there isn't the GameCenter part (only Play Games one). I already achieved the "Unity part":

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");
        }
    }

But it misses the link with Firebase. For this I need to get the access token of GameCenter but like the doc doesn't exist, I don't know how to achieve this.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Hopefully there aren't many holes in the Unity documentation, but when you do find one you can often find sample code in the Unity Quickstarts (as these are also used to validate changes to the Unity SDK).

From UIHandler.cs in the Auth quickstart:

    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;
    }

What's weird about GameCenter is that you don't manage the credential directly, rather you request it from GameCenter (Here's PlayGames by comparison, which you have to cache the result of Authenticate manually).

So in your code, I'd go into the if (success) block and add:

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
        });
    }
});
over 4 years ago · Santiago Trujillo Relatório

0

https://firebase.google.com/docs/auth/ios/game-center This might answer your question. You may have to implement this feature in XCode when you export the project from unity

over 4 years ago · Santiago Trujillo Relatório

0

To complete Patrick's answer I found the machahamster GitHub repo where they use the Game Center Auth with Firebase on Unity. If it can helps someone: https://github.com/google/mechahamster/blob/b5ab9762cc95a2a36156d0cbd1dc08fb767c4080/Assets/Hamster/Scripts/Menus/GameCenterSignIn.cs#L45

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda