diff --git a/Assets/Samples/InGameHints/InGameHintsActions.cs b/Assets/Samples/InGameHints/InGameHintsActions.cs index 43e50d0c9a..d33f1610de 100644 --- a/Assets/Samples/InGameHints/InGameHintsActions.cs +++ b/Assets/Samples/InGameHints/InGameHintsActions.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator -// version 1.11.3 +// version 1.12.0 // from Assets/Samples/InGameHints/InGameHintsActions.inputactions // // Changes to this file may cause incorrect behavior and will be lost if diff --git a/Assets/Samples/SimpleDemo/SimpleControls.cs b/Assets/Samples/SimpleDemo/SimpleControls.cs index 7499985262..8d761da00d 100644 --- a/Assets/Samples/SimpleDemo/SimpleControls.cs +++ b/Assets/Samples/SimpleDemo/SimpleControls.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator -// version 1.11.3 +// version 1.12.0 // from Assets/Samples/SimpleDemo/SimpleControls.inputactions // // Changes to this file may cause incorrect behavior and will be lost if diff --git a/Assets/Samples/Visualizers/GamepadVis.prefab b/Assets/Samples/Visualizers/GamepadVis.prefab index 5da149c674..5fe2262505 100644 --- a/Assets/Samples/Visualizers/GamepadVis.prefab +++ b/Assets/Samples/Visualizers/GamepadVis.prefab @@ -54,7 +54,7 @@ MonoBehaviour: width: 187.5 height: 62.5 m_Visualization: 1 - m_ControlPath: /touchpadButton + m_ControlPath: /touchpadButton m_ControlIndex: 0 --- !u!1 &5430831073950378571 GameObject: diff --git a/Assets/Samples/Visualizers/GamepadVisualizer.unity b/Assets/Samples/Visualizers/GamepadVisualizer.unity index 5db7272668..0e2a0b65ea 100644 --- a/Assets/Samples/Visualizers/GamepadVisualizer.unity +++ b/Assets/Samples/Visualizers/GamepadVisualizer.unity @@ -42,8 +42,7 @@ RenderSettings: --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 - serializedVersion: 13 - m_BakeOnSceneLoad: 0 + serializedVersion: 12 m_GISettings: serializedVersion: 2 m_BounceScale: 1 @@ -218,7 +217,7 @@ LightingSettings: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: Settings.lighting - serializedVersion: 9 + serializedVersion: 8 m_EnableBakedLightmaps: 1 m_EnableRealtimeLightmaps: 1 m_RealtimeEnvironmentLighting: 1 @@ -272,6 +271,18 @@ LightingSettings: m_PVRFilteringAtrousPositionSigmaIndirect: 2 m_PVRFilteringAtrousPositionSigmaAO: 1 m_RespectSceneVisibilityWhenBakingGI: 0 +--- !u!114 &2122909276 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 5802899217532024206, guid: b8429651427a640919754290f3704312, + type: 3} + m_PrefabInstance: {fileID: 5430831075364511436} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 50c7363fac4d24ae8a679e3e8f1fa838, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &5430831075364511436 PrefabInstance: m_ObjectHideFlags: 0 @@ -280,6 +291,86 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 5430831073950378564, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831074071876626, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831074153646139, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831074316365814, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831074333637590, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831074406035310, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831074569589722, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831074657706043, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831074722065634, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831074890777048, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831074908778959, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831074960731594, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831075105443483, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831075159756558, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831075192722340, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831075336578713, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} - target: {fileID: 5430831075476541849, guid: b8429651427a640919754290f3704312, type: 3} propertyPath: m_Name @@ -335,6 +426,61 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 5430831075516136799, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrent + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831075516136799, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831075516136799, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentForControlIndex + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831075640135793, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831075882524474, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831075888579014, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831075958221745, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5430831075990510060, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5802899217532024206, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_Master + value: + objectReference: {fileID: 2122909276} + - target: {fileID: 5802899217532024206, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 6586345530156004295, guid: b8429651427a640919754290f3704312, + type: 3} + propertyPath: m_UseCurrentDevice + value: 1 + objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] diff --git a/Assets/Samples/Visualizers/InputControlVisualizer.cs b/Assets/Samples/Visualizers/InputControlVisualizer.cs index 9a2950c7ab..d8be3a65d4 100644 --- a/Assets/Samples/Visualizers/InputControlVisualizer.cs +++ b/Assets/Samples/Visualizers/InputControlVisualizer.cs @@ -138,13 +138,30 @@ public int controlIndex + "which of the controls to visualize.")] [InputControl, SerializeField] private string m_ControlPath; [Tooltip("If multiple controls match 'Control Path' at runtime, this property decides " - + "which control to visualize from the list of candidates. It is a zero-based index.")] + + "which control to visualize from the list of candidates. It is a zero-based index. " + + "This is ignored if using current device instead.")] [SerializeField] private int m_ControlIndex; + [Tooltip("If set, ignores control index and maps a control of the current device (if it exist) or none.")] + [SerializeField] private bool m_UseCurrentDevice; + [NonSerialized] private InputControl m_Control; private static List s_EnabledInstances; + private static InputControl ResolveCurrentControl(InputControlList candidates) + { + // Only accept control that belongs to the current device of the same device type as candidate control device type. + foreach (var candidate in candidates) + { + var currentDevice = GetCurrentDevice(candidate.device); + if (candidate.device == currentDevice) + return candidate; + } + + return null; + } + private void ResolveControl() { m_Control = null; @@ -154,7 +171,9 @@ private void ResolveControl() using (var candidates = InputSystem.FindControls(m_ControlPath)) { var numCandidates = candidates.Count; - if (numCandidates > 1 && m_ControlIndex < numCandidates && m_ControlIndex >= 0) + if (m_UseCurrentDevice) + m_Control = ResolveCurrentControl(candidates); + else if (numCandidates > 1 && m_ControlIndex < numCandidates && m_ControlIndex >= 0) m_Control = candidates[m_ControlIndex]; else if (numCandidates > 0) m_Control = candidates[0]; @@ -163,30 +182,52 @@ private void ResolveControl() SetupVisualizer(); } - private void SetupVisualizer() + void Update() { - if (m_Control == null) + // There is currently no callback when current device changes so we will reattempt to resolve control + if (m_UseCurrentDevice) { - m_Visualizer = null; - return; + if (m_Control != null && m_Control.device != GetCurrentDevice(m_Control.device)) + m_Control = null; + if (m_Control == null) + ResolveControl(); } + } - switch (m_Visualization) + private static InputDevice GetCurrentDevice(InputDevice device) + { + if (device is Gamepad) return Gamepad.current; + if (device is Mouse) return Mouse.current; + if (device is Pen) return Pen.current; + if (device is Pointer) return Pointer.current; // should be last, because it's a base class for Mouse and Pen + + throw new ArgumentException( + $"Expected device type that implements .current, but got '{device.name}' (deviceId: {device.deviceId}) instead "); + } + + private static VisualizationHelpers.Visualizer CreateVisualizer(Mode mode, InputControl control, int historySamples) + { + switch (mode) { case Mode.Value: { - var valueType = m_Control.valueType; + // This visualization mode requires a control + if (control == null) + return null; + + VisualizationHelpers.Visualizer visualizer = null; + var valueType = control.valueType; if (valueType == typeof(Vector2)) - m_Visualizer = new VisualizationHelpers.Vector2Visualizer(m_HistorySamples); + visualizer = new VisualizationHelpers.Vector2Visualizer(historySamples); else if (valueType == typeof(float)) - m_Visualizer = new VisualizationHelpers.ScalarVisualizer(m_HistorySamples) + visualizer = new VisualizationHelpers.ScalarVisualizer(historySamples) { ////TODO: pass actual min/max limits of control limitMax = 1, limitMin = 0 }; else if (valueType == typeof(int)) - m_Visualizer = new VisualizationHelpers.ScalarVisualizer(m_HistorySamples) + visualizer = new VisualizationHelpers.ScalarVisualizer(historySamples) { ////TODO: pass actual min/max limits of control limitMax = 1, @@ -196,67 +237,66 @@ private void SetupVisualizer() { ////TODO: generic visualizer } - break; + return visualizer; } case Mode.Events: { - var visualizer = new VisualizationHelpers.TimelineVisualizer(m_HistorySamples) + var visualizer = new VisualizationHelpers.TimelineVisualizer(historySamples) { timeUnit = VisualizationHelpers.TimelineVisualizer.TimeUnit.Frames, - historyDepth = m_HistorySamples, + historyDepth = historySamples, showLimits = true, limitsY = new Vector2(0, 5) // Will expand upward automatically }; - m_Visualizer = visualizer; visualizer.AddTimeline("Events", Color.green, VisualizationHelpers.TimelineVisualizer.PlotType.BarChart); - break; + return visualizer; } case Mode.MaximumLag: { - var visualizer = new VisualizationHelpers.TimelineVisualizer(m_HistorySamples) + var visualizer = new VisualizationHelpers.TimelineVisualizer(historySamples) { timeUnit = VisualizationHelpers.TimelineVisualizer.TimeUnit.Frames, - historyDepth = m_HistorySamples, + historyDepth = historySamples, valueUnit = new GUIContent("ms"), showLimits = true, limitsY = new Vector2(0, 6) }; - m_Visualizer = visualizer; visualizer.AddTimeline("MaxLag", Color.red, VisualizationHelpers.TimelineVisualizer.PlotType.BarChart); - break; + return visualizer; } case Mode.Bytes: { - var visualizer = new VisualizationHelpers.TimelineVisualizer(m_HistorySamples) + var visualizer = new VisualizationHelpers.TimelineVisualizer(historySamples) { timeUnit = VisualizationHelpers.TimelineVisualizer.TimeUnit.Frames, valueUnit = new GUIContent("bytes"), - historyDepth = m_HistorySamples, + historyDepth = historySamples, showLimits = true, limitsY = new Vector2(0, 64) }; - m_Visualizer = visualizer; visualizer.AddTimeline("Bytes", Color.red, VisualizationHelpers.TimelineVisualizer.PlotType.BarChart); - break; + return visualizer; } case Mode.DeviceCurrent: - { - m_Visualizer = new VisualizationHelpers.CurrentDeviceVisualizer(); - break; - } + return new VisualizationHelpers.CurrentDeviceVisualizer(); default: - throw new NotImplementedException(); + throw new ArgumentOutOfRangeException(mode.ToString()); } } + private void SetupVisualizer() + { + m_Visualizer = CreateVisualizer(m_Visualization, m_Control, m_HistorySamples); + } + private static void OnDeviceChange(InputDevice device, InputDeviceChange change) { if (change != InputDeviceChange.Added && change != InputDeviceChange.Removed) diff --git a/Assets/Tests/InputSystem.Editor/InputActionsEditorTests.cs b/Assets/Tests/InputSystem.Editor/InputActionsEditorTests.cs index ffe160c38f..ce912230d2 100644 --- a/Assets/Tests/InputSystem.Editor/InputActionsEditorTests.cs +++ b/Assets/Tests/InputSystem.Editor/InputActionsEditorTests.cs @@ -58,6 +58,7 @@ IEnumerator WaitForActionMapRename(int index, bool isActive, double timeoutSecs #endregion [Test] + [Ignore("Instability, see ISXB-1284")] public void CanListActionMaps() { var actionMapsContainer = m_Window.rootVisualElement.Q("action-maps-container"); @@ -71,6 +72,7 @@ public void CanListActionMaps() } [UnityTest] + [Ignore("Instability, see ISXB-1284")] public IEnumerator CanCreateActionMap() { var button = m_Window.rootVisualElement.Q