PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Assets/GameAnalytics/Plugins/Framework/Scripts/GA_Settings.cs

https://bitbucket.org/AgentCodeMonkey/gameframework-unity-project
C# | 239 lines | 148 code | 37 blank | 54 comment | 27 complexity | 7457e9a815fde91e0f23254506279c4b MD5 | raw file
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. /// <summary>
  5. /// GA test. This should be instances as an asset and
  6. /// </summary>
  7. ///
  8. public class GA_Settings : ScriptableObject
  9. {
  10. /// <summary>
  11. /// Types of help given in the help box of the GA inspector
  12. /// </summary>
  13. public enum HelpTypes { None, FpsCriticalAndTrackTargetHelp, GuiAndTrackTargetHelp, IncludeSystemSpecsHelp, ProvideCustomUserID };
  14. public enum MessageTypes { None, Error, Info, Warning };
  15. /// <summary>
  16. /// A message and message type for the help box displayed on the GUI inspector
  17. /// </summary>
  18. public struct HelpInfo
  19. {
  20. public string Message;
  21. public MessageTypes MsgType;
  22. public HelpTypes HelpType;
  23. }
  24. #region public static values
  25. /// <summary>
  26. /// The version of the GA Unity Wrapper plugin
  27. /// </summary>
  28. [HideInInspector]
  29. public static string VERSION = "0.3.7";
  30. #endregion
  31. #region public values
  32. public int TotalMessagesSubmitted;
  33. public int TotalMessagesFailed;
  34. public int DesignMessagesSubmitted;
  35. public int DesignMessagesFailed;
  36. public int QualityMessagesSubmitted;
  37. public int QualityMessagesFailed;
  38. public int BusinessMessagesSubmitted;
  39. public int BusinessMessagesFailed;
  40. public int UserMessagesSubmitted;
  41. public int UserMessagesFailed;
  42. public string CustomArea = string.Empty;
  43. //Set the track target to use for predefined events, such as CriticalFPS (position of track target is sent with these events).
  44. public Transform TrackTarget;
  45. [SerializeField]
  46. public string GameKey = "";
  47. [SerializeField]
  48. public string SecretKey = "";
  49. [SerializeField]
  50. public string ApiKey = "";
  51. [SerializeField]
  52. public string Build = "0.1";
  53. public bool DebugMode = true;
  54. public bool RunInEditorPlayMode = true;
  55. public bool AllowRoaming = false;
  56. public bool ArchiveData = false;
  57. //bytes
  58. public long ArchiveMaxFileSize = 2000;
  59. public bool CustomUserID;
  60. public float SubmitInterval = 10;
  61. public bool InternetConnectivity;
  62. //These values are used for the GA_Inspector only
  63. public enum InspectorStates { Basic, QA, Debugging, Data, Pref }
  64. public InspectorStates CurrentInspectorState;
  65. public List<HelpTypes> ClosedHints = new List<HelpTypes>();
  66. public bool DisplayHints;
  67. public Vector2 DisplayHintsScrollState;
  68. public Texture2D Logo;
  69. #endregion
  70. #region public methods
  71. /// <summary>
  72. /// Help/hints/tips messages used for the GA inspector hints box. This function decides which hint to display.
  73. /// Garbos: Depricated because: Was duplicated to return list of messages instead. Use GetHelpMessageList
  74. /// </summary>
  75. /// <returns>
  76. /// The help message.
  77. /// </returns>
  78. public List<HelpInfo> GetHelpMessageList()
  79. {
  80. List<HelpInfo> result = new List<HelpInfo>();
  81. if (GameKey.Equals("") || SecretKey.Equals(""))
  82. {
  83. result.Add( new HelpInfo() { Message = "Please fill in your Game Key and Secret Key, obtained from the GameAnalytics website where you created your game.", MsgType = MessageTypes.Warning, HelpType = HelpTypes.None });
  84. }
  85. if (Build.Equals(""))
  86. {
  87. result.Add( new HelpInfo() { Message = "Please fill in a name for your build, representing the current version of the game. Updating the build name for each version of the game will allow you to filter by build when viewing your data on the GA website.", MsgType = MessageTypes.Warning, HelpType = HelpTypes.None });
  88. }
  89. if (CustomUserID && !ClosedHints.Contains(HelpTypes.ProvideCustomUserID))
  90. {
  91. result.Add( new HelpInfo() { Message = "You have indicated that you will provide a custom user ID - no data will be submitted until it is provided. This should be defined from code through: GA.Settings.SetCustomUserID", MsgType = MessageTypes.Info, HelpType = HelpTypes.ProvideCustomUserID });
  92. }
  93. return result;
  94. }
  95. /// <summary>
  96. /// Help/hints/tips messages used for the GA inspector hints box. This function decides which hint to display.
  97. /// Garbos: Depricated because: Was duplicated to return list of messages instead. Use GetHelpMessageList
  98. /// </summary>
  99. /// <returns>
  100. /// The help message.
  101. /// </returns>
  102. public HelpInfo GetHelpMessage()
  103. {
  104. if (GameKey.Equals("") || SecretKey.Equals(""))
  105. {
  106. return new HelpInfo() { Message = "Please fill in your Game Key and Secret Key, obtained from the GameAnalytics website where you created your game.", MsgType = MessageTypes.Warning, HelpType = HelpTypes.None };
  107. }
  108. else if (Build.Equals(""))
  109. {
  110. return new HelpInfo() { Message = "Please fill in a name for your build, representing the current version of the game. Updating the build name for each version of the game will allow you to filter by build when viewing your data on the GA website.", MsgType = MessageTypes.Warning, HelpType = HelpTypes.None };
  111. }
  112. else if (CustomUserID && !ClosedHints.Contains(HelpTypes.ProvideCustomUserID))
  113. {
  114. return new HelpInfo() { Message = "You have indicated that you will provide a custom user ID - no data will be submitted until it is provided. This should be defined from code through: GA.Settings.SetCustomUserID", MsgType = MessageTypes.Info, HelpType = HelpTypes.ProvideCustomUserID };
  115. }
  116. return new HelpInfo() { Message = "No hints to display. The \"Reset Hints\" button resets closed hints.", MsgType = MessageTypes.None, HelpType = HelpTypes.None };
  117. }
  118. /// <summary>
  119. /// Checks the internet connectivity, and sets INTERNETCONNECTIVITY
  120. /// </summary>
  121. public IEnumerator CheckInternetConnectivity(bool startQueue)
  122. {
  123. // Application.internetReachability returns the type of Internet reachability currently possible on the device, but does not check if the there is an actual route to the network. So we can check this instantly.
  124. if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork && !GA.Settings.AllowRoaming)
  125. {
  126. InternetConnectivity = false;
  127. }
  128. else
  129. {
  130. //Try to ping the server
  131. WWW www = new WWW(GA.API.Submit.GetBaseURL(true) + "/ping");
  132. //Wait for response
  133. yield return www;
  134. try
  135. {
  136. if (GA.API.Submit.CheckServerReply(www))
  137. {
  138. InternetConnectivity = true;
  139. }
  140. else if (www.error != null)
  141. {
  142. InternetConnectivity = false;
  143. }
  144. else
  145. {
  146. //Get the JSON object from the response
  147. Dictionary<string, object> returnParam = LitJson.JsonMapper.ToObject<Dictionary<string, object>>(www.text);
  148. //If the response contains the key "status" with the value "ok" we know that we are connected
  149. if (returnParam != null && returnParam.ContainsKey("status") && returnParam["status"].ToString().Equals("ok"))
  150. {
  151. InternetConnectivity = true;
  152. }
  153. else
  154. {
  155. InternetConnectivity = false;
  156. }
  157. }
  158. }
  159. catch
  160. {
  161. InternetConnectivity = false;
  162. }
  163. }
  164. if (startQueue)
  165. {
  166. if (InternetConnectivity)
  167. GA.Log("GA initialized, waiting for events..");
  168. else
  169. GA.Log("GA detects no internet connection..");
  170. //Start the submit queue for sending messages to the server
  171. GA.RunCoroutine(GA_Queue.SubmitQueue());
  172. GA.Log("GameAnalytics: Submission queue started.");
  173. }
  174. }
  175. /// <summary>
  176. /// Sets a custom user ID.
  177. /// Make sure each user has a unique user ID. This is useful if you have your own log-in system with unique user IDs.
  178. /// NOTE: Only use this method if you have enabled "Custom User ID" on the GA inspector!
  179. /// </summary>
  180. /// <param name="customID">
  181. /// The custom user ID - this should be unique for each user
  182. /// </param>
  183. public void SetCustomUserID(string customID)
  184. {
  185. if (customID != string.Empty)
  186. {
  187. GA.API.GenericInfo.SetCustomUserID(customID);
  188. }
  189. }
  190. /// <summary>
  191. /// Sets a custom area string. An area is often just a level, but you can set it to whatever makes sense for your game. F.x. in a big open world game you will probably need custom areas to identify regions etc.
  192. /// By default, if no custom area is set, the Application.loadedLevelName string is used.
  193. /// </summary>
  194. /// <param name="customID">
  195. /// The custom area.
  196. /// </param>
  197. public void SetCustomArea(string customArea)
  198. {
  199. CustomArea = customArea;
  200. }
  201. #endregion
  202. }