| #if UNITY_ANALYTICS || UNITY_EDITOR |
| using System; |
| using System.Collections.Generic; |
| using UnityEngine.InputSystem.Layouts; |
| #if UNITY_EDITOR |
| using UnityEngine.InputSystem.Editor; |
| #endif |
|
|
| |
|
|
| namespace UnityEngine.InputSystem |
| { |
| internal static class InputAnalytics |
| { |
| public const string kEventStartup = "input_startup"; |
| public const string kEventShutdown = "input_shutdown"; |
|
|
| public static void Initialize(InputManager manager) |
| { |
| Debug.Assert(manager.m_Runtime != null); |
| } |
|
|
| public static void OnStartup(InputManager manager) |
| { |
| var data = new StartupEventData |
| { |
| version = InputSystem.version.ToString(), |
| }; |
|
|
| |
| var devices = manager.devices; |
| var deviceList = new List<StartupEventData.DeviceInfo>(); |
| for (var i = 0; i < devices.Count; ++i) |
| { |
| var device = devices[i]; |
|
|
| deviceList.Add( |
| StartupEventData.DeviceInfo.FromDescription(device.description, device.native, device.layout)); |
| } |
| data.devices = deviceList.ToArray(); |
|
|
| |
| deviceList.Clear(); |
| var availableDevices = manager.m_AvailableDevices; |
| var availableDeviceCount = manager.m_AvailableDeviceCount; |
| for (var i = 0; i < availableDeviceCount; ++i) |
| { |
| var deviceId = availableDevices[i].deviceId; |
| if (manager.TryGetDeviceById(deviceId) != null) |
| continue; |
|
|
| deviceList.Add(StartupEventData.DeviceInfo.FromDescription(availableDevices[i].description, |
| availableDevices[i].isNative)); |
| } |
|
|
| data.unrecognized_devices = deviceList.ToArray(); |
|
|
| #if UNITY_EDITOR |
| data.new_enabled = EditorPlayerSettingHelpers.newSystemBackendsEnabled; |
| data.old_enabled = EditorPlayerSettingHelpers.oldSystemBackendsEnabled; |
| #endif |
|
|
| manager.m_Runtime.RegisterAnalyticsEvent(kEventStartup, 10, 100); |
| manager.m_Runtime.SendAnalyticsEvent(kEventStartup, data); |
| } |
|
|
| public static void OnShutdown(InputManager manager) |
| { |
| var metrics = manager.metrics; |
| var data = new ShutdownEventData |
| { |
| max_num_devices = metrics.maxNumDevices, |
| max_state_size_in_bytes = metrics.maxStateSizeInBytes, |
| total_event_bytes = metrics.totalEventBytes, |
| total_event_count = metrics.totalEventCount, |
| total_frame_count = metrics.totalUpdateCount, |
| total_event_processing_time = (float)metrics.totalEventProcessingTime, |
| }; |
|
|
| manager.m_Runtime.RegisterAnalyticsEvent(kEventShutdown, 10, 100); |
| manager.m_Runtime.SendAnalyticsEvent(kEventShutdown, data); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| [Serializable] |
| public struct StartupEventData |
| { |
| public string version; |
| public DeviceInfo[] devices; |
| public DeviceInfo[] unrecognized_devices; |
|
|
| |
| #if UNITY_EDITOR |
| public bool new_enabled; |
| public bool old_enabled; |
| #endif |
|
|
| [Serializable] |
| public struct DeviceInfo |
| { |
| public string layout; |
| public string @interface; |
| public string product; |
| public bool native; |
|
|
| public static DeviceInfo FromDescription(InputDeviceDescription description, bool native = false, string layout = null) |
| { |
| string product; |
| if (!string.IsNullOrEmpty(description.product) && !string.IsNullOrEmpty(description.manufacturer)) |
| product = $"{description.manufacturer} {description.product}"; |
| else if (!string.IsNullOrEmpty(description.product)) |
| product = description.product; |
| else |
| product = description.manufacturer; |
|
|
| if (string.IsNullOrEmpty(layout)) |
| layout = description.deviceClass; |
|
|
| return new DeviceInfo |
| { |
| layout = layout, |
| @interface = description.interfaceName, |
| product = product, |
| native = native |
| }; |
| } |
| } |
| } |
|
|
| |
| |
| |
| [Serializable] |
| public struct FirstUserInteractionEventData |
| { |
| } |
|
|
| |
| |
| |
| [Serializable] |
| public struct ShutdownEventData |
| { |
| public int max_num_devices; |
| public int max_state_size_in_bytes; |
| public int total_event_bytes; |
| public int total_event_count; |
| public int total_frame_count; |
| public float total_event_processing_time; |
| } |
| } |
| } |
| #endif // UNITY_ANALYTICS || UNITY_EDITOR |
|
|