官网下载sdk https://firebase.google.com/download/unity
解压出来 长这样
Unity2017 之后的 ,导入dotnet4里面的包
需要用什么功能,导入什么包
代码截图,(图片看着方便,后文直接放代码)
1、看留存,打点用的代码
打点:(注意 , 不要带特殊字符 (: 空格,等等等等)如果非要有加下划线吧。字符串不能过长(测试在45个字节以下才行), 不然无法上传 )
2、A/B测试 -(第一张图的调用位置不要忘了)
注意 AB测试需要条件 :
1、 手机支持Google服务 , 不支持的话 ,会弹窗告诉你(下载google play 会提示安装google服务)
2、翻墙,不然集合传不上去,自然也午饭根据字段获取值
最后 上代码:
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;
}
}