123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class FlurryLogger : MonoBehaviour {
- private static FlurryLogger instance;
- public static FlurryLogger Instance
- {
- get
- {
- if (instance == null)
- {
- instance = FindObjectOfType(typeof(FlurryLogger)) as FlurryLogger;
- if (instance == null)
- {
- Debug.LogError("No gameObject with FlurryLogger component exists. Make sure to create a gameObject with FlurryLogger component");
- }
- }
- return instance;
- }
- }
- void Awake()
- {
- if (instance != null && instance != this)
- {
- Debug.LogWarning("FlurryLogger instance already exists on another gameObject. Destroying this gameObject FlurryLogger");
- Destroy(gameObject);
- return;
- }
- instance = this;
- DontDestroyOnLoad(gameObject);
- #if UNITY_EDITOR
- return;
- #endif
- #if UNITY_IPHONE
- FlurryAgent.Instance.onStartSession("WSGD5GHPPRD7B657PCCJ");
- #endif
- #if UNITY_ANDROID
- FlurryAgent.Instance.onStartSession("YVRNMWV7ZZGQSY4ZD3ZW");
- #endif
- }
- public void GamePlayed()
- {
- LogFlurryEvent("Games played");
- }
- public void CouponWon()
- {
- LogFlurryEvent("Coupons won");
- }
- public void GameFinish(int dist, int packs, int score)
- {
- //LogFlurryEvent("GamesFinish", "meters", dist.ToString(), "packages", packs.ToString(), "score", score.ToString());
- LogFlurryEvent("Meters run", "meters", dist.ToString());
- LogFlurryEvent("Packages collected", "packages", packs.ToString());
- LogFlurryEvent("Score achieved", "score", score.ToString());
- }
- public void CapCode()
- {
- LogFlurryEvent("Cap code");
- }
- public void LogFlurryEvent (string eventName)
- {
- //Debug.Log(string.Format("<color=yellow>Sending a Flurry event '{0}'</color>", eventName));
- #if UNITY_EDITOR
- return;
- #endif
- var parameters = new Dictionary<string,string>();
- parameters.Add("event data","empty");
- // FlurryAgent.Instance.logEvent(eventName, parameters);
- }
-
- public void LogFlurryEvent (string eventName, params string[] keyValues)
- {
- Debug.Assert (keyValues.Length % 2 == 0, "Make sure to pass key value pairs");
- Debug.Log(string.Format("<color=yellow>Sending a Flurry event '{0}' with the following parameters '{1}'</color>", eventName, string.Join(", ", keyValues)));
- #if UNITY_EDITOR
- return;
- #endif
- var parameters = new Dictionary<string, string>();
- for (int i = 0; i < keyValues.Length; i += 2)
- {
- parameters[keyValues[i]] = keyValues[i + 1];
- }
- FlurryAgent.Instance.logEvent(eventName, parameters);
- }
-
- public void CouponConsumed()
- {
- LogFlurryEvent("Coupon consumed");
- }
- }
|