Renderer2DAnalytics.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Analytics;
  4. using UnityEngine.Experimental.Rendering.Universal;
  5. namespace UnityEditor.Experimental.Rendering.Universal.Analytics
  6. {
  7. struct AnalyticsDataTypes
  8. {
  9. public const string k_LightDataString = "u2drendererlights";
  10. public const string k_Renderer2DDataString = "u2drendererdata";
  11. }
  12. internal interface IAnalyticsData { };
  13. [Serializable]
  14. internal struct Light2DData : IAnalyticsData
  15. {
  16. [SerializeField]
  17. public bool was_create_event;
  18. [SerializeField]
  19. public int instance_id;
  20. [SerializeField]
  21. public Light2D.LightType light_type;
  22. };
  23. [Serializable]
  24. internal struct RendererAssetData : IAnalyticsData
  25. {
  26. [SerializeField]
  27. public bool was_create_event;
  28. [SerializeField]
  29. public int instance_id;
  30. [SerializeField]
  31. public int blending_layers_count;
  32. [SerializeField]
  33. public int blending_modes_used;
  34. }
  35. interface IAnalytics
  36. {
  37. AnalyticsResult SendData(string eventString, IAnalyticsData data);
  38. }
  39. [InitializeOnLoad]
  40. internal class Renderer2DAnalytics : IAnalytics
  41. {
  42. const int k_MaxEventsPerHour = 1000;
  43. const int k_MaxNumberOfElements = 1000;
  44. const string k_VendorKey = "unity.renderpipelines.universal.editor";
  45. const int k_Version = 1;
  46. static Renderer2DAnalytics m_Instance = new Renderer2DAnalytics();
  47. static bool s_Initialize = false;
  48. public static Renderer2DAnalytics instance
  49. {
  50. get
  51. {
  52. if (m_Instance == null)
  53. m_Instance = new Renderer2DAnalytics();
  54. return m_Instance;
  55. }
  56. }
  57. public AnalyticsResult SendData(string eventString, IAnalyticsData data)
  58. {
  59. //Debug.Log("Sent Data " + JsonUtility.ToJson(data));
  60. if (false == s_Initialize)
  61. {
  62. EditorAnalytics.RegisterEventWithLimit(AnalyticsDataTypes.k_LightDataString, k_MaxEventsPerHour, k_MaxNumberOfElements, k_VendorKey, k_Version);
  63. EditorAnalytics.RegisterEventWithLimit(AnalyticsDataTypes.k_Renderer2DDataString, k_MaxEventsPerHour, k_MaxNumberOfElements, k_VendorKey, k_Version);
  64. s_Initialize = true;
  65. }
  66. return EditorAnalytics.SendEventWithLimit(eventString, data, k_Version);
  67. }
  68. }
  69. }