如何使用GameCenter Firebase身份验证统一访问身份验证令牌
我想将GameCenter与Firebase的身份验证添加到我的Unity游戏中。但是在文档中没有GameCenter部分(只玩游戏一)。 我已经完成了“统一部分”:如何使用GameCenter Firebase身份验证统一访问身份验证令牌,firebase,unity3d,game-center,Firebase,Unity3d,Game Center,我想将GameCenter与Firebase的身份验证添加到我的Unity游戏中。但是在文档中没有GameCenter部分(只玩游戏一)。 我已经完成了“统一部分”: 但它忽略了与Firebase的联系。为此,我需要获得GameCenter的访问令牌,但就像文档不存在一样,我不知道如何实现这一点。这可能会回答您的问题。当您从unity导出项目时,可能必须在XCode中实现此功能。希望unity文档中没有太多漏洞,但是当您找到漏洞时,通常可以在中找到示例代码(因为这些代码也用于验证对unity S
但它忽略了与Firebase的联系。为此,我需要获得GameCenter的访问令牌,但就像文档不存在一样,我不知道如何实现这一点。这可能会回答您的问题。当您从unity导出项目时,可能必须在XCode中实现此功能。希望unity文档中没有太多漏洞,但是当您找到漏洞时,通常可以在中找到示例代码(因为这些代码也用于验证对unity SDK的更改) 从中: GameCenter的奇怪之处在于,您没有直接管理凭证,而是自己(相比之下,您必须这样做) 因此,在您的代码中,我将进入
if(success)
块并添加:
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
});
}
});
为了完成Patrick的回答,我找到了machahamster GitHub repo,他们在Unity上使用Firebase的游戏中心Auth。 如果它能帮助某人:
感谢您的回复,我看到了这一部分,但我正在寻找直接在Unity中制作的方法。我认为这是可能的,因为在这个链接之后,有一个类具有GetCredentialAsync方法,允许您使用firebase进行身份验证。但是这个方法在参数中使用了一个令牌auth,我不知道如何获得它。非常好用,谢谢!
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;
}
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
});
}
});