Skip to content

Commit 97438f1

Browse files
committed
Merge Upstream-Develop
2 parents a61bb93 + 66ac221 commit 97438f1

File tree

68 files changed

+817
-183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+817
-183
lines changed

Assets/Samples/Visualizers/InputControlVisualizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private static void OnEvent(InputEventPtr eventPtr, InputDevice device)
281281
for (var i = 0; i < s_EnabledInstances.Count; ++i)
282282
{
283283
var component = s_EnabledInstances[i];
284-
if (component.m_Control.device != device || component.m_Visualizer == null)
284+
if (component.m_Control?.device != device || component.m_Visualizer == null)
285285
continue;
286286

287287
component.OnEventImpl(eventPtr);

Assets/Tests/InputSystem/APIVerificationTests.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,16 @@ public void API_MethodReturnTypesAreNotIntPtr()
138138

139139
[Test]
140140
[Category("API")]
141-
public void API_ControlTypesHavePreserveAttribute()
141+
[TestCase(typeof(InputControl))]
142+
[TestCase(typeof(IInputInteraction))]
143+
[TestCase(typeof(InputBindingComposite))]
144+
[TestCase(typeof(InputProcessor))]
145+
public void API_TypesCreatedByReflectionHavePreserveAttribute(Type type)
142146
{
143-
var controlType = typeof(InputControl);
144-
var controlTypes = controlType.Assembly.GetTypes().Where(t => controlType.IsAssignableFrom(t));
145-
Assert.That(controlTypes, Is.Not.Empty);
146-
var controlTypesWithoutPreserveAttribute = controlTypes.Where(t => !t.CustomAttributes.Any(a => a.AttributeType.Name.Contains("PreserveAttribute")));
147-
Assert.That(controlTypesWithoutPreserveAttribute, Is.Empty);
147+
var types = type.Assembly.GetTypes().Where(t => type.IsAssignableFrom(t)).Concat(typeof(APIVerificationTests).Assembly.GetTypes().Where(t => type.IsAssignableFrom(t)));
148+
Assert.That(types, Is.Not.Empty);
149+
var typesWithoutPreserveAttribute = types.Where(t => !t.CustomAttributes.Any(a => a.AttributeType.Name.Contains("PreserveAttribute")));
150+
Assert.That(typesWithoutPreserveAttribute, Is.Empty);
148151
}
149152

150153
[Test]

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text.RegularExpressions;
66
using NUnit.Framework;
77
using UnityEngine;
8+
using UnityEngine.Scripting;
89
using UnityEngine.InputSystem;
910
using UnityEngine.InputSystem.Composites;
1011
using UnityEngine.InputSystem.Controls;
@@ -1389,8 +1390,16 @@ public void Actions_WithMultipleBoundControls_DriveInteractionsFromControlWithGr
13891390
// binding makes that order dependent on the order of controls in Gamepad.
13901391
//
13911392
// So in effect, we get a sequence of Performed calls here that is a little surprising.
1393+
//
1394+
// However, it also turns out that our stripping code may not keep the order of controls when rewriting the
1395+
// updated assemblies, which makes this test indeterministic in players. So we test for the specific callbacks
1396+
// only in the editor. In players, we just make sure that the first and last callbacks match our expectations.
13921397
actions = trace.ToArray();
1398+
1399+
#if UNITY_EDITOR
13931400
Assert.That(actions, Has.Length.EqualTo(5));
1401+
#endif
1402+
13941403
Assert.That(actions[0].phase, Is.EqualTo(InputActionPhase.Started));
13951404
Assert.That(actions[0].control, Is.SameAs(gamepad.buttonSouth));
13961405
Assert.That(actions[0].action, Is.SameAs(buttonAction));
@@ -1399,21 +1408,25 @@ public void Actions_WithMultipleBoundControls_DriveInteractionsFromControlWithGr
13991408
Assert.That(actions[1].control, Is.SameAs(gamepad.buttonSouth));
14001409
Assert.That(actions[1].action, Is.SameAs(buttonAction));
14011410
Assert.That(actions[1].ReadValue<float>(), Is.EqualTo(1).Within(0.00001));
1411+
1412+
#if UNITY_EDITOR
14021413
Assert.That(actions[2].phase, Is.EqualTo(InputActionPhase.Performed));
14031414
Assert.That(actions[2].control, Is.SameAs(gamepad.buttonWest)); // Control immediately following buttonSouth in list of controls.
14041415
Assert.That(actions[2].action, Is.SameAs(buttonAction));
14051416
Assert.That(actions[2].ReadValue<float>(), Is.EqualTo(1).Within(0.00001));
1406-
Assert.That(actions[3].phase, Is.EqualTo(InputActionPhase.Performed)); // Control following buttonWest in list of controls.
1407-
Assert.That(actions[3].control, Is.SameAs(gamepad.buttonNorth));
1408-
Assert.That(actions[3].action, Is.SameAs(buttonAction));
1409-
Assert.That(actions[3].ReadValue<float>(), Is.EqualTo(1).Within(0.00001));
1410-
Assert.That(actions[4].phase, Is.EqualTo(InputActionPhase.Canceled));
1411-
Assert.That(actions[4].control, Is.SameAs(gamepad.buttonNorth));
1412-
Assert.That(actions[4].action, Is.SameAs(buttonAction));
1413-
Assert.That(actions[4].ReadValue<float>(), Is.Zero.Within(0.00001));
1417+
#endif
1418+
1419+
Assert.That(actions[actions.Length - 2].phase, Is.EqualTo(InputActionPhase.Performed)); // Last control to be actuated.
1420+
Assert.That(actions[actions.Length - 2].control, Is.SameAs(gamepad.buttonNorth));
1421+
Assert.That(actions[actions.Length - 2].action, Is.SameAs(buttonAction));
1422+
Assert.That(actions[actions.Length - 2].ReadValue<float>(), Is.EqualTo(1).Within(0.00001));
1423+
Assert.That(actions[actions.Length - 1].control, Is.SameAs(gamepad.buttonNorth));
1424+
Assert.That(actions[actions.Length - 1].action, Is.SameAs(buttonAction));
1425+
Assert.That(actions[actions.Length - 1].ReadValue<float>(), Is.Zero.Within(0.00001));
14141426
}
14151427
}
14161428

1429+
[Preserve]
14171430
private class ReleaseOnlyTestInteraction : IInputInteraction<float>
14181431
{
14191432
private bool m_WaitingForRelease;
@@ -2688,6 +2701,7 @@ public void Actions_IncompatibleProcessorIsIgnored()
26882701
}
26892702

26902703
// ReSharper disable once ClassNeverInstantiated.Local
2704+
[Preserve]
26912705
private class ConstantVector2TestProcessor : InputProcessor<Vector2>
26922706
{
26932707
public override Vector2 Process(Vector2 value, InputControl<Vector2> control)
@@ -2876,6 +2890,7 @@ public void Actions_CanFindEnabledActions()
28762890
}
28772891

28782892
// ReSharper disable once ClassNeverInstantiated.Local
2893+
[Preserve]
28792894
private class TestInteraction : IInputInteraction
28802895
{
28812896
#pragma warning disable CS0649
@@ -4266,6 +4281,7 @@ public void Actions_RegisteringExistingCompositeUnderNewName_CreatesAlias()
42664281
#endif // UNITY_EDITOR
42674282

42684283
#pragma warning disable CS0649
4284+
[Preserve]
42694285
private class CompositeWithParameters : InputBindingComposite<float>
42704286
{
42714287
public int intParameter;
@@ -4685,6 +4701,7 @@ public void Actions_CanCreateComposite_WithPartsBeingOutOfOrder()
46854701
}
46864702
}
46874703

4704+
[Preserve]
46884705
private class LogInteraction : IInputInteraction
46894706
{
46904707
public void Process(ref InputInteractionContext context)
@@ -5008,6 +5025,7 @@ public void Actions_CompositesReportControlThatTriggeredTheCompositeInCallback()
50085025
LogAssert.NoUnexpectedReceived();
50095026
}
50105027

5028+
[Preserve]
50115029
private class CompositeWithVector2Part : InputBindingComposite<Vector2>
50125030
{
50135031
[InputControlAttribute(layout = "Vector2")]
@@ -5041,6 +5059,7 @@ public void Actions_CanCreateCompositeWithVector2PartBinding()
50415059
}
50425060
}
50435061

5062+
[Preserve]
50445063
private class CompositeAskingForSourceControl : InputBindingComposite<float>
50455064
{
50465065
[InputControl(layout = "Button")]
@@ -5818,6 +5837,7 @@ public void Actions_ExceptionsInCallbacksAreCaughtAndLogged()
58185837
LogAssert.NoUnexpectedReceived();
58195838
}
58205839

5840+
[Preserve]
58215841
class TestInteractionCheckingDefaultState : IInputInteraction
58225842
{
58235843
public void Process(ref InputInteractionContext context)

Assets/Tests/InputSystem/CoreTests_Controls.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ public void Controls_CanTurnControlPathIntoHumanReadableText()
10111011
Assert.That(InputControlPath.ToHumanReadableString("*/{PrimaryMotion}/x"), Is.EqualTo("PrimaryMotion/x [Any]"));
10121012
Assert.That(InputControlPath.ToHumanReadableString("<Gamepad>/buttonSouth"), Is.EqualTo("Button South [Gamepad]"));
10131013
Assert.That(InputControlPath.ToHumanReadableString("<XInputController>/buttonSouth"), Is.EqualTo("A [Xbox Controller]"));
1014+
Assert.That(InputControlPath.ToHumanReadableString("<Touchscreen>/touch4/tap"), Is.EqualTo("Touch #4/Tap [Touchscreen]"));
10141015

10151016
Assert.That(
10161017
InputControlPath.ToHumanReadableString("<Gamepad>/buttonSouth",

Assets/Tests/InputSystem/CoreTests_Devices.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using UnityEngine.InputSystem.DualShock;
1414
using UnityEngine.InputSystem.Utilities;
1515
using UnityEngine.Profiling;
16+
using UnityEngine.Scripting;
1617
using UnityEngine.TestTools;
1718
using UnityEngine.TestTools.Utils;
1819
using Gyroscope = UnityEngine.InputSystem.Gyroscope;
@@ -542,6 +543,7 @@ public void Devices_RemovingLastDeviceThatUsesBeforeRenderUpdates_CausesBeforeRe
542543
Assert.That(InputSystem.s_Manager.updateMask & InputUpdateType.BeforeRender, Is.EqualTo((InputUpdateType)0));
543544
}
544545

546+
[Preserve]
545547
private class TestDeviceReceivingAddAndRemoveNotification : Mouse
546548
{
547549
public int addedCount;
@@ -942,6 +944,7 @@ public void Devices_ChangingStateOfDevice_TriggersNotification()
942944
Assert.That(receivedEventPtr.IsA<StateEvent>(), Is.True);
943945
}
944946

947+
[Preserve]
945948
private class TestDeviceThatResetsStateInCallback : InputDevice, IInputStateCallbackReceiver
946949
{
947950
[InputControl(format = "FLT")]
@@ -1029,6 +1032,7 @@ private unsafe struct TestDeviceFullState : IInputStateTypeInfo
10291032
}
10301033

10311034
[InputControlLayout(stateType = typeof(TestDeviceFullState))]
1035+
[Preserve]
10321036
private class TestDeviceIntegratingStateItself : InputDevice, IInputStateCallbackReceiver
10331037
{
10341038
public void OnNextUpdate()

Assets/Tests/InputSystem/CoreTests_Editor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.CodeDom.Compiler;
88
using NUnit.Framework;
99
using UnityEditor;
10+
using UnityEngine.Scripting;
1011
using UnityEditor.IMGUI.Controls;
1112
using UnityEngine;
1213
using UnityEngine.InputSystem;
@@ -1923,6 +1924,7 @@ public void Editor_CanGetValueTypeOfProcessor()
19231924
Assert.That(InputProcessor.GetValueTypeFromType(typeof(ScaleProcessor)), Is.SameAs(typeof(float)));
19241925
}
19251926

1927+
[Preserve]
19261928
private class TestInteractionWithValueType : IInputInteraction<float>
19271929
{
19281930
public void Process(ref InputInteractionContext context)

Assets/Tests/InputSystem/CoreTests_Events.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using NUnit.Framework;
66
using Unity.Collections.LowLevel.Unsafe;
77
using UnityEngine;
8+
using UnityEngine.Scripting;
89
using UnityEngine.InputSystem;
910
using UnityEngine.InputSystem.Controls;
1011
using UnityEngine.InputSystem.Layouts;
@@ -624,6 +625,7 @@ struct StateWith2Bytes : IInputStateTypeInfo
624625
}
625626

626627
[InputControlLayout(stateType = typeof(StateWith2Bytes))]
628+
[Preserve]
627629
class DeviceWith2ByteState : InputDevice
628630
{
629631
}
@@ -840,6 +842,7 @@ private struct CustomDeviceState : IInputStateTypeInfo
840842
}
841843

842844
[InputControlLayout(stateType = typeof(CustomDeviceState))]
845+
[Preserve]
843846
private class CustomDevice : InputDevice
844847
{
845848
public AxisControl axis { get; private set; }
@@ -852,6 +855,7 @@ protected override void FinishSetup()
852855
}
853856

854857
[InputControlLayout(stateType = typeof(CustomDeviceState))]
858+
[Preserve]
855859
private class CustomDeviceWithUpdate : CustomDevice, IInputUpdateCallbackReceiver
856860
{
857861
public int onUpdateCallCount;

0 commit comments

Comments
 (0)