Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using Firebase;
- using Firebase.Analytics;
- using System.Threading.Tasks;
- using Firebase.Extensions;
- public class FirebaseManager : MonoBehaviour
- {
- protected bool firebaseInitialized = false;
- void Awake()
- {
- FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
- var dependencyStatus = task.Result;
- if (dependencyStatus == DependencyStatus.Available)
- {
- InitializeFirebase();
- }
- else
- {
- Debug.LogError(string.Format(
- "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
- // Firebase Unity SDK is not safe to use here.
- }
- });
- }
- // Handle initialization of the necessary firebase modules:
- void InitializeFirebase()
- {
- Debug.Log("Enabling data collection.");
- FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
- Debug.Log("Set user properties.");
- // Set the user's sign up method.
- FirebaseAnalytics.SetUserProperty(FirebaseAnalytics.UserPropertySignUpMethod, "Google");
- //// Set the user ID.
- //FirebaseAnalytics.SetUserId("uber_user_510");
- //// Set default session duration values.
- //FirebaseAnalytics.SetMinimumSessionDuration(new TimeSpan(0, 0, 10));
- //FirebaseAnalytics.SetSessionTimeoutDuration(new TimeSpan(0, 30, 0));
- firebaseInitialized = true;
- }
- // Get the current app instance ID.
- public Task<string> DisplayAnalyticsInstanceId()
- {
- return FirebaseAnalytics.GetAnalyticsInstanceIdAsync().ContinueWithOnMainThread(task => {
- if (task.IsCanceled)
- {
- Debug.Log("App instance ID fetch was canceled.");
- }
- else if (task.IsFaulted)
- {
- Debug.Log(string.Format("Encounted an error fetching app instance ID {0}",
- task.Exception.ToString()));
- }
- else if (task.IsCompleted)
- {
- Debug.Log(string.Format("App instance ID: {0}", task.Result));
- }
- return task;
- }).Unwrap();
- }
- public static void TutorialPhaseEvent(bool began) //Вызываем из Grathic Component, когда показываем начальный тутор и когда закрываем его
- {
- if(began)
- FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventTutorialBegin);
- else
- FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventTutorialComplete);
- }
- public static void CompletedLevelEvent(int levelNumber)
- {
- FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventLevelUp, new Parameter(FirebaseAnalytics.ParameterLevel, levelNumber));
- }
- public static void EarnedCurrencyEvent()
- {
- FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventEarnVirtualCurrency, new Parameter[]
- { new Parameter(FirebaseAnalytics.ParameterValue, 1), new Parameter(FirebaseAnalytics.ParameterVirtualCurrencyName, "Coin") });
- }
- public static void UsedFrostEvent(int frostCharges) //MY OWN EVENT
- {
- FirebaseAnalytics.LogEvent("Player pressed the Frost button", new Parameter("Frost charges left", frostCharges));
- }
- public static void SpentCurrencyEvent(string itemName, int spentAmount)
- {
- FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventSpendVirtualCurrency, new Parameter[]
- { new Parameter(FirebaseAnalytics.ParameterItemName, itemName), new Parameter(FirebaseAnalytics.ParameterValue, spentAmount)});
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement