Skip to content

Commit

Permalink
Merge branch 'develop' into docs-quality-week-2024-mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanunity authored Dec 10, 2024
2 parents 900b475 + c756a5e commit 0904b47
Show file tree
Hide file tree
Showing 7 changed files with 504 additions and 212 deletions.
2 changes: 2 additions & 0 deletions Assets/Tests/InputSystem.Editor/InputActionsEditorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void CanListActionMaps()
}

[UnityTest]
[Ignore("Instability, see ISXB-1284")]
public IEnumerator CanCreateActionMap()
{
var button = m_Window.rootVisualElement.Q<Button>("add-new-action-map-button");
Expand Down Expand Up @@ -147,6 +148,7 @@ public IEnumerator CanRenameActionMap()
}

[UnityTest]
[Ignore("Instability, see ISXB-1284")]
public IEnumerator CanDeleteActionMap()
{
var actionMapsContainer = m_Window.rootVisualElement.Q("action-maps-container");
Expand Down
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ however, it has to be formatted properly to pass verification tests.
- 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).
- Fixed an issue when displaying Serialized InputAction's Processor properties inside the Inspector window. [ISXB-1269](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1269)
- Fixed an issue with default device selection when adding new Control Scheme.

### Changed
- Added back the InputManager to InputSystem project-wide asset migration code with performance improvement (ISX-2086).
Expand Down
78 changes: 64 additions & 14 deletions Packages/com.unity.inputsystem/InputSystem/Controls/InputControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace UnityEngine.InputSystem
/// which has APIs specific to the type of value of the control (e.g. <see cref="InputControl{TValue}.ReadValue()"/>.
///
/// The following example demonstrates various common operations performed on input controls:
///
/// </remarks>
/// <example>
/// <code>
/// // Look up dpad/up control on current gamepad.
Expand All @@ -99,10 +99,7 @@ namespace UnityEngine.InputSystem
/// leftStickHistory.Enable();
/// </code>
/// </example>
/// <example>
/// </example>
/// </remarks>
/// <see cref="InputControl{TValue}"/>
/// <seealso cref="InputControl{TValue}"/>
/// <seealso cref="InputDevice"/>
/// <seealso cref="InputControlPath"/>
/// <seealso cref="InputStateBlock"/>
Expand Down Expand Up @@ -611,6 +608,8 @@ public virtual unsafe void WriteValueFromObjectIntoState(object value, void* sta
/// Note that if the given path matches multiple child controls, only the first control
/// encountered in the search will be returned.
///
/// This method is equivalent to calling <see cref="InputControlPath.TryFindChild"/>.
/// </remarks>
/// <example>
/// <code>
/// // Returns the leftStick control of the current gamepad.
Expand All @@ -625,9 +624,6 @@ public virtual unsafe void WriteValueFromObjectIntoState(object value, void* sta
/// Gamepad.current.TryGetChildControl("*stick");
/// </code>
/// </example>
///
/// This method is equivalent to calling <see cref="InputControlPath.TryFindChild"/>.
/// </remarks>
public InputControl TryGetChildControl(string path)
{
if (string.IsNullOrEmpty(path))
Expand Down Expand Up @@ -689,7 +685,7 @@ protected InputControl()
/// <remarks>
/// This method can be overridden to perform control- or device-specific setup work. The most
/// common use case is for looking up child controls and storing them in local getters.
///
/// </remarks>
/// <example>
/// <code>
/// public class MyDevice : InputDevice
Expand All @@ -706,7 +702,6 @@ protected InputControl()
/// }
/// </code>
/// </example>
/// </remarks>
protected virtual void FinishSetup()
{
}
Expand All @@ -723,9 +718,12 @@ protected virtual void FinishSetup()
///
/// This method should be called if you are accessing cached data set up by
/// <see cref="RefreshConfiguration"/>.
///
/// </remarks>
/// <example>
/// <code>
/// using UnityEngine.InputSystem;
/// using UnityEngine.InputSystem.Utilities;
///
/// // Let's say your device has an associated orientation which it can be held with
/// // and you want to surface both as a property and as a usage on the device.
/// // Whenever your backend code detects a change in orientation, it should send
Expand Down Expand Up @@ -779,7 +777,6 @@ protected virtual void FinishSetup()
/// }
/// </code>
/// </example>
/// </remarks>
/// <seealso cref="RefreshConfiguration"/>
protected void RefreshConfigurationIfNeeded()
{
Expand All @@ -790,6 +787,61 @@ protected void RefreshConfigurationIfNeeded()
}
}

/// <summary>
/// Refresh the configuration of the control. This is used to update the control's state (e.g. Keyboard Layout or display Name of Keys).
/// </summary>
/// <remarks>
/// The system will call this method automatically whenever a change is made to one of the control's configuration properties.
/// See <see cref="RefreshConfigurationIfNeeded"/>.
/// </remarks>
/// <example>
/// <code>
/// using UnityEngine.InputSystem;
/// using UnityEngine.InputSystem.Utilities;
///
/// public class MyDevice : InputDevice
/// {
/// public enum Orientation
/// {
/// Horizontal,
/// Vertical,
/// }
/// private Orientation m_Orientation;
/// private static InternedString s_Vertical = new InternedString("Vertical");
/// private static InternedString s_Horizontal = new InternedString("Horizontal");
///
/// public Orientation orientation
/// {
/// get
/// {
/// // Call RefreshOrientation if the configuration of the device has been
/// // invalidated since last time we initialized m_Orientation.
/// // Calling RefreshConfigurationIfNeeded() is sufficient in most cases, RefreshConfiguration() forces the refresh.
/// RefreshConfiguration();
/// return m_Orientation;
/// }
/// }
/// protected override void RefreshConfiguration()
/// {
/// // Set Orientation back to horizontal. Alternatively fetch from device.
/// m_Orientation = Orientation.Horizontal;
/// // Reflect the orientation on the device.
/// switch (m_Orientation)
/// {
/// case Orientation.Vertical:
/// InputSystem.RemoveDeviceUsage(this, s_Horizontal);
/// InputSystem.AddDeviceUsage(this, s_Vertical);
/// break;
///
/// case Orientation.Horizontal:
/// InputSystem.RemoveDeviceUsage(this, s_Vertical);
/// InputSystem.AddDeviceUsage(this, s_Horizontal);
/// break;
/// }
/// }
/// }
/// </code>
/// </example>
protected virtual void RefreshConfiguration()
{
}
Expand Down Expand Up @@ -902,8 +954,6 @@ protected virtual FourCC CalculateOptimizedControlDataType()
/// <summary>
/// Apply built-in parameters changes (e.g. <see cref="AxisControl.invert"/>, others), recompute <see cref="InputControl.optimizedControlDataType"/> for impacted controls and clear cached value.
/// </summary>
/// <remarks>
/// </remarks>
public void ApplyParameterChanges()
{
// First we go through all children of our own hierarchy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public int scanCode
return m_ScanCode;
}
}

/// <inheritdoc/>
protected override void RefreshConfiguration()
{
// Wipe our last cached set of data (if any).
Expand Down
94 changes: 65 additions & 29 deletions Packages/com.unity.inputsystem/InputSystem/Devices/InputDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,31 @@ namespace UnityEngine.InputSystem
/// runtime. However, it is possible to manually add devices using methods such as <see
/// cref="InputSystem.AddDevice{TDevice}(string)"/>.
///
/// <example>
/// <code>
/// // Add a "synthetic" gamepad that isn't actually backed by hardware.
/// var gamepad = InputSystem.AddDevice&lt;Gamepad&gt;();
/// </code>
/// </example>
///
/// There are subclasses representing the most common types of devices, like <see cref="Mouse"/>,
/// <see cref="Keyboard"/>, <see cref="Gamepad"/>, and <see cref="Touchscreen"/>.
///
/// To create your own types of devices, you can derive from InputDevice and register your device
/// as a new "layout".
///
/// Devices can have usages like any other control (<see cref="InputControl.usages"/>). However, usages of InputDevices are allowed to be changed on the fly without requiring a change to the
/// device layout (see <see cref="InputSystem.SetDeviceUsage(InputDevice,string)"/>).
///
/// For a more complete example of how to implement custom input devices, check out the "Custom Device"
/// sample which you can install from the Unity package manager.
///
/// You can also find more information in the <a href="../manual/Devices.html">manual</a>.
/// </remarks>
/// <example>
/// <code>
/// using System.Runtime.InteropServices;
/// using UnityEditor;
/// using UnityEngine;
/// using UnityEngine.InputSystem;
/// using UnityEngine.InputSystem.Controls;
/// using UnityEngine.InputSystem.Layouts;
/// using UnityEngine.InputSystem.LowLevel;
/// using UnityEngine.InputSystem.Utilities;
///
/// // InputControlLayoutAttribute attribute is only necessary if you want
/// // to override default behavior that occurs when registering your device
/// // as a layout.
Expand All @@ -70,6 +80,9 @@ namespace UnityEngine.InputSystem
/// public ButtonControl button { get; private set; }
/// public AxisControl axis { get; private set; }
///
/// // This is an example of how to add a "synthetic" gamepad that isn't actually backed by hardware.
/// Gamepad gamepad = InputSystem.AddDevice&lt;Gamepad&gt;();
///
/// // Register the device.
/// static MyDevice()
/// {
Expand Down Expand Up @@ -113,34 +126,24 @@ namespace UnityEngine.InputSystem
/// // particular device is connected and fed into the input system.
/// // The format is a simple FourCC code that "tags" state memory blocks for the
/// // device to give a base level of safety checks on memory operations.
/// public FourCC format => return new FourCC('H', 'I', 'D');
/// public FourCC format => new FourCC('H', 'I', 'D');
///
/// // InputControlAttributes on fields tell the input system to create controls
/// // for the public fields found in the struct.
///
/// // Assume a 16bit field of buttons. Create one button that is tied to
/// // bit #3 (zero-based). Note that buttons do not need to be stored as bits.
/// // They can also be stored as floats or shorts, for example.
/// [InputControl(name = "button", layout = "Button", bit = 3)]
/// [InputControl(name = "button", layout = "Button", bit = 3)] [FieldOffset(0)]
/// public ushort buttons;
///
/// // Create a floating-point axis. The name, if not supplied, is taken from
/// // the field.
/// [InputControl(layout = "Axis")]
/// [InputControl(layout = "Axis")] [FieldOffset(0)]
/// public short axis;
/// }
/// </code>
/// </example>
///
/// Devices can have usages like any other control (<see cref="InputControl.usages"/>). Unlike other controls,
/// however, usages of InputDevices are allowed to be changed on the fly without requiring a change to the
/// device layout (see <see cref="InputSystem.SetDeviceUsage(InputDevice,string)"/>).
///
/// For a more complete example of how to implement custom input devices, check out the "Custom Device"
/// sample which you can install from the Unity package manager.
///
/// And, as always, you can also find more information in the <a href="../manual/Devices.html">manual</a>.
/// </remarks>
/// <seealso cref="InputControl"/>
/// <seealso cref="Mouse"/>
/// <seealso cref="Keyboard"/>
Expand Down Expand Up @@ -508,10 +511,26 @@ public virtual void MakeCurrent()
/// </summary>
/// <remarks>
/// This is called <em>after</em> the device has already been added.
/// <see cref="InputSystem.devices"/>
/// <see cref="InputDeviceChange.Added"/>
/// <see cref="OnRemoved"/>
/// </remarks>
/// <seealso cref="InputSystem.devices"/>
/// <seealso cref="InputDeviceChange.Added"/>
/// <seealso cref="OnRemoved"/>
/// <example>
/// <code>
/// using UnityEngine.InputSystem;
///
/// public class MyDevice : InputDevice
/// {
/// public static MyDevice current { get; private set; }
/// protected override void OnAdded()
/// {
/// // use this context to assign the current device for instance
/// base.OnAdded();
/// current = this;
/// }
/// }
/// </code>
/// </example>
protected virtual void OnAdded()
{
}
Expand All @@ -521,10 +540,27 @@ protected virtual void OnAdded()
/// </summary>
/// <remarks>
/// This is called <em>after</em> the device has already been removed.
/// <see cref="InputSystem.devices"/>
/// <see cref="InputDeviceChange.Removed"/>
/// <see cref="OnAdded"/>
/// </remarks>
/// <seealso cref="InputSystem.devices"/>
/// <seealso cref="InputDeviceChange.Removed"/>
/// <seealso cref="OnRemoved"/>
/// <example>
/// <code>
/// using UnityEngine.InputSystem;
///
/// public class MyDevice : InputDevice
/// {
/// public static MyDevice current { get; private set; }
/// protected override void OnRemoved()
/// {
/// // use this context to unassign the current device for instance
/// base.OnRemoved();
/// if (current == this)
/// current = null;
/// }
/// }
/// </code>
/// </example>
protected virtual void OnRemoved()
{
}
Expand All @@ -542,7 +578,7 @@ protected virtual void OnRemoved()
/// </remarks>
/// <seealso cref="InputManager.OnUpdate"/>
/// <seealso cref="InputDeviceChange.ConfigurationChanged"/>
/// <seealso cref="OnConfigurationChanged"/>///
/// <seealso cref="OnConfigurationChanged"/>
protected virtual void OnConfigurationChanged()
{
}
Expand All @@ -560,8 +596,8 @@ protected virtual void OnConfigurationChanged()
/// the device API. This is most useful for devices implemented in the native Unity runtime
/// which, through the command interface, may provide custom, device-specific functions.
///
/// This is a low-level API. It works in a similar way to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363216%28v=vs.85%29.aspx?f=255&amp;MSPPError=-2147217396" target="_blank">
/// DeviceIoControl</a> on Windows and <a href="https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/ioctl.2.html#//apple_ref/doc/man/2/ioctl" target="_blank">ioctl</a>
/// This is a low-level API. It works in a similar way to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363216%28v=vs.85%29.aspx?f=255&amp;MSPPError=-2147217396">
/// DeviceIoControl</a> on Windows and <a href="https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/ioctl.2.html#//apple_ref/doc/man/2/ioctl">ioctl</a>
/// on UNIX-like systems.
/// </remarks>
public unsafe long ExecuteCommand<TCommand>(ref TCommand command)
Expand Down
Loading

0 comments on commit 0904b47

Please sign in to comment.