Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AdaptivePerformanceAnalyticsEvent.cs 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using UnityEngine.Analytics;
  2. namespace UnityEditor.AdaptivePerformance.Editor.Analytics
  3. {
  4. internal abstract class AdaptivePerformanceAnalyticsEvent<T> where T : struct
  5. {
  6. protected const int k_DefaultMaxEventsPerHour = 1000;
  7. protected const int k_DefaultMaxElementCount = 1000;
  8. /// <summary>
  9. /// The event name for an event determines which database table it goes into in the CDP backend.
  10. /// All events which we want grouped into a table must share the same event name.
  11. /// </summary>
  12. protected readonly string k_EventName;
  13. protected int m_MaxEventsPerHour;
  14. protected int m_MaxElementCount;
  15. /// <summary>
  16. /// <c>True</c> if the event is registered with Unity analytics API, otherwise <c>False</c>.
  17. /// </summary>
  18. bool m_Registered;
  19. protected AdaptivePerformanceAnalyticsEvent(string eventName,
  20. int maxEventsPerHour = k_DefaultMaxEventsPerHour, int maxElementCount = k_DefaultMaxElementCount)
  21. {
  22. k_EventName = eventName;
  23. m_MaxEventsPerHour = maxEventsPerHour;
  24. m_MaxElementCount = maxElementCount;
  25. }
  26. public bool Register()
  27. {
  28. if (m_Registered)
  29. return m_Registered;
  30. var result = RegisterWithAnalyticsServer();
  31. // AnalyticsResult.TooManyRequests means that we have already registered for this tableName
  32. if (result != AnalyticsResult.Ok && result != AnalyticsResult.TooManyRequests)
  33. m_Registered = false;
  34. else
  35. m_Registered = true;
  36. return m_Registered;
  37. }
  38. protected abstract AnalyticsResult RegisterWithAnalyticsServer();
  39. public bool Send(T eventArgs) => m_Registered && SendEvent(eventArgs);
  40. protected abstract bool SendEvent(T eventArgs);
  41. }
  42. }