首先
在这个下一下FireBase的资源
firebase11.0.6
然后导入Analytics Auth Crashlytics
其他的看着加就行
然后直接丢到Unity里面
接下来需要去Firebase里面下载
Google json
丢到
这个下面
然后就是脚本代码了
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class CrashlyticsInit : MonoBehaviour
{public static CrashlyticsInit instance;private void Awake(){instance = this;}// Start is called before the first frame updatevoid Start(){// Initialize FirebaseDebug.Log("开始初始化Firebase------------------------------------------");Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {Debug.Log("开始进入Firebase------------------------------------------");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.// Crashlytics will use the DefaultInstance, as well;// this ensures that Crashlytics is initialized.Firebase.FirebaseApp app = Firebase.FirebaseApp.DefaultInstance;UploadFirebase("FirebaseInit",new Dictionary<string, object> { { "FirebaseInit", "FirebaseInit" } });// FirebaseZhifu(1.0f);Debug.Log("初始化Firebase完成------------------------------------------");// Set a flag here for indicating that your project is ready to use Firebase.}else{UnityEngine.Debug.LogError(System.String.Format("Could not resolve all Firebase dependencies: {0}", dependencyStatus));// Firebase Unity SDK is not safe to use here.Debug.Log("初始化Firebase失败------------------------------------------");}});Firebase.Analytics.FirebaseAnalytics.LogEvent(Firebase.Analytics.FirebaseAnalytics.EventPurchase,new Firebase.Analytics.Parameter[] {new Firebase.Analytics.Parameter(Firebase.Analytics.FirebaseAnalytics.ParameterCharacter, "character"),new Firebase.Analytics.Parameter(Firebase.Analytics.FirebaseAnalytics.ParameterLevel, "level"),});}public void UploadFirebase(string EventName, Dictionary<string, object> dic){if (Application.platform == RuntimePlatform.WindowsEditor){return;}List<Firebase.Analytics.Parameter> parmlist = new List<Firebase.Analytics.Parameter>();foreach (var item in dic){Firebase.Analytics.Parameter parameter = new Firebase.Analytics.Parameter(item.Key, item.Value.ToString());parmlist.Add(parameter);}Firebase.Analytics.FirebaseAnalytics.LogEvent(EventName, parmlist.ToArray());}//支付打点public void FirebaseZhifu(float jine) {Firebase.Analytics.FirebaseAnalytics.LogEvent("custom_progress_event", "percent", jine);}// Update is called once per framevoid Update(){}
}
嫌麻烦直接复制这段就行
然后把这玩意丢到不会销毁的物体上
Firebase不出意外就对接完成
接下来是处理Fb的支付埋点
按他官方文档来说,只要你接入了Firebase他就会自动去打点支付
但是你得去开发者后台关联一下
那么
这样点完
然后看到这个地方
我这个是关联完成了的
如果你没关联完成
那么你需要点一下关联
然后里面如果是英文把他翻译成中文
然后你就啥都懂了
如果你没法关联提示什么找不到包名什么的
那么你需要检查你这个Firebase账号是不是和上架的谷歌账号是一个
如果不是一个那么去
这个地方添加权限
然后大抵就行了
还有就是你得看一下包名和
这一坨填没
这一坨要去谷歌开发者的
这个地方看
至此
结束