Skip to content
Merged
152 changes: 149 additions & 3 deletions Assets/Samples/Visualizers/GamepadVisualizer.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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: []
Expand Down
98 changes: 69 additions & 29 deletions Assets/Samples/Visualizers/InputControlVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InputControlVisualizer> s_EnabledInstances;

private static InputControl ResolveCurrentControl(InputControlList<InputControl> 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;
Expand All @@ -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];
Expand All @@ -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<float>(m_HistorySamples)
visualizer = new VisualizationHelpers.ScalarVisualizer<float>(historySamples)
{
////TODO: pass actual min/max limits of control
limitMax = 1,
limitMin = 0
};
else if (valueType == typeof(int))
m_Visualizer = new VisualizationHelpers.ScalarVisualizer<int>(m_HistorySamples)
visualizer = new VisualizationHelpers.ScalarVisualizer<int>(historySamples)
{
////TODO: pass actual min/max limits of control
limitMax = 1,
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ however, it has to be formatted properly to pass verification tests.
- Fixed a CS0105 compiler warning due to duplicate using statement in test source code (ISXB-1247).
- Fixed tooltip support in the UI Toolkit version of the Input Actions Asset editor.
- Fixed documentation to clarify bindings with modifiers `overrideModifiersNeedToBePressedFirst` configuration [ISXB-806](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-806).
- Fixed an issue in `Samples/Visualizers/GamepadVisualizer.unity` sample where the visualization wouldn't handle device disconnects or current device changes properly (ISXB-1243).

### Changed
- Added back the InputManager to InputSystem project-wide asset migration code with performance improvement (ISX-2086).
- Changed `OnScreenControl` to automaticaly switch, in Single Player with autoswitch enabled, to the target device control scheme when the first component is enabled to prevent bad interactions when it start.
- Changed paremeter `overrideModifiersNeedToBePressedFirst` to obsolete for `ButtonWithOneModifier`, `ButtonWithTwoModifiers`, `OneModifierComposite` and `TwoModifiersComposite` in favour the new `modifiersOrder` parameter which is more explicit.
- Changed `Samples/Visualizers/GamepadVisualizer.unity` to visualize the control values of the current device instead of the first device.

## [1.11.2] - 2024-10-16

Expand Down