Download the SDK from the official website https://firebase.google.com/download/unity
Unzip it looks like this
After Unity2017, import the package in dotnet4
What function need to be used, what package to import
Code screenshot, (picture is convenient to look at, put the code directly in the text below)
1. Look at the code used for retention and management
Dot: (note, do not bring special characters (: spaces, etc.) if you have to add an underline. The string cannot be too long (the test is less than 45 bytes), otherwise it cannot be uploaded)
2. A/B test-(don’t forget the calling position of the first picture)
Note that AB test requires conditions:
1. The mobile phone supports Google services, if not, a pop-up window will tell you (downloading google play will prompt to install google services)
2. Over the wall, otherwise the collection will not be uploaded, so naturally we will get the value based on the field for lunch
Finally, the code:
void InitializeFirebaseAndStart()
{
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.
FirebaseApp app = Firebase.FirebaseApp.DefaultInstance;
IsInit = true;
//Firebase.Analytics.FirebaseAnalytics.LogEvent("Login");
Debug.LogError("firebase 实例成功");
InitializeRemote();
// 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.
}
});
}
public Task InitializeRemote()
{
System.Collections.Generic.Dictionary<string, object> defaults =
new System.Collections.Generic.Dictionary<string, object>();
defaults.Add("Get_NewbieReward", 0);
defaults.Add("Default_Useweapon", 0);
Firebase.RemoteConfig.FirebaseRemoteConfig.SetDefaults(defaults);
return FetchDataAsync();
}
public Task FetchDataAsync()
{
// FetchAsync only fetches new data if the current data is older than the provided
// timespan. Otherwise it assumes the data is "recent enough", and does nothing.
// By default the timespan is 12 hours, and for production apps, this is a good
// number. For this example though, it's set to a timespan of zero, so that
// changes in the console will always show up immediately.
System.Threading.Tasks.Task fetchTask = Firebase.RemoteConfig.FirebaseRemoteConfig.FetchAsync(System.TimeSpan.Zero);
return fetchTask.ContinueWith(FetchComplete);
}
private bool Activate =false ;
void FetchComplete(Task fetchTask)
{
if (fetchTask.IsCanceled)
{
Debug.LogError("______________AB FetchComplete Fetch canceled.");
}
else if (fetchTask.IsFaulted)
{
Debug.LogError("______________AB FetchComplete Fetch encountered an error.");
}
else if (fetchTask.IsCompleted)
{
Debug.LogError("______________AB Fetch completed successfully!");
}
var info = Firebase.RemoteConfig.FirebaseRemoteConfig.Info;
Debug.LogError("featchTask::::" + info.LastFetchStatus);
switch (info.LastFetchStatus)
{
case Firebase.RemoteConfig.LastFetchStatus.Success:
Firebase.RemoteConfig.FirebaseRemoteConfig.ActivateFetched();
Activate = true;
Debug.LogError("___ Success ___________AB "+ Activate); ;
Debug.Log(string.Format("FetchComplete Remote data loaded and ready (last fetch time {0}).",
info.FetchTime));
break;
case Firebase.RemoteConfig.LastFetchStatus.Failure:
switch (info.LastFetchFailureReason)
{
case Firebase.RemoteConfig.FetchFailureReason.Error:
break;
case Firebase.RemoteConfig.FetchFailureReason.Throttled:
break;
}
Debug.LogError("___ Failure ___________AB ");
break;
case Firebase.RemoteConfig.LastFetchStatus.Pending:
Debug.LogError("___ Pending ___________AB ");
break;
}
}