Skip to content

Commit b419900

Browse files
Merge branch 'develop' into isxb-483-touchsimulation-playerinput-fix
2 parents 3e5849a + 82ec624 commit b419900

18 files changed

+350
-31
lines changed

Assets/Tests/InputSystem/CoreTests_Analytics.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,55 @@ public void Analytics_ShouldReportPlayerInputManagerData()
663663
}
664664
}
665665

666+
[Test]
667+
[Category("Analytics")]
668+
public void Analytics_ShouldReportCodeAuthoringAnalytic()
669+
{
670+
CollectAnalytics(InputExitPlayModeAnalytic.kEventName);
671+
672+
// NOTE: We do not want to trigger entering/exiting play-mode for this small data-sanity check
673+
// so just stick to triggering it explicitly. A better test would have been an editor test
674+
// going in and out of play-mode for real but not clear if this is really possible.
675+
676+
// Pretend we are entering play-mode
677+
InputExitPlayModeAnalytic.OnPlayModeStateChange(PlayModeStateChange.ExitingEditMode);
678+
InputExitPlayModeAnalytic.OnPlayModeStateChange(PlayModeStateChange.EnteredPlayMode);
679+
680+
// Assert no data received
681+
Assert.That(sentAnalyticsEvents.Count, Is.EqualTo(0));
682+
683+
// Pretend we are exiting play-mode
684+
InputExitPlayModeAnalytic.OnPlayModeStateChange(PlayModeStateChange.ExitingPlayMode);
685+
InputExitPlayModeAnalytic.OnPlayModeStateChange(PlayModeStateChange.EnteredEditMode);
686+
687+
// Assert: Data received
688+
Assert.That(sentAnalyticsEvents.Count, Is.EqualTo(1));
689+
Assert.That(sentAnalyticsEvents[0].name, Is.EqualTo(InputExitPlayModeAnalytic.kEventName));
690+
Assert.That(sentAnalyticsEvents[0].data, Is.TypeOf<InputExitPlayModeAnalytic.Data>());
691+
692+
var data0 = (InputExitPlayModeAnalytic.Data)sentAnalyticsEvents[0].data;
693+
Assert.That(data0.uses_code_authoring, Is.False);
694+
695+
// Pretend we are entering play-mode
696+
InputExitPlayModeAnalytic.OnPlayModeStateChange(PlayModeStateChange.ExitingEditMode);
697+
InputExitPlayModeAnalytic.OnPlayModeStateChange(PlayModeStateChange.EnteredPlayMode);
698+
699+
var action = new InputAction("Dance");
700+
action.AddBinding("<Keyboard>/Space");
701+
702+
// Pretend we are exiting play-mode
703+
InputExitPlayModeAnalytic.OnPlayModeStateChange(PlayModeStateChange.ExitingPlayMode);
704+
InputExitPlayModeAnalytic.OnPlayModeStateChange(PlayModeStateChange.EnteredEditMode);
705+
706+
// Assert: Data received
707+
Assert.That(sentAnalyticsEvents.Count, Is.EqualTo(2));
708+
Assert.That(sentAnalyticsEvents[1].name, Is.EqualTo(InputExitPlayModeAnalytic.kEventName));
709+
Assert.That(sentAnalyticsEvents[1].data, Is.TypeOf<InputExitPlayModeAnalytic.Data>());
710+
711+
var data1 = (InputExitPlayModeAnalytic.Data)sentAnalyticsEvents[1].data;
712+
Assert.That(data1.uses_code_authoring, Is.True);
713+
}
714+
666715
#if UNITY_INPUT_SYSTEM_ENABLE_UI
667716
[Test]
668717
[Category("Analytics")]

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ however, it has to be formatted properly to pass verification tests.
1010

1111
## [Unreleased] - yyyy-mm-dd
1212

13+
### Added
14+
- Added the display of the device flag `CanRunInBackground` in device debug view.
15+
- Added analytics for programmatic `InputAction` setup via `InputActionSetupExtensions` when exiting play-mode.
16+
1317
## [1.11.1] - 2024-09-26
1418

1519
### Fixed

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,23 @@ public static BindingSyntax AddBinding(this InputAction action, string path, str
306306
});
307307
}
308308

309+
/// <summary>
310+
/// Conditionally compiled helper for logging API usage of code-authored actions.
311+
/// </summary>
312+
/// <param name="api">The associated API function.</param>
313+
/// <remarks>
314+
/// Be extremely carefully to review for indirect calls and overloads to not register analytics twice.
315+
/// Be extremely careful in enabling/disabling tracking before internal calls since those may otherwise
316+
/// be incorrectly registered.
317+
/// </remarks>
318+
#if UNITY_EDITOR
319+
private static void RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api api)
320+
{
321+
UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Register(api);
322+
}
323+
324+
#endif
325+
309326
/// <summary>
310327
/// Add a binding that references the given <paramref name="control"/> and triggers
311328
/// the given <paramref cref="action"/>.
@@ -349,6 +366,10 @@ public static BindingSyntax AddBinding(this InputAction action, InputControl con
349366
/// </remarks>
350367
public static BindingSyntax AddBinding(this InputAction action, InputBinding binding = default)
351368
{
369+
#if UNITY_EDITOR
370+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.AddBinding);
371+
#endif
372+
352373
if (action == null)
353374
throw new ArgumentNullException(nameof(action));
354375

@@ -478,6 +499,10 @@ public static BindingSyntax AddBinding(this InputActionMap actionMap, string pat
478499
/// <seealso cref="InputActionMap.bindings"/>
479500
public static BindingSyntax AddBinding(this InputActionMap actionMap, InputBinding binding)
480501
{
502+
#if UNITY_EDITOR
503+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.AddBinding);
504+
#endif
505+
481506
if (actionMap == null)
482507
throw new ArgumentNullException(nameof(actionMap));
483508
if (binding.path == null)
@@ -501,6 +526,10 @@ public static BindingSyntax AddBinding(this InputActionMap actionMap, InputBindi
501526
public static CompositeSyntax AddCompositeBinding(this InputAction action, string composite,
502527
string interactions = null, string processors = null)
503528
{
529+
#if UNITY_EDITOR
530+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.AddCompositeBinding);
531+
#endif
532+
504533
if (action == null)
505534
throw new ArgumentNullException(nameof(action));
506535
if (string.IsNullOrEmpty(composite))
@@ -580,6 +609,10 @@ private static int AddBindingInternal(InputActionMap map, InputBinding binding,
580609
/// of <paramref name="action"/>).</exception>
581610
public static BindingSyntax ChangeBinding(this InputAction action, int index)
582611
{
612+
#if UNITY_EDITOR
613+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.ChangeBinding);
614+
#endif
615+
583616
if (action == null)
584617
throw new ArgumentNullException(nameof(action));
585618

@@ -638,6 +671,10 @@ public static BindingSyntax ChangeBinding(this InputAction action, string name)
638671
/// of <paramref name="actionMap"/>).</exception>
639672
public static BindingSyntax ChangeBinding(this InputActionMap actionMap, int index)
640673
{
674+
#if UNITY_EDITOR
675+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.ChangeBinding);
676+
#endif
677+
641678
if (actionMap == null)
642679
throw new ArgumentNullException(nameof(actionMap));
643680
if (index < 0 || index >= actionMap.m_Bindings.LengthSafe())
@@ -836,6 +873,10 @@ public static BindingSyntax ChangeBinding(this InputAction action, InputBinding
836873
/// <seealso cref="InputBindingComposite"/>
837874
public static BindingSyntax ChangeCompositeBinding(this InputAction action, string compositeName)
838875
{
876+
#if UNITY_EDITOR
877+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.ChangeCompositeBinding);
878+
#endif
879+
839880
if (action == null)
840881
throw new ArgumentNullException(nameof(action));
841882
if (string.IsNullOrEmpty(compositeName))
@@ -877,6 +918,10 @@ public static BindingSyntax ChangeCompositeBinding(this InputAction action, stri
877918
/// </remarks>
878919
public static void Rename(this InputAction action, string newName)
879920
{
921+
#if UNITY_EDITOR
922+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.Rename);
923+
#endif
924+
880925
if (action == null)
881926
throw new ArgumentNullException(nameof(action));
882927
if (string.IsNullOrEmpty(newName))
@@ -919,6 +964,10 @@ public static void Rename(this InputAction action, string newName)
919964
/// </remarks>
920965
public static void AddControlScheme(this InputActionAsset asset, InputControlScheme controlScheme)
921966
{
967+
#if UNITY_EDITOR
968+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.AddControlScheme);
969+
#endif
970+
922971
if (asset == null)
923972
throw new ArgumentNullException(nameof(asset));
924973
if (string.IsNullOrEmpty(controlScheme.name))
@@ -987,6 +1036,10 @@ public static ControlSchemeSyntax AddControlScheme(this InputActionAsset asset,
9871036
/// </remarks>
9881037
public static void RemoveControlScheme(this InputActionAsset asset, string name)
9891038
{
1039+
#if UNITY_EDITOR
1040+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.RemoveControlScheme);
1041+
#endif
1042+
9901043
if (asset == null)
9911044
throw new ArgumentNullException(nameof(asset));
9921045
if (string.IsNullOrEmpty(name))
@@ -1007,33 +1060,57 @@ public static void RemoveControlScheme(this InputActionAsset asset, string name)
10071060
/// <returns><paramref name="scheme"/></returns>
10081061
public static InputControlScheme WithBindingGroup(this InputControlScheme scheme, string bindingGroup)
10091062
{
1063+
#if UNITY_EDITOR
1064+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.ControlSchemeWithBindingGroup);
1065+
#endif
1066+
10101067
return new ControlSchemeSyntax(scheme).WithBindingGroup(bindingGroup).Done();
10111068
}
10121069

10131070
public static InputControlScheme WithDevice(this InputControlScheme scheme, string controlPath, bool required)
10141071
{
1072+
#if UNITY_EDITOR
1073+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.ControlSchemeWithDevice);
1074+
#endif
1075+
10151076
if (required)
10161077
return new ControlSchemeSyntax(scheme).WithRequiredDevice(controlPath).Done();
10171078
return new ControlSchemeSyntax(scheme).WithOptionalDevice(controlPath).Done();
10181079
}
10191080

10201081
public static InputControlScheme WithRequiredDevice(this InputControlScheme scheme, string controlPath)
10211082
{
1083+
#if UNITY_EDITOR
1084+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.ControlSchemeWithRequiredDevice);
1085+
#endif
1086+
10221087
return new ControlSchemeSyntax(scheme).WithRequiredDevice(controlPath).Done();
10231088
}
10241089

10251090
public static InputControlScheme WithOptionalDevice(this InputControlScheme scheme, string controlPath)
10261091
{
1092+
#if UNITY_EDITOR
1093+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.ControlSchemeWithOptionalDevice);
1094+
#endif
1095+
10271096
return new ControlSchemeSyntax(scheme).WithOptionalDevice(controlPath).Done();
10281097
}
10291098

10301099
public static InputControlScheme OrWithRequiredDevice(this InputControlScheme scheme, string controlPath)
10311100
{
1101+
#if UNITY_EDITOR
1102+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.ControlSchemeOrWithRequiredDevice);
1103+
#endif
1104+
10321105
return new ControlSchemeSyntax(scheme).OrWithRequiredDevice(controlPath).Done();
10331106
}
10341107

10351108
public static InputControlScheme OrWithOptionalDevice(this InputControlScheme scheme, string controlPath)
10361109
{
1110+
#if UNITY_EDITOR
1111+
RegisterApiUsage(UnityEngine.InputSystem.Editor.InputExitPlayModeAnalytic.Api.ControlSchemeOrWithOptionalDevice);
1112+
#endif
1113+
10371114
return new ControlSchemeSyntax(scheme).OrWithOptionalDevice(controlPath).Done();
10381115
}
10391116

Packages/com.unity.inputsystem/InputSystem/Devices/InputDevice.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ public bool canRunInBackground
255255
return !(this is Pointer || this is Keyboard); // Anything but pointers and keyboards considered as being able to run in background.
256256
#endif
257257

258+
return canDeviceRunInBackground;
259+
}
260+
}
261+
/// <summary>
262+
/// In editor, it may differ from canRunInBackground depending on the gameViewFocus setting.
263+
/// This property is used by Device Debug View
264+
/// </summary>
265+
/// <value>Whether the device should generate input while in the background.</value>
266+
internal bool canDeviceRunInBackground
267+
{
268+
get
269+
{
258270
if ((m_DeviceFlags & DeviceFlags.CanRunInBackgroundHasBeenQueried) != 0)
259271
return (m_DeviceFlags & DeviceFlags.CanRunInBackground) != 0;
260272

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void End()
178178

179179
#region IInputAnalytic Interface
180180

181-
#if UNITY_EDITOR && UNITY_2023_2_OR_NEWER
181+
#if UNITY_2023_2_OR_NEWER
182182
public bool TryGatherData(out UnityEngine.Analytics.IAnalytic.IData data, out Exception error)
183183
#else
184184
public bool TryGatherData(out InputAnalytics.IInputAnalyticData data, out Exception error)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public InputBuildAnalytic(BuildReport buildReport)
3131
public InputAnalytics.InputAnalyticInfo info =>
3232
new InputAnalytics.InputAnalyticInfo(kEventName, kMaxEventsPerHour, kMaxNumberOfElements);
3333

34-
#if UNITY_EDITOR && UNITY_2023_2_OR_NEWER
34+
#if UNITY_2023_2_OR_NEWER
3535
public bool TryGatherData(out UnityEngine.Analytics.IAnalytic.IData data, out Exception error)
3636
#else
3737
public bool TryGatherData(out InputAnalytics.IInputAnalyticData data, out Exception error)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public InputComponentEditorAnalytic(InputSystemComponent component)
7272
m_Component = component;
7373
}
7474

75-
#if UNITY_EDITOR && UNITY_2023_2_OR_NEWER
75+
#if UNITY_2023_2_OR_NEWER
7676
public bool TryGatherData(out UnityEngine.Analytics.IAnalytic.IData data, out Exception error)
7777
#else
7878
public bool TryGatherData(out InputAnalytics.IInputAnalyticData data, out Exception error)
@@ -86,4 +86,4 @@ public bool TryGatherData(out InputAnalytics.IInputAnalyticData data, out Except
8686
public InputAnalytics.InputAnalyticInfo info { get; }
8787
}
8888
}
89-
#endif
89+
#endif // UNITY_EDITOR

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace UnityEngine.InputSystem.Editor
66
{
7-
internal static partial class InputEditorAnalytics
7+
internal static class InputEditorAnalytics
88
{
99
/// <summary>
1010
/// Represents notification behavior setting associated with <see cref="PlayerInput"/> and

0 commit comments

Comments
 (0)