Skip to content

Commit 9aea79a

Browse files
authored
Merge branch 'develop' into docs-quality-week-2024-inputstatehistory
2 parents f2a52da + eca97b8 commit 9aea79a

File tree

6 files changed

+502
-212
lines changed

6 files changed

+502
-212
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ however, it has to be formatted properly to pass verification tests.
3131
- Fixed documentation to clarify bindings with modifiers `overrideModifiersNeedToBePressedFirst` configuration [ISXB-806](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-806).
3232
- Fixed an issue in `Samples/Visualizers/GamepadVisualizer.unity` sample where the visualization wouldn't handle device disconnects or current device changes properly (ISXB-1243).
3333
- 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)
34+
- Fixed an issue with default device selection when adding new Control Scheme.
3435

3536
### Changed
3637
- Added back the InputManager to InputSystem project-wide asset migration code with performance improvement (ISX-2086).

Packages/com.unity.inputsystem/InputSystem/Controls/InputControl.cs

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace UnityEngine.InputSystem
7777
/// which has APIs specific to the type of value of the control (e.g. <see cref="InputControl{TValue}.ReadValue()"/>.
7878
///
7979
/// The following example demonstrates various common operations performed on input controls:
80-
///
80+
/// </remarks>
8181
/// <example>
8282
/// <code>
8383
/// // Look up dpad/up control on current gamepad.
@@ -99,10 +99,7 @@ namespace UnityEngine.InputSystem
9999
/// leftStickHistory.Enable();
100100
/// </code>
101101
/// </example>
102-
/// <example>
103-
/// </example>
104-
/// </remarks>
105-
/// <see cref="InputControl{TValue}"/>
102+
/// <seealso cref="InputControl{TValue}"/>
106103
/// <seealso cref="InputDevice"/>
107104
/// <seealso cref="InputControlPath"/>
108105
/// <seealso cref="InputStateBlock"/>
@@ -611,6 +608,8 @@ public virtual unsafe void WriteValueFromObjectIntoState(object value, void* sta
611608
/// Note that if the given path matches multiple child controls, only the first control
612609
/// encountered in the search will be returned.
613610
///
611+
/// This method is equivalent to calling <see cref="InputControlPath.TryFindChild"/>.
612+
/// </remarks>
614613
/// <example>
615614
/// <code>
616615
/// // Returns the leftStick control of the current gamepad.
@@ -625,9 +624,6 @@ public virtual unsafe void WriteValueFromObjectIntoState(object value, void* sta
625624
/// Gamepad.current.TryGetChildControl("*stick");
626625
/// </code>
627626
/// </example>
628-
///
629-
/// This method is equivalent to calling <see cref="InputControlPath.TryFindChild"/>.
630-
/// </remarks>
631627
public InputControl TryGetChildControl(string path)
632628
{
633629
if (string.IsNullOrEmpty(path))
@@ -689,7 +685,7 @@ protected InputControl()
689685
/// <remarks>
690686
/// This method can be overridden to perform control- or device-specific setup work. The most
691687
/// common use case is for looking up child controls and storing them in local getters.
692-
///
688+
/// </remarks>
693689
/// <example>
694690
/// <code>
695691
/// public class MyDevice : InputDevice
@@ -706,7 +702,6 @@ protected InputControl()
706702
/// }
707703
/// </code>
708704
/// </example>
709-
/// </remarks>
710705
protected virtual void FinishSetup()
711706
{
712707
}
@@ -723,9 +718,12 @@ protected virtual void FinishSetup()
723718
///
724719
/// This method should be called if you are accessing cached data set up by
725720
/// <see cref="RefreshConfiguration"/>.
726-
///
721+
/// </remarks>
727722
/// <example>
728723
/// <code>
724+
/// using UnityEngine.InputSystem;
725+
/// using UnityEngine.InputSystem.Utilities;
726+
///
729727
/// // Let's say your device has an associated orientation which it can be held with
730728
/// // and you want to surface both as a property and as a usage on the device.
731729
/// // Whenever your backend code detects a change in orientation, it should send
@@ -779,7 +777,6 @@ protected virtual void FinishSetup()
779777
/// }
780778
/// </code>
781779
/// </example>
782-
/// </remarks>
783780
/// <seealso cref="RefreshConfiguration"/>
784781
protected void RefreshConfigurationIfNeeded()
785782
{
@@ -790,6 +787,61 @@ protected void RefreshConfigurationIfNeeded()
790787
}
791788
}
792789

790+
/// <summary>
791+
/// Refresh the configuration of the control. This is used to update the control's state (e.g. Keyboard Layout or display Name of Keys).
792+
/// </summary>
793+
/// <remarks>
794+
/// The system will call this method automatically whenever a change is made to one of the control's configuration properties.
795+
/// See <see cref="RefreshConfigurationIfNeeded"/>.
796+
/// </remarks>
797+
/// <example>
798+
/// <code>
799+
/// using UnityEngine.InputSystem;
800+
/// using UnityEngine.InputSystem.Utilities;
801+
///
802+
/// public class MyDevice : InputDevice
803+
/// {
804+
/// public enum Orientation
805+
/// {
806+
/// Horizontal,
807+
/// Vertical,
808+
/// }
809+
/// private Orientation m_Orientation;
810+
/// private static InternedString s_Vertical = new InternedString("Vertical");
811+
/// private static InternedString s_Horizontal = new InternedString("Horizontal");
812+
///
813+
/// public Orientation orientation
814+
/// {
815+
/// get
816+
/// {
817+
/// // Call RefreshOrientation if the configuration of the device has been
818+
/// // invalidated since last time we initialized m_Orientation.
819+
/// // Calling RefreshConfigurationIfNeeded() is sufficient in most cases, RefreshConfiguration() forces the refresh.
820+
/// RefreshConfiguration();
821+
/// return m_Orientation;
822+
/// }
823+
/// }
824+
/// protected override void RefreshConfiguration()
825+
/// {
826+
/// // Set Orientation back to horizontal. Alternatively fetch from device.
827+
/// m_Orientation = Orientation.Horizontal;
828+
/// // Reflect the orientation on the device.
829+
/// switch (m_Orientation)
830+
/// {
831+
/// case Orientation.Vertical:
832+
/// InputSystem.RemoveDeviceUsage(this, s_Horizontal);
833+
/// InputSystem.AddDeviceUsage(this, s_Vertical);
834+
/// break;
835+
///
836+
/// case Orientation.Horizontal:
837+
/// InputSystem.RemoveDeviceUsage(this, s_Vertical);
838+
/// InputSystem.AddDeviceUsage(this, s_Horizontal);
839+
/// break;
840+
/// }
841+
/// }
842+
/// }
843+
/// </code>
844+
/// </example>
793845
protected virtual void RefreshConfiguration()
794846
{
795847
}
@@ -902,8 +954,6 @@ protected virtual FourCC CalculateOptimizedControlDataType()
902954
/// <summary>
903955
/// Apply built-in parameters changes (e.g. <see cref="AxisControl.invert"/>, others), recompute <see cref="InputControl.optimizedControlDataType"/> for impacted controls and clear cached value.
904956
/// </summary>
905-
/// <remarks>
906-
/// </remarks>
907957
public void ApplyParameterChanges()
908958
{
909959
// First we go through all children of our own hierarchy

Packages/com.unity.inputsystem/InputSystem/Controls/KeyControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public int scanCode
5858
return m_ScanCode;
5959
}
6060
}
61-
61+
/// <inheritdoc/>
6262
protected override void RefreshConfiguration()
6363
{
6464
// Wipe our last cached set of data (if any).

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

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,31 @@ namespace UnityEngine.InputSystem
4141
/// runtime. However, it is possible to manually add devices using methods such as <see
4242
/// cref="InputSystem.AddDevice{TDevice}(string)"/>.
4343
///
44-
/// <example>
45-
/// <code>
46-
/// // Add a "synthetic" gamepad that isn't actually backed by hardware.
47-
/// var gamepad = InputSystem.AddDevice&lt;Gamepad&gt;();
48-
/// </code>
49-
/// </example>
50-
///
5144
/// There are subclasses representing the most common types of devices, like <see cref="Mouse"/>,
5245
/// <see cref="Keyboard"/>, <see cref="Gamepad"/>, and <see cref="Touchscreen"/>.
5346
///
5447
/// To create your own types of devices, you can derive from InputDevice and register your device
5548
/// as a new "layout".
5649
///
50+
/// 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
51+
/// device layout (see <see cref="InputSystem.SetDeviceUsage(InputDevice,string)"/>).
52+
///
53+
/// For a more complete example of how to implement custom input devices, check out the "Custom Device"
54+
/// sample which you can install from the Unity package manager.
55+
///
56+
/// You can also find more information in the <a href="../manual/Devices.html">manual</a>.
57+
/// </remarks>
5758
/// <example>
5859
/// <code>
60+
/// using System.Runtime.InteropServices;
61+
/// using UnityEditor;
62+
/// using UnityEngine;
63+
/// using UnityEngine.InputSystem;
64+
/// using UnityEngine.InputSystem.Controls;
65+
/// using UnityEngine.InputSystem.Layouts;
66+
/// using UnityEngine.InputSystem.LowLevel;
67+
/// using UnityEngine.InputSystem.Utilities;
68+
///
5969
/// // InputControlLayoutAttribute attribute is only necessary if you want
6070
/// // to override default behavior that occurs when registering your device
6171
/// // as a layout.
@@ -70,6 +80,9 @@ namespace UnityEngine.InputSystem
7080
/// public ButtonControl button { get; private set; }
7181
/// public AxisControl axis { get; private set; }
7282
///
83+
/// // This is an example of how to add a "synthetic" gamepad that isn't actually backed by hardware.
84+
/// Gamepad gamepad = InputSystem.AddDevice&lt;Gamepad&gt;();
85+
///
7386
/// // Register the device.
7487
/// static MyDevice()
7588
/// {
@@ -113,34 +126,24 @@ namespace UnityEngine.InputSystem
113126
/// // particular device is connected and fed into the input system.
114127
/// // The format is a simple FourCC code that "tags" state memory blocks for the
115128
/// // device to give a base level of safety checks on memory operations.
116-
/// public FourCC format => return new FourCC('H', 'I', 'D');
129+
/// public FourCC format => new FourCC('H', 'I', 'D');
117130
///
118131
/// // InputControlAttributes on fields tell the input system to create controls
119132
/// // for the public fields found in the struct.
120133
///
121134
/// // Assume a 16bit field of buttons. Create one button that is tied to
122135
/// // bit #3 (zero-based). Note that buttons do not need to be stored as bits.
123136
/// // They can also be stored as floats or shorts, for example.
124-
/// [InputControl(name = "button", layout = "Button", bit = 3)]
137+
/// [InputControl(name = "button", layout = "Button", bit = 3)] [FieldOffset(0)]
125138
/// public ushort buttons;
126139
///
127140
/// // Create a floating-point axis. The name, if not supplied, is taken from
128141
/// // the field.
129-
/// [InputControl(layout = "Axis")]
142+
/// [InputControl(layout = "Axis")] [FieldOffset(0)]
130143
/// public short axis;
131144
/// }
132145
/// </code>
133146
/// </example>
134-
///
135-
/// Devices can have usages like any other control (<see cref="InputControl.usages"/>). Unlike other controls,
136-
/// however, usages of InputDevices are allowed to be changed on the fly without requiring a change to the
137-
/// device layout (see <see cref="InputSystem.SetDeviceUsage(InputDevice,string)"/>).
138-
///
139-
/// For a more complete example of how to implement custom input devices, check out the "Custom Device"
140-
/// sample which you can install from the Unity package manager.
141-
///
142-
/// And, as always, you can also find more information in the <a href="../manual/Devices.html">manual</a>.
143-
/// </remarks>
144147
/// <seealso cref="InputControl"/>
145148
/// <seealso cref="Mouse"/>
146149
/// <seealso cref="Keyboard"/>
@@ -508,10 +511,26 @@ public virtual void MakeCurrent()
508511
/// </summary>
509512
/// <remarks>
510513
/// This is called <em>after</em> the device has already been added.
514+
/// <see cref="InputSystem.devices"/>
515+
/// <see cref="InputDeviceChange.Added"/>
516+
/// <see cref="OnRemoved"/>
511517
/// </remarks>
512-
/// <seealso cref="InputSystem.devices"/>
513-
/// <seealso cref="InputDeviceChange.Added"/>
514-
/// <seealso cref="OnRemoved"/>
518+
/// <example>
519+
/// <code>
520+
/// using UnityEngine.InputSystem;
521+
///
522+
/// public class MyDevice : InputDevice
523+
/// {
524+
/// public static MyDevice current { get; private set; }
525+
/// protected override void OnAdded()
526+
/// {
527+
/// // use this context to assign the current device for instance
528+
/// base.OnAdded();
529+
/// current = this;
530+
/// }
531+
/// }
532+
/// </code>
533+
/// </example>
515534
protected virtual void OnAdded()
516535
{
517536
}
@@ -521,10 +540,27 @@ protected virtual void OnAdded()
521540
/// </summary>
522541
/// <remarks>
523542
/// This is called <em>after</em> the device has already been removed.
543+
/// <see cref="InputSystem.devices"/>
544+
/// <see cref="InputDeviceChange.Removed"/>
545+
/// <see cref="OnAdded"/>
524546
/// </remarks>
525-
/// <seealso cref="InputSystem.devices"/>
526-
/// <seealso cref="InputDeviceChange.Removed"/>
527-
/// <seealso cref="OnRemoved"/>
547+
/// <example>
548+
/// <code>
549+
/// using UnityEngine.InputSystem;
550+
///
551+
/// public class MyDevice : InputDevice
552+
/// {
553+
/// public static MyDevice current { get; private set; }
554+
/// protected override void OnRemoved()
555+
/// {
556+
/// // use this context to unassign the current device for instance
557+
/// base.OnRemoved();
558+
/// if (current == this)
559+
/// current = null;
560+
/// }
561+
/// }
562+
/// </code>
563+
/// </example>
528564
protected virtual void OnRemoved()
529565
{
530566
}
@@ -542,7 +578,7 @@ protected virtual void OnRemoved()
542578
/// </remarks>
543579
/// <seealso cref="InputManager.OnUpdate"/>
544580
/// <seealso cref="InputDeviceChange.ConfigurationChanged"/>
545-
/// <seealso cref="OnConfigurationChanged"/>///
581+
/// <seealso cref="OnConfigurationChanged"/>
546582
protected virtual void OnConfigurationChanged()
547583
{
548584
}
@@ -560,8 +596,8 @@ protected virtual void OnConfigurationChanged()
560596
/// the device API. This is most useful for devices implemented in the native Unity runtime
561597
/// which, through the command interface, may provide custom, device-specific functions.
562598
///
563-
/// 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">
564-
/// 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>
599+
/// 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">
600+
/// 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>
565601
/// on UNIX-like systems.
566602
/// </remarks>
567603
public unsafe long ExecuteCommand<TCommand>(ref TCommand command)

0 commit comments

Comments
 (0)