暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TelemetryMetricEvent.cs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Diagnostics;
  3. namespace UnityEngine.Purchasing.Telemetry
  4. {
  5. class TelemetryMetricEvent : ITelemetryMetricEvent
  6. {
  7. readonly ITelemetryMetricsInstanceWrapper m_TelemetryMetricsInstanceWrapper;
  8. readonly TelemetryMetricTypes m_MetricType;
  9. readonly string m_MetricName;
  10. Stopwatch m_Stopwatch = new Stopwatch();
  11. internal TelemetryMetricEvent(ITelemetryMetricsInstanceWrapper telemetryMetricsInstanceWrapper, TelemetryMetricTypes metricType, string metricName)
  12. {
  13. m_TelemetryMetricsInstanceWrapper = telemetryMetricsInstanceWrapper;
  14. m_MetricType = metricType;
  15. m_MetricName = metricName;
  16. }
  17. public void StartMetric()
  18. {
  19. if (m_Stopwatch != null)
  20. {
  21. if (!m_Stopwatch.IsRunning)
  22. {
  23. m_Stopwatch.Start();
  24. }
  25. else
  26. {
  27. throw new IapTelemetryException("Metric was already started.");
  28. }
  29. }
  30. else
  31. {
  32. throw new IapTelemetryException("Metric was already sent.");
  33. }
  34. }
  35. public void StopAndSendMetric()
  36. {
  37. if (m_Stopwatch != null)
  38. {
  39. m_TelemetryMetricsInstanceWrapper?.SendMetric(m_MetricType, m_MetricName, m_Stopwatch.Elapsed.Seconds);
  40. m_Stopwatch = null;
  41. }
  42. else
  43. {
  44. throw new IapTelemetryException("Metric was already sent.");
  45. }
  46. }
  47. }
  48. }