PageRenderTime 81ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/AgentCodeMonkey/gameframework-unity-project
C# | 90 lines | 56 code | 16 blank | 18 comment | 14 complexity | ec836d650ede2c3a644f3d5ab4e348f1 MD5 | raw file
  1. /// <summary>
  2. /// This class handles error and exception messages, and makes sure they are added to the Quality category
  3. /// </summary>
  4. using UnityEngine;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Text;
  8. public class GA_Debug
  9. {
  10. public bool SubmitErrors;
  11. public int MaxErrorCount;
  12. public bool SubmitErrorStackTrace;
  13. public bool SubmitErrorSystemInfo;
  14. private int _errorCount = 0;
  15. private bool _showLogOnGUI = true;
  16. public List<string> Messages;
  17. /// <summary>
  18. /// If SubmitErrors is enabled on the GA object this makes sure that any exceptions or errors are submitted to the GA server
  19. /// </summary>
  20. /// <param name="logString">
  21. /// The message <see cref="System.String"/>
  22. /// </param>
  23. /// <param name="stackTrace">
  24. /// The exception stack trace <see cref="System.String"/>
  25. /// </param>
  26. /// <param name="type">
  27. /// The type of the log message (we only submit errors and exceptions to the GA server) <see cref="LogType"/>
  28. /// </param>
  29. public void HandleLog(string logString, string stackTrace, LogType type)
  30. {
  31. //Only used if the GA_DebugGUI script is added to the GA object (for testing)
  32. if (_showLogOnGUI)
  33. {
  34. if (Messages == null)
  35. {
  36. Messages = new List<string>();
  37. }
  38. Messages.Add(logString);
  39. }
  40. //We only submit exceptions and errors
  41. if (SubmitErrors && _errorCount < MaxErrorCount && (type == LogType.Exception || type == LogType.Error))
  42. {
  43. // Might be worth looking into: http://www.doogal.co.uk/exception.php
  44. _errorCount++;
  45. bool errorSubmitted = false;
  46. string eventID = "Exception";
  47. if (SubmitErrorStackTrace)
  48. {
  49. SubmitError(eventID, logString + " " + stackTrace);
  50. errorSubmitted = true;
  51. }
  52. if (SubmitErrorSystemInfo)
  53. {
  54. List<Dictionary<string, object>> systemspecs = GA.API.GenericInfo.GetGenericInfo(eventID);
  55. foreach (Dictionary<string, object> spec in systemspecs)
  56. {
  57. GA_Queue.AddItem(spec, GA_Submit.CategoryType.GA_Log, false);
  58. }
  59. errorSubmitted = true;
  60. }
  61. if (!errorSubmitted)
  62. {
  63. SubmitError(eventID, null);
  64. }
  65. }
  66. }
  67. public void SubmitError(string eventName, string message)
  68. {
  69. Vector3 target = Vector3.zero;
  70. if (GA.Settings.TrackTarget != null)
  71. target = GA.Settings.TrackTarget.position;
  72. GA.API.Quality.NewErrorEvent(eventName, message, target.x, target.y, target.z);
  73. }
  74. }