2026-10-21 20:45:23 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
#endif
|
|
|
|
|
#if UNITY_ANALYTICS && ENABLE_CLOUD_SERVICES_ANALYTICS
|
|
|
|
|
using UnityEngine.Analytics;
|
2026-11-30 19:13:17 +00:00
|
|
|
#endif
|
2026-10-21 20:45:23 +01:00
|
|
|
|
|
|
|
|
[assembly:InternalsVisibleTo("Unity.XR.Management.Editor")]
|
|
|
|
|
namespace UnityEngine.XR.Management
|
|
|
|
|
{
|
2026-11-30 19:13:17 +00:00
|
|
|
static class XRManagementAnalytics
|
2026-10-21 20:45:23 +01:00
|
|
|
{
|
2026-11-30 19:13:17 +00:00
|
|
|
const int k_MaxEventsPerHour = 1000;
|
|
|
|
|
const int k_MaxNumberOfElements = 1000;
|
|
|
|
|
const string k_VendorKey = "unity.xrmanagement";
|
|
|
|
|
const string k_EventBuild = "xrmanagment_build";
|
2026-10-21 20:45:23 +01:00
|
|
|
|
|
|
|
|
#if ENABLE_CLOUD_SERVICES_ANALYTICS && UNITY_ANALYTICS
|
2026-11-30 19:13:17 +00:00
|
|
|
static bool s_Initialized = false;
|
2026-10-21 20:45:23 +01:00
|
|
|
#endif //ENABLE_CLOUD_SERVICES_ANALYTICS && UNITY_ANALYTICS
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
2026-11-30 19:13:17 +00:00
|
|
|
struct BuildEvent
|
2026-10-21 20:45:23 +01:00
|
|
|
#if UNITY_2023_2_OR_NEWER && ENABLE_CLOUD_SERVICES_ANALYTICS && UNITY_ANALYTICS
|
|
|
|
|
: IAnalytic.IData
|
|
|
|
|
#endif //UNITY_2023_2_OR_NEWER && ENABLE_CLOUD_SERVICES_ANALYTICS && UNITY_ANALYTICS
|
|
|
|
|
{
|
|
|
|
|
public string buildGuid;
|
|
|
|
|
public string buildTarget;
|
|
|
|
|
public string buildTargetGroup;
|
|
|
|
|
public string[] assigned_loaders;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if UNITY_2023_2_OR_NEWER && ENABLE_CLOUD_SERVICES_ANALYTICS && UNITY_ANALYTICS
|
2026-11-30 19:13:17 +00:00
|
|
|
[AnalyticInfo(
|
|
|
|
|
eventName: k_EventBuild,
|
|
|
|
|
vendorKey: k_VendorKey,
|
|
|
|
|
maxEventsPerHour: k_MaxEventsPerHour,
|
|
|
|
|
maxNumberOfElements: k_MaxNumberOfElements)]
|
|
|
|
|
class XrInitializeAnalytic : IAnalytic
|
2026-10-21 20:45:23 +01:00
|
|
|
{
|
2026-11-30 19:13:17 +00:00
|
|
|
BuildEvent? m_Data;
|
2026-10-21 20:45:23 +01:00
|
|
|
|
|
|
|
|
public XrInitializeAnalytic(BuildEvent data)
|
|
|
|
|
{
|
2026-11-30 19:13:17 +00:00
|
|
|
m_Data = data;
|
2026-10-21 20:45:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool TryGatherData(out IAnalytic.IData data, [NotNullWhen(false)] out Exception error)
|
|
|
|
|
{
|
|
|
|
|
error = null;
|
2026-11-30 19:13:17 +00:00
|
|
|
data = m_Data;
|
2026-10-21 20:45:23 +01:00
|
|
|
return data != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif //UNITY_2023_2_OR_NEWER && ENABLE_CLOUD_SERVICES_ANALYTICS && UNITY_ANALYTICS
|
|
|
|
|
|
2026-11-30 19:13:17 +00:00
|
|
|
static bool Initialize()
|
2026-10-21 20:45:23 +01:00
|
|
|
{
|
|
|
|
|
#if ENABLE_TEST_SUPPORT || !ENABLE_CLOUD_SERVICES_ANALYTICS || !UNITY_ANALYTICS
|
|
|
|
|
return false;
|
|
|
|
|
#elif UNITY_EDITOR && UNITY_2023_2_OR_NEWER
|
|
|
|
|
return EditorAnalytics.enabled;
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
if (!EditorAnalytics.enabled)
|
|
|
|
|
return false;
|
|
|
|
|
|
2026-11-30 19:13:17 +00:00
|
|
|
if(AnalyticsResult.Ok != EditorAnalytics.RegisterEventWithLimit(k_EventBuild, k_MaxEventsPerHour, k_MaxNumberOfElements, k_VendorKey))
|
2026-10-21 20:45:23 +01:00
|
|
|
return false;
|
|
|
|
|
s_Initialized = true;
|
|
|
|
|
#endif //UNITY_EDITOR
|
|
|
|
|
return s_Initialized;
|
|
|
|
|
#endif //ENABLE_TEST_SUPPORT || !ENABLE_CLOUD_SERVICES_ANALYTICS || !UNITY_ANALYTICS
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
2026-11-30 19:13:17 +00:00
|
|
|
public static void SendBuildEvent(
|
|
|
|
|
GUID guid, BuildTarget buildTarget, BuildTargetGroup buildTargetGroup, IEnumerable<XRLoader> loaders)
|
2026-10-21 20:45:23 +01:00
|
|
|
{
|
|
|
|
|
#if UNITY_ANALYTICS && ENABLE_CLOUD_SERVICES_ANALYTICS
|
|
|
|
|
if (!s_Initialized && !Initialize())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-30 19:13:17 +00:00
|
|
|
var loaderTypeNames = new List<string>();
|
2026-10-21 20:45:23 +01:00
|
|
|
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(),
|
|
|
|
|
};
|
|
|
|
|
#if UNITY_2023_2_OR_NEWER
|
|
|
|
|
EditorAnalytics.SendAnalytic(new XrInitializeAnalytic(data));
|
|
|
|
|
#else
|
2026-11-30 19:13:17 +00:00
|
|
|
EditorAnalytics.SendEventWithLimit(k_EventBuild, data);
|
2026-10-21 20:45:23 +01:00
|
|
|
#endif //UNITY_2023_2_OR_NEWER
|
|
|
|
|
#endif //UNITY_ANALYTICS && ENABLE_CLOUD_SERVICES_ANALYTICS
|
|
|
|
|
}
|
|
|
|
|
#endif //UNITY_EDITOR
|
|
|
|
|
}
|
|
|
|
|
}
|