forked from needle-mirror/com.unity.xr.management
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXRManagementAnalytics.cs
More file actions
89 lines (72 loc) · 2.66 KB
/
XRManagementAnalytics.cs
File metadata and controls
89 lines (72 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
#if UNITY_EDITOR
using UnityEditor;
#endif
#if UNITY_ANALYTICS && ENABLE_CLOUD_SERVICES_ANALYTICS
using UnityEngine.Analytics;
#endif //UNITY_ANALYTICS && ENABLE_CLOUD_SERVICES_ANALYTICS
[assembly:InternalsVisibleTo("Unity.XR.Management.Editor")]
namespace UnityEngine.XR.Management
{
internal static class XRManagementAnalytics
{
private const int kMaxEventsPerHour = 1000;
private const int kMaxNumberOfElements = 1000;
private const string kVendorKey = "unity.xrmanagement";
private const string kEventBuild = "xrmanagment_build";
#if ENABLE_CLOUD_SERVICES_ANALYTICS && UNITY_ANALYTICS
private static bool s_Initialized = false;
#endif //ENABLE_CLOUD_SERVICES_ANALYTICS && UNITY_ANALYTICS
[Serializable]
private struct BuildEvent
{
public string buildGuid;
public string buildTarget;
public string buildTargetGroup;
public string[] assigned_loaders;
}
private static bool Initialize()
{
#if ENABLE_TEST_SUPPORT || !ENABLE_CLOUD_SERVICES_ANALYTICS || !UNITY_ANALYTICS
return false;
#else
#if UNITY_EDITOR
if (!EditorAnalytics.enabled)
return false;
if(AnalyticsResult.Ok != EditorAnalytics.RegisterEventWithLimit(kEventBuild, kMaxEventsPerHour, kMaxNumberOfElements, kVendorKey))
return false;
s_Initialized = true;
#endif //UNITY_EDITOR
return s_Initialized;
#endif //ENABLE_TEST_SUPPORT || !ENABLE_CLOUD_SERVICES_ANALYTICS || !UNITY_ANALYTICS
}
#if UNITY_EDITOR
public static void SendBuildEvent(GUID guid, BuildTarget buildTarget, BuildTargetGroup buildTargetGroup, IEnumerable<XRLoader> loaders)
{
#if UNITY_ANALYTICS && ENABLE_CLOUD_SERVICES_ANALYTICS
if (!s_Initialized && !Initialize())
{
return;
}
List<string> loaderTypeNames = new List<string>();
foreach (var loader in loaders)
{
loaderTypeNames.Add(loader.GetType().Name);
}
var data = new BuildEvent
{
buildGuid = guid.ToString(),
buildTarget = buildTarget.ToString(),
buildTargetGroup = buildTargetGroup.ToString(),
assigned_loaders = loaderTypeNames.ToArray(),
};
EditorAnalytics.SendEventWithLimit(kEventBuild, data);
#endif //UNITY_ANALYTICS && ENABLE_CLOUD_SERVICES_ANALYTICS
}
#endif //UNITY_EDITOR
}
}