Skip to content

Commit 3161712

Browse files
committed
Moved and renamed Analytics API enum to Runtime
1 parent fd127b7 commit 3161712

4 files changed

Lines changed: 47 additions & 66 deletions

File tree

Packages/com.unity.inputsystem/InputSystem/Editor/Analytics/InputExitPlayModeAnalytic.cs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,19 @@ internal class InputExitPlayModeAnalytic : UnityEngine.InputSystem.InputAnalytic
1616
public const int kMaxEventsPerHour = 100; // default: 1000
1717
public const int kMaxNumberOfElements = 100; // default: 1000
1818

19-
/// <summary>
20-
/// Enumeration type for code authoring APIs mapping to <see cref="InputActionSetupExtensions"/>.
21-
/// </summary>
22-
/// <remarks>
23-
/// This enumeration type may be added to, but NEVER changed, since it would break older data.
24-
/// </remarks>
25-
public enum Api
26-
{
27-
AddBinding = 0,
28-
AddCompositeBinding = 1,
29-
ChangeBinding = 2,
30-
ChangeCompositeBinding = 3,
31-
Rename = 4,
32-
AddControlScheme = 5,
33-
RemoveControlScheme = 6,
34-
ControlSchemeWithBindingGroup = 7,
35-
ControlSchemeWithDevice = 8,
36-
ControlSchemeWithRequiredDevice = 9,
37-
ControlSchemeWithOptionalDevice = 10,
38-
ControlSchemeOrWithRequiredDevice = 11,
39-
ControlSchemeOrWithOptionalDevice = 12
40-
}
41-
42-
private static readonly int[] m_Counters = new int[Enum.GetNames(typeof(Api)).Length];
19+
private static readonly int[] m_Counters = new int[Enum.GetNames(typeof(InputAnalytics.AuthoringApi)).Length];
4320

4421
/// <summary>
4522
/// Registers a call to the associated API.
4623
/// </summary>
47-
/// <param name="api">Enumeration identifying the API.</param>
48-
public static void Register(Api api)
24+
/// <param name="authoringApi">Enumeration identifying the API.</param>
25+
public static void Register(InputAnalytics.AuthoringApi authoringApi)
4926
{
5027
if (suppress)
5128
return;
5229

5330
// Note: Currently discards detailed information and only sets a boolean (aggregated) value.
54-
++m_Counters[(int)api];
31+
++m_Counters[(int)authoringApi];
5532
}
5633

5734
/// <summary>

Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemEditorInitializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ private static void SendEditorAnalytic(InputAnalytics.IInputAnalytic analytic)
119119

120120
#endregion
121121

122-
private static void RegisterSetupApiUsage(int api)
122+
private static void RegisterSetupApiUsage(InputAnalytics.AuthoringApi authoringApi)
123123
{
124-
InputExitPlayModeAnalytic.Register((InputExitPlayModeAnalytic.Api)api);
124+
InputExitPlayModeAnalytic.Register(authoringApi);
125125
}
126126

127127
private static void SuppressSetupAnalytics(bool suppress)

Packages/com.unity.inputsystem/InputSystem/Runtime/Actions/InputActionSetupExtensions.cs

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -325,32 +325,14 @@ public static BindingSyntax AddBinding(this InputAction action, string path, str
325325
/// </remarks>
326326

327327
// Internal hook for Editor to register analytics tracking
328-
internal static Action<int> s_ApiUsageCallback;
328+
internal static Action<InputAnalytics.AuthoringApi> s_ApiUsageCallback;
329329

330330
// Internal hook for Editor to suppress analytics
331331
internal static Action<bool> s_SuppressAnalytics;
332332

333-
// API constants for analytics (matches Editor InputExitPlayModeAnalytic.Api enum)
334-
internal enum Api
333+
private static void RegisterAnalyticsApi(InputAnalytics.AuthoringApi authoringApi)
335334
{
336-
AddBinding,
337-
AddCompositeBinding,
338-
ChangeBinding,
339-
ChangeCompositeBinding,
340-
Rename,
341-
AddControlScheme,
342-
RemoveControlScheme,
343-
ControlSchemeWithBindingGroup,
344-
ControlSchemeWithDevice,
345-
ControlSchemeWithRequiredDevice,
346-
ControlSchemeWithOptionalDevice,
347-
ControlSchemeOrWithRequiredDevice,
348-
ControlSchemeOrWithOptionalDevice
349-
}
350-
351-
private static void RegisterAnalyticsApi(int api)
352-
{
353-
s_ApiUsageCallback?.Invoke(api);
335+
s_ApiUsageCallback?.Invoke(authoringApi);
354336
}
355337

356338
/// <summary>
@@ -397,7 +379,7 @@ public static BindingSyntax AddBinding(this InputAction action, InputControl con
397379
public static BindingSyntax AddBinding(this InputAction action, InputBinding binding = default)
398380
{
399381
#if UNITY_EDITOR
400-
RegisterAnalyticsApi((int)Api.AddBinding);
382+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.AddBinding);
401383
#endif
402384

403385
if (action == null)
@@ -530,7 +512,7 @@ public static BindingSyntax AddBinding(this InputActionMap actionMap, string pat
530512
public static BindingSyntax AddBinding(this InputActionMap actionMap, InputBinding binding)
531513
{
532514
#if UNITY_EDITOR
533-
RegisterAnalyticsApi((int)Api.AddBinding);
515+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.AddBinding);
534516
#endif
535517

536518
if (actionMap == null)
@@ -557,7 +539,7 @@ public static CompositeSyntax AddCompositeBinding(this InputAction action, strin
557539
string interactions = null, string processors = null)
558540
{
559541
#if UNITY_EDITOR
560-
RegisterAnalyticsApi((int)Api.AddCompositeBinding);
542+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.AddCompositeBinding);
561543
#endif
562544

563545
if (action == null)
@@ -640,7 +622,7 @@ private static int AddBindingInternal(InputActionMap map, InputBinding binding,
640622
public static BindingSyntax ChangeBinding(this InputAction action, int index)
641623
{
642624
#if UNITY_EDITOR
643-
RegisterAnalyticsApi((int)Api.ChangeBinding);
625+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.ChangeBinding);
644626
#endif
645627

646628
if (action == null)
@@ -702,7 +684,7 @@ public static BindingSyntax ChangeBinding(this InputAction action, string name)
702684
public static BindingSyntax ChangeBinding(this InputActionMap actionMap, int index)
703685
{
704686
#if UNITY_EDITOR
705-
RegisterAnalyticsApi((int)Api.ChangeBinding);
687+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.ChangeBinding);
706688
#endif
707689

708690
if (actionMap == null)
@@ -904,7 +886,7 @@ public static BindingSyntax ChangeBinding(this InputAction action, InputBinding
904886
public static BindingSyntax ChangeCompositeBinding(this InputAction action, string compositeName)
905887
{
906888
#if UNITY_EDITOR
907-
RegisterAnalyticsApi((int)Api.ChangeCompositeBinding);
889+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.ChangeCompositeBinding);
908890
#endif
909891

910892
if (action == null)
@@ -949,7 +931,7 @@ public static BindingSyntax ChangeCompositeBinding(this InputAction action, stri
949931
public static void Rename(this InputAction action, string newName)
950932
{
951933
#if UNITY_EDITOR
952-
RegisterAnalyticsApi((int)Api.Rename);
934+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.Rename);
953935
#endif
954936

955937
if (action == null)
@@ -995,7 +977,7 @@ public static void Rename(this InputAction action, string newName)
995977
public static void AddControlScheme(this InputActionAsset asset, InputControlScheme controlScheme)
996978
{
997979
#if UNITY_EDITOR
998-
RegisterAnalyticsApi((int)Api.AddControlScheme);
980+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.AddControlScheme);
999981
#endif
1000982

1001983
if (asset == null)
@@ -1067,7 +1049,7 @@ public static ControlSchemeSyntax AddControlScheme(this InputActionAsset asset,
10671049
public static void RemoveControlScheme(this InputActionAsset asset, string name)
10681050
{
10691051
#if UNITY_EDITOR
1070-
RegisterAnalyticsApi((int)Api.RemoveControlScheme);
1052+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.RemoveControlScheme);
10711053
#endif
10721054

10731055
if (asset == null)
@@ -1091,7 +1073,7 @@ public static void RemoveControlScheme(this InputActionAsset asset, string name)
10911073
public static InputControlScheme WithBindingGroup(this InputControlScheme scheme, string bindingGroup)
10921074
{
10931075
#if UNITY_EDITOR
1094-
RegisterAnalyticsApi((int)Api.ControlSchemeWithBindingGroup);
1076+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.ControlSchemeWithBindingGroup);
10951077
#endif
10961078

10971079
return new ControlSchemeSyntax(scheme).WithBindingGroup(bindingGroup).Done();
@@ -1100,7 +1082,7 @@ public static InputControlScheme WithBindingGroup(this InputControlScheme scheme
11001082
public static InputControlScheme WithDevice(this InputControlScheme scheme, string controlPath, bool required)
11011083
{
11021084
#if UNITY_EDITOR
1103-
RegisterAnalyticsApi((int)Api.ControlSchemeWithDevice);
1085+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.ControlSchemeWithDevice);
11041086
#endif
11051087

11061088
if (required)
@@ -1111,7 +1093,7 @@ public static InputControlScheme WithDevice(this InputControlScheme scheme, stri
11111093
public static InputControlScheme WithRequiredDevice(this InputControlScheme scheme, string controlPath)
11121094
{
11131095
#if UNITY_EDITOR
1114-
RegisterAnalyticsApi((int)Api.ControlSchemeWithRequiredDevice);
1096+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.ControlSchemeWithRequiredDevice);
11151097
#endif
11161098

11171099
return new ControlSchemeSyntax(scheme).WithRequiredDevice(controlPath).Done();
@@ -1120,7 +1102,7 @@ public static InputControlScheme WithRequiredDevice(this InputControlScheme sche
11201102
public static InputControlScheme WithOptionalDevice(this InputControlScheme scheme, string controlPath)
11211103
{
11221104
#if UNITY_EDITOR
1123-
RegisterAnalyticsApi((int)Api.ControlSchemeWithOptionalDevice);
1105+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.ControlSchemeWithOptionalDevice);
11241106
#endif
11251107

11261108
return new ControlSchemeSyntax(scheme).WithOptionalDevice(controlPath).Done();
@@ -1129,7 +1111,7 @@ public static InputControlScheme WithOptionalDevice(this InputControlScheme sche
11291111
public static InputControlScheme OrWithRequiredDevice(this InputControlScheme scheme, string controlPath)
11301112
{
11311113
#if UNITY_EDITOR
1132-
RegisterAnalyticsApi((int)Api.ControlSchemeOrWithRequiredDevice);
1114+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.ControlSchemeOrWithRequiredDevice);
11331115
#endif
11341116

11351117
return new ControlSchemeSyntax(scheme).OrWithRequiredDevice(controlPath).Done();
@@ -1138,7 +1120,7 @@ public static InputControlScheme OrWithRequiredDevice(this InputControlScheme sc
11381120
public static InputControlScheme OrWithOptionalDevice(this InputControlScheme scheme, string controlPath)
11391121
{
11401122
#if UNITY_EDITOR
1141-
RegisterAnalyticsApi((int)Api.ControlSchemeOrWithOptionalDevice);
1123+
RegisterAnalyticsApi(InputAnalytics.AuthoringApi.ControlSchemeOrWithOptionalDevice);
11421124
#endif
11431125

11441126
return new ControlSchemeSyntax(scheme).OrWithOptionalDevice(controlPath).Done();

Packages/com.unity.inputsystem/InputSystem/Runtime/InputAnalytics.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,34 @@
66

77
namespace UnityEngine.InputSystem
88
{
9-
internal static class InputAnalytics
9+
internal static partial class InputAnalytics
1010
{
1111
public const string kVendorKey = "unity.input";
1212

1313
internal static Func<bool> IsNewSystemBackendsEnabled { get; set; }
1414
internal static Func<bool> IsOldSystemBackendsEnabled { get; set; }
15+
/// <summary>
16+
/// Code authoring APIs on <see cref="InputActionSetupExtensions"/> used for analytics.
17+
/// </summary>
18+
/// <remarks>
19+
/// This enumeration may be added to, but NEVER changed, since it would break older data.
20+
/// </remarks>
21+
internal enum AuthoringApi
22+
{
23+
AddBinding,
24+
AddCompositeBinding,
25+
ChangeBinding,
26+
ChangeCompositeBinding,
27+
Rename,
28+
AddControlScheme,
29+
RemoveControlScheme,
30+
ControlSchemeWithBindingGroup,
31+
ControlSchemeWithDevice,
32+
ControlSchemeWithRequiredDevice,
33+
ControlSchemeWithOptionalDevice,
34+
ControlSchemeOrWithRequiredDevice,
35+
ControlSchemeOrWithOptionalDevice
36+
}
1537

1638
// Struct similar to AnalyticInfo for simplifying usage.
1739
public struct InputAnalyticInfo

0 commit comments

Comments
 (0)