FlurryLogger.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class FlurryLogger : MonoBehaviour {
  5. private static FlurryLogger instance;
  6. public static FlurryLogger Instance
  7. {
  8. get
  9. {
  10. if (instance == null)
  11. {
  12. instance = FindObjectOfType(typeof(FlurryLogger)) as FlurryLogger;
  13. if (instance == null)
  14. {
  15. Debug.LogError("No gameObject with FlurryLogger component exists. Make sure to create a gameObject with FlurryLogger component");
  16. }
  17. }
  18. return instance;
  19. }
  20. }
  21. void Awake()
  22. {
  23. if (instance != null && instance != this)
  24. {
  25. Debug.LogWarning("FlurryLogger instance already exists on another gameObject. Destroying this gameObject FlurryLogger");
  26. Destroy(gameObject);
  27. return;
  28. }
  29. instance = this;
  30. DontDestroyOnLoad(gameObject);
  31. #if UNITY_EDITOR
  32. return;
  33. #endif
  34. #if UNITY_IPHONE
  35. FlurryAgent.Instance.onStartSession("WSGD5GHPPRD7B657PCCJ");
  36. #endif
  37. #if UNITY_ANDROID
  38. FlurryAgent.Instance.onStartSession("YVRNMWV7ZZGQSY4ZD3ZW");
  39. #endif
  40. }
  41. public void GamePlayed()
  42. {
  43. LogFlurryEvent("Games played");
  44. }
  45. public void CouponWon()
  46. {
  47. LogFlurryEvent("Coupons won");
  48. }
  49. public void GameFinish(int dist, int packs, int score)
  50. {
  51. //LogFlurryEvent("GamesFinish", "meters", dist.ToString(), "packages", packs.ToString(), "score", score.ToString());
  52. LogFlurryEvent("Meters run", "meters", dist.ToString());
  53. LogFlurryEvent("Packages collected", "packages", packs.ToString());
  54. LogFlurryEvent("Score achieved", "score", score.ToString());
  55. }
  56. public void CapCode()
  57. {
  58. LogFlurryEvent("Cap code");
  59. }
  60. public void LogFlurryEvent (string eventName)
  61. {
  62. //Debug.Log(string.Format("<color=yellow>Sending a Flurry event '{0}'</color>", eventName));
  63. #if UNITY_EDITOR
  64. return;
  65. #endif
  66. var parameters = new Dictionary<string,string>();
  67. parameters.Add("event data","empty");
  68. // FlurryAgent.Instance.logEvent(eventName, parameters);
  69. }
  70. public void LogFlurryEvent (string eventName, params string[] keyValues)
  71. {
  72. Debug.Assert (keyValues.Length % 2 == 0, "Make sure to pass key value pairs");
  73. Debug.Log(string.Format("<color=yellow>Sending a Flurry event '{0}' with the following parameters '{1}'</color>", eventName, string.Join(", ", keyValues)));
  74. #if UNITY_EDITOR
  75. return;
  76. #endif
  77. var parameters = new Dictionary<string, string>();
  78. for (int i = 0; i < keyValues.Length; i += 2)
  79. {
  80. parameters[keyValues[i]] = keyValues[i + 1];
  81. }
  82. FlurryAgent.Instance.logEvent(eventName, parameters);
  83. }
  84. public void CouponConsumed()
  85. {
  86. LogFlurryEvent("Coupon consumed");
  87. }
  88. }