Unity快速引入Firebase

最近在尝试给APP引入账号第三方SDK,再三比较,如果是出海的APP,Firebase是不二选择。

接入的过程中比较坎坷,分别尝试了AS导出aar包到unity,还有从unity导出AS工程,都以失败告终(IOS还未尝试)。

其实是根本就是我没仔细阅读官方文档,google官方有提供unitypackage,将其导入unity并在后台做简单设置即可。

官方文档:https://firebase.google.com/docs/auth/unity/start

0.1. 在Firebase后台注册应用


(注意,注册的时的包名要跟应用的最终包名一致)

0.2. 在应用设置中添加SHA证书指纹

0.3. 下载google-services.json

文件放到unity项目里的Asset/StreamingAssets中

0.4. 启用服务提供方

0.5. 导入FirebaseAuth.unitypackage

0.6. 添加测试代码

auth.CreateUserWithEmailAndPasswordAsync(email, password)
.ContinueWith(task =>
{
if (task.IsCanceled)
{
Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError(
"CreateUserWithEmailAndPasswordAsync encountered an error: "
+ task.Exception
);
return;
}

// Firebase user has been created.
FirebaseUser newUser = task.Result;
Debug.LogFormat(
"Firebase user created successfully: {0} ({1})",
newUser.DisplayName,
newUser.UserId
);
});