Firebase 初始化
官方範例
The Firebase Unity SDK for Android requires Google Play services, which must be up-to-date before the SDK can be used.
官方初始化範例
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
var dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available) {
// Create and hold a reference to your FirebaseApp,
// where app is a Firebase.FirebaseApp property of your application class.
app = Firebase.FirebaseApp.DefaultInstance;
// Set a flag here to indicate whether Firebase is ready to use by your app.
} else {
UnityEngine.Debug.LogError(System.String.Format(
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
// Firebase Unity SDK is not safe to use here.
}
});
Create FirebaseApp
根據google-services.json或GoogleService-Info.plist內設定串建預設的FirebaseApp
FirebaseApp app = FirebaseApp.DefaultInstance;
Debug.Log(app.Name);//output:__FIRAPP_DEFAULT
一個應用程式內內創建多個FirebaseApp
Firebase.AppOptions secondaryAppOptions = new Firebase.AppOptions {
ApiKey = "<API_KEY>",
AppId = "<GOOGLE_APP_ID>",
ProjectId = "<PROJECT_ID>"
};
FirebaseApp secondaryApp = FirebaseApp.Create(secondaryAppOptions, name);
Debug.Log(secondaryApp.Name);//output: 會是你輸入的name,需唯一
如果要用APP使用其他Firebase功能,以Auth作範例
FirebaseAuth auth = FirebaseAuth.DefaultInstance;
FirebaseAuth secondaryAuth = FirebaseAuth.GetAuth(secondaryApp);
Reference
Add Firebase to your Unity project
Configure multiple projects