From 110e5c6df1671dc258a083a87b2c5bceb47d40c0 Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Wed, 7 Aug 2024 14:38:59 -0400 Subject: [PATCH 01/10] ISXB-543 Implemented custom drawer base for enums as well as on specific to gamepad buttons. Also removed aliased values in GamepadButton enum --- Assets/Tests/InputSystem/CoreTests_Actions.cs | 6 +- Assets/Tests/InputSystem/CoreTests_Devices.cs | 8 +-- Assets/Tests/InputSystem/CoreTests_Events.cs | 18 ++--- Assets/Tests/InputSystem/CoreTests_State.cs | 6 +- Assets/Tests/InputSystem/Plugins/UserTests.cs | 2 +- .../InputSystem/Devices/Gamepad.cs | 66 ++----------------- .../PropertyDrawers/InputEnumDrawerBase.cs | 28 ++++++++ .../InputEnumDrawerBase.cs.meta | 11 ++++ .../InputGamepadButtonDrawer.cs | 55 ++++++++++++++++ .../InputGamepadButtonDrawer.cs.meta | 11 ++++ 10 files changed, 129 insertions(+), 82 deletions(-) create mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs create mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs.meta create mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs create mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs.meta diff --git a/Assets/Tests/InputSystem/CoreTests_Actions.cs b/Assets/Tests/InputSystem/CoreTests_Actions.cs index 3106ccf80f..5261ad1a96 100644 --- a/Assets/Tests/InputSystem/CoreTests_Actions.cs +++ b/Assets/Tests/InputSystem/CoreTests_Actions.cs @@ -4661,7 +4661,7 @@ public void Actions_PressingAndReleasingButtonInSameUpdate_StillTriggersAction() ctx => { ++receivedCalls; }; action.Enable(); - var firstState = new GamepadState {buttons = 1 << (int)GamepadButton.B}; + var firstState = new GamepadState {buttons = 1 << (int)GamepadButton.East}; var secondState = new GamepadState {buttons = 0}; InputSystem.QueueStateEvent(gamepad, firstState); @@ -6925,7 +6925,7 @@ public void Actions_CanDistinguishTapAndSlowTapOnSameAction() trace.SubscribeTo(action); // Perform tap. - InputSystem.QueueStateEvent(gamepad, new GamepadState().WithButton(GamepadButton.A), 0.0); + InputSystem.QueueStateEvent(gamepad, new GamepadState().WithButton(GamepadButton.South), 0.0); InputSystem.QueueStateEvent(gamepad, new GamepadState(), 0.05); InputSystem.Update(); @@ -6942,7 +6942,7 @@ public void Actions_CanDistinguishTapAndSlowTapOnSameAction() trace.Clear(); // Perform slow tap. - InputSystem.QueueStateEvent(gamepad, new GamepadState().WithButton(GamepadButton.A), 2.0); + InputSystem.QueueStateEvent(gamepad, new GamepadState().WithButton(GamepadButton.South), 2.0); InputSystem.QueueStateEvent(gamepad, new GamepadState(), 2.0 + InputSystem.settings.defaultSlowTapTime + 0.0001); InputSystem.Update(); diff --git a/Assets/Tests/InputSystem/CoreTests_Devices.cs b/Assets/Tests/InputSystem/CoreTests_Devices.cs index 0408664175..8ae119cb72 100644 --- a/Assets/Tests/InputSystem/CoreTests_Devices.cs +++ b/Assets/Tests/InputSystem/CoreTests_Devices.cs @@ -4160,7 +4160,7 @@ public void Devices_AreMadeCurrentWhenReceivingStateEvent() Assert.That(Gamepad.current, Is.Not.SameAs(gamepad1)); - InputSystem.QueueStateEvent(gamepad1, new GamepadState().WithButton(GamepadButton.A)); + InputSystem.QueueStateEvent(gamepad1, new GamepadState().WithButton(GamepadButton.South)); InputSystem.Update(); Assert.That(Gamepad.current, Is.SameAs(gamepad1)); @@ -4179,15 +4179,15 @@ public void Devices_AreNotMadeCurrentWhenReceivingStateEventWithNoControlsChange var gamepad1 = InputSystem.AddDevice(); var gamepad2 = InputSystem.AddDevice(); - InputSystem.QueueStateEvent(gamepad1, new GamepadState().WithButton(GamepadButton.A)); + InputSystem.QueueStateEvent(gamepad1, new GamepadState().WithButton(GamepadButton.South)); InputSystem.Update(); Assert.That(Gamepad.current, Is.SameAs(gamepad1)); - InputSystem.QueueStateEvent(gamepad2, new GamepadState().WithButton(GamepadButton.B)); + InputSystem.QueueStateEvent(gamepad2, new GamepadState().WithButton(GamepadButton.East)); InputSystem.Update(); Assert.That(Gamepad.current, Is.SameAs(gamepad2)); - InputSystem.QueueStateEvent(gamepad1, new GamepadState().WithButton(GamepadButton.A)); + InputSystem.QueueStateEvent(gamepad1, new GamepadState().WithButton(GamepadButton.South)); InputSystem.Update(); // If none of the controls changed, a state event shouldn't switch current gamepad. diff --git a/Assets/Tests/InputSystem/CoreTests_Events.cs b/Assets/Tests/InputSystem/CoreTests_Events.cs index 6addd65598..6702003019 100644 --- a/Assets/Tests/InputSystem/CoreTests_Events.cs +++ b/Assets/Tests/InputSystem/CoreTests_Events.cs @@ -103,7 +103,7 @@ public void Events_CanListenForEvents() allButtonPresses.Clear(); Release(gamepad.buttonSouth); - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A, GamepadButton.B)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South, GamepadButton.East)); InputSystem.Update(); Assert.That(callOnceOnButtonPressCount, Is.EqualTo(1)); @@ -135,7 +135,7 @@ public void Events_CanListenForButtonPresses() Assert.That(callCount, Is.Zero); - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South)); InputSystem.Update(); Assert.That(callCount, Is.EqualTo(1)); @@ -145,7 +145,7 @@ public void Events_CanListenForButtonPresses() Assert.That(callCount, Is.EqualTo(1)); - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South)); InputSystem.Update(); Assert.That(callCount, Is.EqualTo(1)); @@ -222,7 +222,7 @@ public void Events_CanGetAllButtonPressesInEvent() controls = eventPtr.GetAllButtonPresses().ToList(); }; - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A, GamepadButton.B)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South, GamepadButton.East)); InputSystem.Update(); Assert.That(controls, Is.EquivalentTo(new[] { gamepad.aButton, gamepad.bButton })); @@ -1319,7 +1319,7 @@ public unsafe void Events_CanTraceEventsOfDevice_AndFilterEventsThroughCallback( trace.Enable(); - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South)); InputSystem.QueueStateEvent(gamepad, default(GamepadState)); InputSystem.Update(); @@ -1338,8 +1338,8 @@ public void Events_CanTraceEventsOfDevice_AndGrowBufferAsNeeded() { trace.Enable(); - InputSystem.QueueStateEvent(device, new GamepadState().WithButton(GamepadButton.A)); - InputSystem.QueueStateEvent(device, new GamepadState().WithButton(GamepadButton.B)); + InputSystem.QueueStateEvent(device, new GamepadState().WithButton(GamepadButton.South)); + InputSystem.QueueStateEvent(device, new GamepadState().WithButton(GamepadButton.East)); InputSystem.Update(); @@ -1358,7 +1358,7 @@ public void Events_CanTraceEventsOfDevice_AndRecordFrameBoundaries() { trace.Enable(); - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South)); InputSystem.Update(); Assert.That(trace.eventCount, Is.EqualTo(2)); @@ -1539,7 +1539,7 @@ public void Events_CanPersistEventTracesInStream() originalTrace.Enable(); InputSystem.QueueStateEvent(pen, new PenState { position = new Vector2(123, 234) }); - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South)); InputSystem.QueueStateEvent(pen, new PenState { position = new Vector2(234, 345) }); InputSystem.Update(); diff --git a/Assets/Tests/InputSystem/CoreTests_State.cs b/Assets/Tests/InputSystem/CoreTests_State.cs index 8bc38bf728..1502188009 100644 --- a/Assets/Tests/InputSystem/CoreTests_State.cs +++ b/Assets/Tests/InputSystem/CoreTests_State.cs @@ -424,7 +424,7 @@ public void State_CanUpdateButtonStateUsingEvent() Assert.That(gamepad.buttonEast.isPressed, Is.False); - var newState = new GamepadState {buttons = 1 << (int)GamepadButton.B}; + var newState = new GamepadState {buttons = 1 << (int)GamepadButton.East}; InputSystem.QueueStateEvent(gamepad, newState); InputSystem.Update(); @@ -440,7 +440,7 @@ public void State_CanDetectWhetherButtonStateHasChangedThisFrame() Assert.That(gamepad.buttonEast.wasPressedThisFrame, Is.False); Assert.That(gamepad.buttonEast.wasReleasedThisFrame, Is.False); - var firstState = new GamepadState {buttons = 1 << (int)GamepadButton.B}; + var firstState = new GamepadState {buttons = 1 << (int)GamepadButton.East}; InputSystem.QueueStateEvent(gamepad, firstState); InputSystem.Update(); @@ -472,7 +472,7 @@ public void State_PressingAndReleasingButtonInSameFrame_ShowsStateChange(bool us var gamepad = InputSystem.AddDevice(); - var firstState = new GamepadState {buttons = 1 << (int)GamepadButton.B}; + var firstState = new GamepadState {buttons = 1 << (int)GamepadButton.East}; var secondState = new GamepadState {buttons = 0}; InputSystem.QueueStateEvent(gamepad, firstState); diff --git a/Assets/Tests/InputSystem/Plugins/UserTests.cs b/Assets/Tests/InputSystem/Plugins/UserTests.cs index 1a8e13e776..7abcaaa158 100644 --- a/Assets/Tests/InputSystem/Plugins/UserTests.cs +++ b/Assets/Tests/InputSystem/Plugins/UserTests.cs @@ -942,7 +942,7 @@ public void Users_CanDetectUseOfUnpairedDevice() ++InputUser.listenForUnpairedDeviceActivity; - InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(1, 0)}.WithButton(GamepadButton.A)); + InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(1, 0)}.WithButton(GamepadButton.South)); InputSystem.Update(); Assert.That(receivedControls, Has.Count.EqualTo(2)); diff --git a/Packages/com.unity.inputsystem/InputSystem/Devices/Gamepad.cs b/Packages/com.unity.inputsystem/InputSystem/Devices/Gamepad.cs index 1a6a98c1e9..5ea43b6fdf 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Devices/Gamepad.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Devices/Gamepad.cs @@ -255,7 +255,7 @@ public enum GamepadButton /// The upper action button on a gamepad. /// /// - /// Identical to and which are the Xbox and PlayStation controller names for this button. + /// Identical to and which are the Xbox and PlayStation controller names for this button. /// North = 4, @@ -263,7 +263,7 @@ public enum GamepadButton /// The right action button on a gamepad. /// /// - /// Identical to and which are the Xbox and PlayStation controller names for this button. + /// Identical to and which are the Xbox and PlayStation controller names for this button. /// East = 5, @@ -271,7 +271,7 @@ public enum GamepadButton /// The lower action button on a gamepad. /// /// - /// Identical to and which are the Xbox and PlayStation controller names for this button. + /// Identical to and which are the Xbox and PlayStation controller names for this button. /// South = 6, @@ -279,7 +279,7 @@ public enum GamepadButton /// The left action button on a gamepad. /// /// - /// Identical to and which are the Xbox and PlayStation controller names for this button. + /// Identical to and which are the Xbox and PlayStation controller names for this button. /// West = 7, @@ -326,64 +326,6 @@ public enum GamepadButton /// The right trigger button on a gamepad. /// RightTrigger = 33, - - /// - /// The X button on an Xbox controller. - /// - /// - /// Identical to , which is the generic name of this button. - /// - X = West, - /// - /// The Y button on an Xbox controller. - /// - /// - /// Identical to , which is the generic name of this button. - /// - Y = North, - /// - /// The A button on an Xbox controller. - /// - /// - /// Identical to , which is the generic name of this button. - /// - A = South, - /// - /// The B button on an Xbox controller. - /// - /// - /// Identical to , which is the generic name of this button. - /// - B = East, - - /// - /// The cross button on a PlayStation controller. - /// - /// - /// Identical to , which is the generic name of this button. - /// - Cross = South, - /// - /// The square button on a PlayStation controller. - /// - /// - /// Identical to , which is the generic name of this button. - /// - Square = West, - /// - /// The triangle button on a PlayStation controller. - /// - /// - /// Identical to , which is the generic name of this button. - /// - Triangle = North, - /// - /// The circle button on a PlayStation controller. - /// - /// - /// Identical to , which is the generic name of this button. - /// - Circle = East, } } diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs new file mode 100644 index 0000000000..d3aefa321a --- /dev/null +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs @@ -0,0 +1,28 @@ +#if UNITY_EDITOR +using System; +using UnityEditor; +using UnityEngine; + +namespace UnityEngine.InputSystem.Editor +{ + public abstract class InputEnumDrawerBase : PropertyDrawer where T : Enum + { + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + EditorGUI.BeginProperty(position, label, property); + if (TryGetPopupOptions(property, out string[] popupOptions)) + { + property.intValue = EditorGUILayout.Popup(label, property.intValue, popupOptions); + } + else + { + DisplayDefaultEnum(property, label); + } + EditorGUI.EndProperty(); + } + + protected abstract bool TryGetPopupOptions(SerializedProperty property, out string[] popupOptions); + protected abstract void DisplayDefaultEnum(SerializedProperty property, GUIContent label); + } +} +#endif \ No newline at end of file diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs.meta b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs.meta new file mode 100644 index 0000000000..573b94bfe6 --- /dev/null +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: daecd8281c311144d9d6233a2ee01884 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs new file mode 100644 index 0000000000..6921a9c6f8 --- /dev/null +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs @@ -0,0 +1,55 @@ +using UnityEditor; +using UnityEngine.InputSystem.LowLevel; + +namespace UnityEngine.InputSystem.Editor +{ + [CustomPropertyDrawer(typeof(GamepadButton))] + public class InputGamepadButtonDrawer : InputEnumDrawerBase + { + protected override bool TryGetPopupOptions(SerializedProperty property, out string[] popupOptions) + { + + controllerType = (ControllerTypes)EditorGUILayout.EnumPopup("Controller type", controllerType); + string[] options = property.enumDisplayNames; + switch (controllerType) + { + case ControllerTypes.Switch: + options[4] = "X"; + options[5] = "A"; + options[6] = "B"; + options[7] = "Y"; + break; + case ControllerTypes.PlayStation: + options[4] = "Triangle"; + options[5] = "Circle"; + options[6] = "Cross"; + options[7] = "Square"; + break; + case ControllerTypes.Xbox: + options[4] = "Y"; + options[5] = "B"; + options[6] = "A"; + options[7] = "X"; + break; + default: + popupOptions = null; + return false; + } + popupOptions = options; + return true; + } + protected override void DisplayDefaultEnum(SerializedProperty property, GUIContent label) + { + property.intValue = (int)(GamepadButton)EditorGUILayout.EnumPopup(label, (GamepadButton)property.intValue); + } + + private enum ControllerTypes + { + Switch, + PlayStation, + Xbox, + Other + } + private ControllerTypes controllerType; + } +} \ No newline at end of file diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs.meta b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs.meta new file mode 100644 index 0000000000..be4b4c2c20 --- /dev/null +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4f27e7f15c09b1c489b0964d1f5d9c4d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 50f2a472ea648b494b4e5921008adbf38d630da4 Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Tue, 13 Aug 2024 15:45:45 -0400 Subject: [PATCH 02/10] Removed custom enum drawer. --- .../PropertyDrawers/InputEnumDrawerBase.cs | 28 ---------- .../InputEnumDrawerBase.cs.meta | 11 ---- .../InputGamepadButtonDrawer.cs | 55 ------------------- .../InputGamepadButtonDrawer.cs.meta | 11 ---- 4 files changed, 105 deletions(-) delete mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs delete mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs.meta delete mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs delete mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs.meta diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs deleted file mode 100644 index d3aefa321a..0000000000 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs +++ /dev/null @@ -1,28 +0,0 @@ -#if UNITY_EDITOR -using System; -using UnityEditor; -using UnityEngine; - -namespace UnityEngine.InputSystem.Editor -{ - public abstract class InputEnumDrawerBase : PropertyDrawer where T : Enum - { - public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) - { - EditorGUI.BeginProperty(position, label, property); - if (TryGetPopupOptions(property, out string[] popupOptions)) - { - property.intValue = EditorGUILayout.Popup(label, property.intValue, popupOptions); - } - else - { - DisplayDefaultEnum(property, label); - } - EditorGUI.EndProperty(); - } - - protected abstract bool TryGetPopupOptions(SerializedProperty property, out string[] popupOptions); - protected abstract void DisplayDefaultEnum(SerializedProperty property, GUIContent label); - } -} -#endif \ No newline at end of file diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs.meta b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs.meta deleted file mode 100644 index 573b94bfe6..0000000000 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputEnumDrawerBase.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: daecd8281c311144d9d6233a2ee01884 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs deleted file mode 100644 index 6921a9c6f8..0000000000 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs +++ /dev/null @@ -1,55 +0,0 @@ -using UnityEditor; -using UnityEngine.InputSystem.LowLevel; - -namespace UnityEngine.InputSystem.Editor -{ - [CustomPropertyDrawer(typeof(GamepadButton))] - public class InputGamepadButtonDrawer : InputEnumDrawerBase - { - protected override bool TryGetPopupOptions(SerializedProperty property, out string[] popupOptions) - { - - controllerType = (ControllerTypes)EditorGUILayout.EnumPopup("Controller type", controllerType); - string[] options = property.enumDisplayNames; - switch (controllerType) - { - case ControllerTypes.Switch: - options[4] = "X"; - options[5] = "A"; - options[6] = "B"; - options[7] = "Y"; - break; - case ControllerTypes.PlayStation: - options[4] = "Triangle"; - options[5] = "Circle"; - options[6] = "Cross"; - options[7] = "Square"; - break; - case ControllerTypes.Xbox: - options[4] = "Y"; - options[5] = "B"; - options[6] = "A"; - options[7] = "X"; - break; - default: - popupOptions = null; - return false; - } - popupOptions = options; - return true; - } - protected override void DisplayDefaultEnum(SerializedProperty property, GUIContent label) - { - property.intValue = (int)(GamepadButton)EditorGUILayout.EnumPopup(label, (GamepadButton)property.intValue); - } - - private enum ControllerTypes - { - Switch, - PlayStation, - Xbox, - Other - } - private ControllerTypes controllerType; - } -} \ No newline at end of file diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs.meta b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs.meta deleted file mode 100644 index be4b4c2c20..0000000000 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputGamepadButtonDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 4f27e7f15c09b1c489b0964d1f5d9c4d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From 4035fe5243daf02ff7b637bc3f4beceb7e353439 Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Tue, 13 Aug 2024 15:52:49 -0400 Subject: [PATCH 03/10] Added changes to changelog. --- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index e137cd5ba6..0665824785 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -15,6 +15,7 @@ however, it has to be formatted properly to pass verification tests. ### Changed - Use `ProfilerMarker` instead of `Profiler.BeginSample` and `Profiler.EndSample` when appropriate to enable recording of profiling data. +- Removed aliased values in GamepadButton enum. ## [1.10.0] - 2024-07-24 From 3044d28706d5b5db8b916b45a792466e46b0e5c0 Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Wed, 14 Aug 2024 14:26:23 -0400 Subject: [PATCH 04/10] Re-added aliased enums into GamepadButton for compatibility with existing projects. Added custom aliased enum drawer base and custom enum drawer for GamepadButton to hide aliased values. --- .../InputSystem/Devices/Gamepad.cs | 58 +++++++++++++++ .../AliasedEnumPropertyDrawer.cs | 72 +++++++++++++++++++ .../AliasedEnumPropertyDrawer.cs.meta | 11 +++ .../GpadButtonPropertyDrawer.cs | 34 +++++++++ .../GpadButtonPropertyDrawer.cs.meta | 11 +++ 5 files changed, 186 insertions(+) create mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs create mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs.meta create mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs create mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs.meta diff --git a/Packages/com.unity.inputsystem/InputSystem/Devices/Gamepad.cs b/Packages/com.unity.inputsystem/InputSystem/Devices/Gamepad.cs index 5ea43b6fdf..bb74fd4e1d 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Devices/Gamepad.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Devices/Gamepad.cs @@ -326,6 +326,64 @@ public enum GamepadButton /// The right trigger button on a gamepad. /// RightTrigger = 33, + + /// + /// The X button on an Xbox controller. + /// + /// + /// Identical to , which is the generic name of this button. + /// + X = West, + /// + /// The Y button on an Xbox controller. + /// + /// + /// Identical to , which is the generic name of this button. + /// + Y = North, + /// + /// The A button on an Xbox controller. + /// + /// + /// Identical to , which is the generic name of this button. + /// + A = South, + /// + /// The B button on an Xbox controller. + /// + /// + /// Identical to , which is the generic name of this button. + /// + B = East, + + /// + /// The cross button on a PlayStation controller. + /// + /// + /// Identical to , which is the generic name of this button. + /// + Cross = South, + /// + /// The square button on a PlayStation controller. + /// + /// + /// Identical to , which is the generic name of this button. + /// + Square = West, + /// + /// The triangle button on a PlayStation controller. + /// + /// + /// Identical to , which is the generic name of this button. + /// + Triangle = North, + /// + /// The circle button on a PlayStation controller. + /// + /// + /// Identical to , which is the generic name of this button. + /// + Circle = East, } } diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs new file mode 100644 index 0000000000..86d9f59f8a --- /dev/null +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs @@ -0,0 +1,72 @@ +#if UNITY_EDITOR + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Xml.Linq; +using UnityEditor; +using UnityEngine.UIElements; + +namespace UnityEngine.InputSystem.Editor +{ + /// + /// Abstract base class for a generic property drawer for aliased enums. + /// + internal abstract class AliasedEnumPropertyDrawer : PropertyDrawer where T : Enum + { + private string[] m_EnumDisplayNames; + + public override VisualElement CreatePropertyGUI(SerializedProperty property) + { + ProcessDisplayNamesForAliasedEnums(); + return base.CreatePropertyGUI(property); + } + + protected abstract bool TryGetNonAliasedNames(string enumName, string displayName, out string outputName); + + private void ProcessDisplayNamesForAliasedEnums() + { + var enumNamesAndValues = new Dictionary(); + var enumDisplayNames = Enum.GetNames(typeof(T)); + var enumValues = Enum.GetValues(typeof(T)).Cast().ToArray(); + var enumStringValues = enumValues.Select(v => v.ToString()).ToArray(); + for (var i = 0; i < enumDisplayNames.Length; ++i) + { + var enumName = enumDisplayNames[i]; + + if (TryGetNonAliasedNames(enumStringValues[i], enumDisplayNames[i], out string aliasedName)) + { + if (!string.IsNullOrEmpty(aliasedName)) + { + enumName = $"{enumName} ({aliasedName})"; + } + else + { + continue; + } + } + + enumNamesAndValues.Add(enumName, (int)enumValues.GetValue(i)); + } + + var sortedEntries = enumNamesAndValues + .OrderBy(x => x.Value) + .ThenBy(x => x.Key.Contains("(")); + + m_EnumDisplayNames = sortedEntries.Select(x => x.Key).ToArray(); + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + EditorGUI.BeginProperty(position, label, property); + + if (property.propertyType == SerializedPropertyType.Enum) + { + property.enumValueIndex = EditorGUI.Popup(position, label.text, property.enumValueIndex, m_EnumDisplayNames); + } + + EditorGUI.EndProperty(); + } + } +} +#endif // UNITY_EDITOR diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs.meta b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs.meta new file mode 100644 index 0000000000..f9f98aadb8 --- /dev/null +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4bc1abc7badba644ca447c8be9bf055f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs new file mode 100644 index 0000000000..b8de362257 --- /dev/null +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs @@ -0,0 +1,34 @@ +#if UNITY_EDITOR + +using UnityEditor; +using UnityEngine.InputSystem.LowLevel; + +namespace UnityEngine.InputSystem.Editor +{ + /// + /// Property drawer for + /// + [CustomPropertyDrawer(typeof(GamepadButton))] + internal class GpadButtonPropertyDrawer : AliasedEnumPropertyDrawer + { + protected override bool TryGetNonAliasedNames(string enumName, string displayName, out string outputName) + { + outputName = ""; + switch (displayName) + { + case nameof(GamepadButton.Y): + case nameof(GamepadButton.Triangle): + case nameof(GamepadButton.A): + case nameof(GamepadButton.Cross): + case nameof(GamepadButton.B): + case nameof(GamepadButton.Circle): + case nameof(GamepadButton.X): + case nameof(GamepadButton.Square): + return true; + default: + return false; + } + } + } +} +#endif // UNITY_EDITOR diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs.meta b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs.meta new file mode 100644 index 0000000000..c441b453bc --- /dev/null +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5e64ea03a5bf05845977ae0cd2e1dd4f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From e09b57532e33256ea83fb525873662863ae557f9 Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Mon, 9 Sep 2024 15:46:06 -0400 Subject: [PATCH 05/10] Ran the formatter on commit changes. --- Packages/com.unity.inputsystem/CHANGELOG.md | 2 +- .../Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs | 2 +- .../Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 29a299e265..bc3197c305 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -22,7 +22,7 @@ however, it has to be formatted properly to pass verification tests. ### Changed - Use `ProfilerMarker` instead of `Profiler.BeginSample` and `Profiler.EndSample` when appropriate to enable recording of profiling data. -- Removed aliased values in GamepadButton enum. +- Removed aliased values in GamepadButton enum. ### Added - Added Hinge Angle sensor support for foldable devices. diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs index 86d9f59f8a..f747e0d003 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs @@ -1,4 +1,4 @@ -#if UNITY_EDITOR +#if UNITY_EDITOR using System; using System.Collections.Generic; diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs index b8de362257..22752fdc3a 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs @@ -1,4 +1,4 @@ -#if UNITY_EDITOR +#if UNITY_EDITOR using UnityEditor; using UnityEngine.InputSystem.LowLevel; From 1318c70dafccdfec7dc8f90b34e8a31c6b28f7ca Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Fri, 13 Sep 2024 13:32:41 -0400 Subject: [PATCH 06/10] Revert "ISXB-543 Implemented custom drawer base for enums as well as on specific to gamepad buttons. Also removed aliased values in GamepadButton enum" This reverts commit 110e5c6df1671dc258a083a87b2c5bceb47d40c0. # Conflicts: # Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs.meta # Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs.meta --- Assets/Tests/InputSystem/CoreTests_Actions.cs | 6 +++--- Assets/Tests/InputSystem/CoreTests_Devices.cs | 8 ++++---- Assets/Tests/InputSystem/CoreTests_Events.cs | 18 +++++++++--------- Assets/Tests/InputSystem/CoreTests_State.cs | 6 +++--- Assets/Tests/InputSystem/Plugins/UserTests.cs | 2 +- .../InputSystem/Devices/Gamepad.cs | 8 ++++---- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Assets/Tests/InputSystem/CoreTests_Actions.cs b/Assets/Tests/InputSystem/CoreTests_Actions.cs index 5261ad1a96..3106ccf80f 100644 --- a/Assets/Tests/InputSystem/CoreTests_Actions.cs +++ b/Assets/Tests/InputSystem/CoreTests_Actions.cs @@ -4661,7 +4661,7 @@ public void Actions_PressingAndReleasingButtonInSameUpdate_StillTriggersAction() ctx => { ++receivedCalls; }; action.Enable(); - var firstState = new GamepadState {buttons = 1 << (int)GamepadButton.East}; + var firstState = new GamepadState {buttons = 1 << (int)GamepadButton.B}; var secondState = new GamepadState {buttons = 0}; InputSystem.QueueStateEvent(gamepad, firstState); @@ -6925,7 +6925,7 @@ public void Actions_CanDistinguishTapAndSlowTapOnSameAction() trace.SubscribeTo(action); // Perform tap. - InputSystem.QueueStateEvent(gamepad, new GamepadState().WithButton(GamepadButton.South), 0.0); + InputSystem.QueueStateEvent(gamepad, new GamepadState().WithButton(GamepadButton.A), 0.0); InputSystem.QueueStateEvent(gamepad, new GamepadState(), 0.05); InputSystem.Update(); @@ -6942,7 +6942,7 @@ public void Actions_CanDistinguishTapAndSlowTapOnSameAction() trace.Clear(); // Perform slow tap. - InputSystem.QueueStateEvent(gamepad, new GamepadState().WithButton(GamepadButton.South), 2.0); + InputSystem.QueueStateEvent(gamepad, new GamepadState().WithButton(GamepadButton.A), 2.0); InputSystem.QueueStateEvent(gamepad, new GamepadState(), 2.0 + InputSystem.settings.defaultSlowTapTime + 0.0001); InputSystem.Update(); diff --git a/Assets/Tests/InputSystem/CoreTests_Devices.cs b/Assets/Tests/InputSystem/CoreTests_Devices.cs index d2eeee9baa..62b5a9232f 100644 --- a/Assets/Tests/InputSystem/CoreTests_Devices.cs +++ b/Assets/Tests/InputSystem/CoreTests_Devices.cs @@ -4180,7 +4180,7 @@ public void Devices_AreMadeCurrentWhenReceivingStateEvent() Assert.That(Gamepad.current, Is.Not.SameAs(gamepad1)); - InputSystem.QueueStateEvent(gamepad1, new GamepadState().WithButton(GamepadButton.South)); + InputSystem.QueueStateEvent(gamepad1, new GamepadState().WithButton(GamepadButton.A)); InputSystem.Update(); Assert.That(Gamepad.current, Is.SameAs(gamepad1)); @@ -4199,15 +4199,15 @@ public void Devices_AreNotMadeCurrentWhenReceivingStateEventWithNoControlsChange var gamepad1 = InputSystem.AddDevice(); var gamepad2 = InputSystem.AddDevice(); - InputSystem.QueueStateEvent(gamepad1, new GamepadState().WithButton(GamepadButton.South)); + InputSystem.QueueStateEvent(gamepad1, new GamepadState().WithButton(GamepadButton.A)); InputSystem.Update(); Assert.That(Gamepad.current, Is.SameAs(gamepad1)); - InputSystem.QueueStateEvent(gamepad2, new GamepadState().WithButton(GamepadButton.East)); + InputSystem.QueueStateEvent(gamepad2, new GamepadState().WithButton(GamepadButton.B)); InputSystem.Update(); Assert.That(Gamepad.current, Is.SameAs(gamepad2)); - InputSystem.QueueStateEvent(gamepad1, new GamepadState().WithButton(GamepadButton.South)); + InputSystem.QueueStateEvent(gamepad1, new GamepadState().WithButton(GamepadButton.A)); InputSystem.Update(); // If none of the controls changed, a state event shouldn't switch current gamepad. diff --git a/Assets/Tests/InputSystem/CoreTests_Events.cs b/Assets/Tests/InputSystem/CoreTests_Events.cs index 6702003019..6addd65598 100644 --- a/Assets/Tests/InputSystem/CoreTests_Events.cs +++ b/Assets/Tests/InputSystem/CoreTests_Events.cs @@ -103,7 +103,7 @@ public void Events_CanListenForEvents() allButtonPresses.Clear(); Release(gamepad.buttonSouth); - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South, GamepadButton.East)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A, GamepadButton.B)); InputSystem.Update(); Assert.That(callOnceOnButtonPressCount, Is.EqualTo(1)); @@ -135,7 +135,7 @@ public void Events_CanListenForButtonPresses() Assert.That(callCount, Is.Zero); - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A)); InputSystem.Update(); Assert.That(callCount, Is.EqualTo(1)); @@ -145,7 +145,7 @@ public void Events_CanListenForButtonPresses() Assert.That(callCount, Is.EqualTo(1)); - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A)); InputSystem.Update(); Assert.That(callCount, Is.EqualTo(1)); @@ -222,7 +222,7 @@ public void Events_CanGetAllButtonPressesInEvent() controls = eventPtr.GetAllButtonPresses().ToList(); }; - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South, GamepadButton.East)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A, GamepadButton.B)); InputSystem.Update(); Assert.That(controls, Is.EquivalentTo(new[] { gamepad.aButton, gamepad.bButton })); @@ -1319,7 +1319,7 @@ public unsafe void Events_CanTraceEventsOfDevice_AndFilterEventsThroughCallback( trace.Enable(); - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A)); InputSystem.QueueStateEvent(gamepad, default(GamepadState)); InputSystem.Update(); @@ -1338,8 +1338,8 @@ public void Events_CanTraceEventsOfDevice_AndGrowBufferAsNeeded() { trace.Enable(); - InputSystem.QueueStateEvent(device, new GamepadState().WithButton(GamepadButton.South)); - InputSystem.QueueStateEvent(device, new GamepadState().WithButton(GamepadButton.East)); + InputSystem.QueueStateEvent(device, new GamepadState().WithButton(GamepadButton.A)); + InputSystem.QueueStateEvent(device, new GamepadState().WithButton(GamepadButton.B)); InputSystem.Update(); @@ -1358,7 +1358,7 @@ public void Events_CanTraceEventsOfDevice_AndRecordFrameBoundaries() { trace.Enable(); - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A)); InputSystem.Update(); Assert.That(trace.eventCount, Is.EqualTo(2)); @@ -1539,7 +1539,7 @@ public void Events_CanPersistEventTracesInStream() originalTrace.Enable(); InputSystem.QueueStateEvent(pen, new PenState { position = new Vector2(123, 234) }); - InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.South)); + InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A)); InputSystem.QueueStateEvent(pen, new PenState { position = new Vector2(234, 345) }); InputSystem.Update(); diff --git a/Assets/Tests/InputSystem/CoreTests_State.cs b/Assets/Tests/InputSystem/CoreTests_State.cs index 1502188009..8bc38bf728 100644 --- a/Assets/Tests/InputSystem/CoreTests_State.cs +++ b/Assets/Tests/InputSystem/CoreTests_State.cs @@ -424,7 +424,7 @@ public void State_CanUpdateButtonStateUsingEvent() Assert.That(gamepad.buttonEast.isPressed, Is.False); - var newState = new GamepadState {buttons = 1 << (int)GamepadButton.East}; + var newState = new GamepadState {buttons = 1 << (int)GamepadButton.B}; InputSystem.QueueStateEvent(gamepad, newState); InputSystem.Update(); @@ -440,7 +440,7 @@ public void State_CanDetectWhetherButtonStateHasChangedThisFrame() Assert.That(gamepad.buttonEast.wasPressedThisFrame, Is.False); Assert.That(gamepad.buttonEast.wasReleasedThisFrame, Is.False); - var firstState = new GamepadState {buttons = 1 << (int)GamepadButton.East}; + var firstState = new GamepadState {buttons = 1 << (int)GamepadButton.B}; InputSystem.QueueStateEvent(gamepad, firstState); InputSystem.Update(); @@ -472,7 +472,7 @@ public void State_PressingAndReleasingButtonInSameFrame_ShowsStateChange(bool us var gamepad = InputSystem.AddDevice(); - var firstState = new GamepadState {buttons = 1 << (int)GamepadButton.East}; + var firstState = new GamepadState {buttons = 1 << (int)GamepadButton.B}; var secondState = new GamepadState {buttons = 0}; InputSystem.QueueStateEvent(gamepad, firstState); diff --git a/Assets/Tests/InputSystem/Plugins/UserTests.cs b/Assets/Tests/InputSystem/Plugins/UserTests.cs index 7abcaaa158..1a8e13e776 100644 --- a/Assets/Tests/InputSystem/Plugins/UserTests.cs +++ b/Assets/Tests/InputSystem/Plugins/UserTests.cs @@ -942,7 +942,7 @@ public void Users_CanDetectUseOfUnpairedDevice() ++InputUser.listenForUnpairedDeviceActivity; - InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(1, 0)}.WithButton(GamepadButton.South)); + InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(1, 0)}.WithButton(GamepadButton.A)); InputSystem.Update(); Assert.That(receivedControls, Has.Count.EqualTo(2)); diff --git a/Packages/com.unity.inputsystem/InputSystem/Devices/Gamepad.cs b/Packages/com.unity.inputsystem/InputSystem/Devices/Gamepad.cs index bb74fd4e1d..1a6a98c1e9 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Devices/Gamepad.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Devices/Gamepad.cs @@ -255,7 +255,7 @@ public enum GamepadButton /// The upper action button on a gamepad. /// /// - /// Identical to and which are the Xbox and PlayStation controller names for this button. + /// Identical to and which are the Xbox and PlayStation controller names for this button. /// North = 4, @@ -263,7 +263,7 @@ public enum GamepadButton /// The right action button on a gamepad. /// /// - /// Identical to and which are the Xbox and PlayStation controller names for this button. + /// Identical to and which are the Xbox and PlayStation controller names for this button. /// East = 5, @@ -271,7 +271,7 @@ public enum GamepadButton /// The lower action button on a gamepad. /// /// - /// Identical to and which are the Xbox and PlayStation controller names for this button. + /// Identical to and which are the Xbox and PlayStation controller names for this button. /// South = 6, @@ -279,7 +279,7 @@ public enum GamepadButton /// The left action button on a gamepad. /// /// - /// Identical to and which are the Xbox and PlayStation controller names for this button. + /// Identical to and which are the Xbox and PlayStation controller names for this button. /// West = 7, From e7e69d38ea90eca43b26ad8d4f47077b75af92e7 Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Mon, 16 Sep 2024 14:47:40 -0400 Subject: [PATCH 07/10] Reworked GpadButtonPropertyDrawer according to feedback. Removed general AliasedEnumPropertyDrawer script. --- .../AliasedEnumPropertyDrawer.cs | 72 ----------------- .../AliasedEnumPropertyDrawer.cs.meta | 11 --- .../GpadButtonPropertyDrawer.cs | 80 +++++++++++++++---- 3 files changed, 64 insertions(+), 99 deletions(-) delete mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs delete mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs.meta diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs deleted file mode 100644 index f747e0d003..0000000000 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs +++ /dev/null @@ -1,72 +0,0 @@ -#if UNITY_EDITOR - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Xml.Linq; -using UnityEditor; -using UnityEngine.UIElements; - -namespace UnityEngine.InputSystem.Editor -{ - /// - /// Abstract base class for a generic property drawer for aliased enums. - /// - internal abstract class AliasedEnumPropertyDrawer : PropertyDrawer where T : Enum - { - private string[] m_EnumDisplayNames; - - public override VisualElement CreatePropertyGUI(SerializedProperty property) - { - ProcessDisplayNamesForAliasedEnums(); - return base.CreatePropertyGUI(property); - } - - protected abstract bool TryGetNonAliasedNames(string enumName, string displayName, out string outputName); - - private void ProcessDisplayNamesForAliasedEnums() - { - var enumNamesAndValues = new Dictionary(); - var enumDisplayNames = Enum.GetNames(typeof(T)); - var enumValues = Enum.GetValues(typeof(T)).Cast().ToArray(); - var enumStringValues = enumValues.Select(v => v.ToString()).ToArray(); - for (var i = 0; i < enumDisplayNames.Length; ++i) - { - var enumName = enumDisplayNames[i]; - - if (TryGetNonAliasedNames(enumStringValues[i], enumDisplayNames[i], out string aliasedName)) - { - if (!string.IsNullOrEmpty(aliasedName)) - { - enumName = $"{enumName} ({aliasedName})"; - } - else - { - continue; - } - } - - enumNamesAndValues.Add(enumName, (int)enumValues.GetValue(i)); - } - - var sortedEntries = enumNamesAndValues - .OrderBy(x => x.Value) - .ThenBy(x => x.Key.Contains("(")); - - m_EnumDisplayNames = sortedEntries.Select(x => x.Key).ToArray(); - } - - public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) - { - EditorGUI.BeginProperty(position, label, property); - - if (property.propertyType == SerializedPropertyType.Enum) - { - property.enumValueIndex = EditorGUI.Popup(position, label.text, property.enumValueIndex, m_EnumDisplayNames); - } - - EditorGUI.EndProperty(); - } - } -} -#endif // UNITY_EDITOR diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs.meta b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs.meta deleted file mode 100644 index f9f98aadb8..0000000000 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 4bc1abc7badba644ca447c8be9bf055f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs index 22752fdc3a..9b7e58d04f 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs @@ -1,7 +1,11 @@ #if UNITY_EDITOR -using UnityEditor; +using System; +using System.Collections.Generic; +using System.Linq; using UnityEngine.InputSystem.LowLevel; +using UnityEditor; +using UnityEngine.UIElements; namespace UnityEngine.InputSystem.Editor { @@ -9,25 +13,69 @@ namespace UnityEngine.InputSystem.Editor /// Property drawer for /// [CustomPropertyDrawer(typeof(GamepadButton))] - internal class GpadButtonPropertyDrawer : AliasedEnumPropertyDrawer + internal class GpadButtonPropertyDrawer : PropertyDrawer { - protected override bool TryGetNonAliasedNames(string enumName, string displayName, out string outputName) + private string[] m_EnumDisplayNames; + + public override VisualElement CreatePropertyGUI(SerializedProperty property) + { + var enumNamesAndValues = new Dictionary(); + var enumDisplayNames = Enum.GetNames(typeof(GamepadButton)); + var enumValues = Enum.GetValues(typeof(GamepadButton)).Cast().ToArray(); + + for (var i = 0; i < enumDisplayNames.Length; ++i) + { + string enumName = enumDisplayNames[i]; + + switch (enumName) + { + case nameof(GamepadButton.Y): + case nameof(GamepadButton.Triangle): + case nameof(GamepadButton.A): + case nameof(GamepadButton.Cross): + case nameof(GamepadButton.B): + case nameof(GamepadButton.Circle): + case nameof(GamepadButton.X): + case nameof(GamepadButton.Square): + enumName = null; + break; + case nameof(GamepadButton.North): + enumName = "North, Y, Triangle, X"; + break; + case nameof(GamepadButton.South): + enumName = "South, A, Cross, B"; + break; + case nameof(GamepadButton.East): + enumName = "East, B, Circle, A"; + break; + case nameof(GamepadButton.West): + enumName = "West, X, Square, Y"; + break; + default: + break; + } + + if (enumName != null) + { + enumNamesAndValues.Add(enumName, (int)enumValues.GetValue(i)); + } + } + var sortedEntries = enumNamesAndValues.OrderBy(x => x.Value); + + m_EnumDisplayNames = sortedEntries.Select(x => x.Key).ToArray(); + return base.CreatePropertyGUI(property); + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { - outputName = ""; - switch (displayName) + EditorGUI.BeginProperty(position, label, property); + + if (property.propertyType == SerializedPropertyType.Enum) { - case nameof(GamepadButton.Y): - case nameof(GamepadButton.Triangle): - case nameof(GamepadButton.A): - case nameof(GamepadButton.Cross): - case nameof(GamepadButton.B): - case nameof(GamepadButton.Circle): - case nameof(GamepadButton.X): - case nameof(GamepadButton.Square): - return true; - default: - return false; + property.intValue = EditorGUI.Popup(position, label.text, property.intValue, m_EnumDisplayNames); } + + EditorGUI.EndProperty(); } } } From dd2de3742d3ca3293d1a155ef1d4223325aad679 Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Wed, 18 Sep 2024 10:39:58 -0400 Subject: [PATCH 08/10] Fixed GamepadButtonPropertyDrawer issues based on PR feedback. -Renamed GpadButtonPropertyDrawer to GamepadButtonPropertyDrawer. -Fixed nullref issue caused by m_EnumDisplayNames being reset when entering/exiting play mode. -Simplified code for setting up enum list. -Updated CHANGELOG.md --- Packages/com.unity.inputsystem/CHANGELOG.md | 2 +- ...awer.cs => GamepadButtonPropertyDrawer.cs} | 55 ++++++++++--------- ...ta => GamepadButtonPropertyDrawer.cs.meta} | 0 3 files changed, 31 insertions(+), 26 deletions(-) rename Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/{GpadButtonPropertyDrawer.cs => GamepadButtonPropertyDrawer.cs} (83%) rename Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/{GpadButtonPropertyDrawer.cs.meta => GamepadButtonPropertyDrawer.cs.meta} (100%) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 18d295a9f3..ef07b1956a 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -32,7 +32,7 @@ however, it has to be formatted properly to pass verification tests. ### Changed - Use `ProfilerMarker` instead of `Profiler.BeginSample` and `Profiler.EndSample` when appropriate to enable recording of profiling data. -- Removed aliased values in GamepadButton enum. +- Changed representation of GamepadButton enum values in Inspector to display aliased enum values as a single item to avoid confusion around selection and aliased value display when multiple enum items map to the same numerical value. ### Added - Added Hinge Angle sensor support for foldable devices. diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GamepadButtonPropertyDrawer.cs similarity index 83% rename from Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs rename to Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GamepadButtonPropertyDrawer.cs index 9b7e58d04f..6475b6d400 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GamepadButtonPropertyDrawer.cs @@ -13,11 +13,32 @@ namespace UnityEngine.InputSystem.Editor /// Property drawer for /// [CustomPropertyDrawer(typeof(GamepadButton))] - internal class GpadButtonPropertyDrawer : PropertyDrawer + internal class GamepadButtonPropertyDrawer : PropertyDrawer { - private string[] m_EnumDisplayNames; - public override VisualElement CreatePropertyGUI(SerializedProperty property) + { + CreateEnumList(); + return base.CreatePropertyGUI(property); + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + EditorGUI.BeginProperty(position, label, property); + + if (m_EnumDisplayNames == null) + { + CreateEnumList(); + } + + if (property.propertyType == SerializedPropertyType.Enum) + { + property.intValue = EditorGUI.Popup(position, label.text, property.intValue, m_EnumDisplayNames); + } + + EditorGUI.EndProperty(); + } + + private void CreateEnumList() { var enumNamesAndValues = new Dictionary(); var enumDisplayNames = Enum.GetNames(typeof(GamepadButton)); @@ -25,9 +46,8 @@ public override VisualElement CreatePropertyGUI(SerializedProperty property) for (var i = 0; i < enumDisplayNames.Length; ++i) { - string enumName = enumDisplayNames[i]; - - switch (enumName) + string enumName; + switch (enumDisplayNames[i]) { case nameof(GamepadButton.Y): case nameof(GamepadButton.Triangle): @@ -37,8 +57,7 @@ public override VisualElement CreatePropertyGUI(SerializedProperty property) case nameof(GamepadButton.Circle): case nameof(GamepadButton.X): case nameof(GamepadButton.Square): - enumName = null; - break; + continue; case nameof(GamepadButton.North): enumName = "North, Y, Triangle, X"; break; @@ -52,31 +71,17 @@ public override VisualElement CreatePropertyGUI(SerializedProperty property) enumName = "West, X, Square, Y"; break; default: + enumName = enumDisplayNames[i]; break; } - - if (enumName != null) - { - enumNamesAndValues.Add(enumName, (int)enumValues.GetValue(i)); - } + enumNamesAndValues.Add(enumName, (int)enumValues.GetValue(i)); } var sortedEntries = enumNamesAndValues.OrderBy(x => x.Value); m_EnumDisplayNames = sortedEntries.Select(x => x.Key).ToArray(); - return base.CreatePropertyGUI(property); } - public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) - { - EditorGUI.BeginProperty(position, label, property); - - if (property.propertyType == SerializedPropertyType.Enum) - { - property.intValue = EditorGUI.Popup(position, label.text, property.intValue, m_EnumDisplayNames); - } - - EditorGUI.EndProperty(); - } + private string[] m_EnumDisplayNames; } } #endif // UNITY_EDITOR diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs.meta b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GamepadButtonPropertyDrawer.cs.meta similarity index 100% rename from Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs.meta rename to Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GamepadButtonPropertyDrawer.cs.meta From d3fa10ed59a876f97ab0f4c54da846ed8ab52d0a Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Thu, 19 Sep 2024 09:18:31 -0400 Subject: [PATCH 09/10] Moved changelog entry for ISXB-543 into correct version and added link to jira. --- Packages/com.unity.inputsystem/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index ef07b1956a..97e3bd7ec9 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -16,6 +16,7 @@ however, it has to be formatted properly to pass verification tests. ### Changed - Renamed editor Resources directories to PackageResources to fix package validation warnings. +- Changed representation of GamepadButton enum values in Inspector to display aliased enum values as a single item to avoid confusion around selection and aliased value display when multiple enum items map to the same numerical value. [ISXB-543](https://jira.unity3d.com/browse/ISXB-543) ## [1.11.0] - 2024-09-10 @@ -32,7 +33,6 @@ however, it has to be formatted properly to pass verification tests. ### Changed - Use `ProfilerMarker` instead of `Profiler.BeginSample` and `Profiler.EndSample` when appropriate to enable recording of profiling data. -- Changed representation of GamepadButton enum values in Inspector to display aliased enum values as a single item to avoid confusion around selection and aliased value display when multiple enum items map to the same numerical value. ### Added - Added Hinge Angle sensor support for foldable devices. From fc85832289eb81381081c1dd4bdd5608552a87bd Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Thu, 19 Sep 2024 09:35:36 -0400 Subject: [PATCH 10/10] Changed jira link in changelog for ISXB-543 to public issue tracker. --- Packages/com.unity.inputsystem/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 97e3bd7ec9..bf238bff51 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -16,7 +16,7 @@ however, it has to be formatted properly to pass verification tests. ### Changed - Renamed editor Resources directories to PackageResources to fix package validation warnings. -- Changed representation of GamepadButton enum values in Inspector to display aliased enum values as a single item to avoid confusion around selection and aliased value display when multiple enum items map to the same numerical value. [ISXB-543](https://jira.unity3d.com/browse/ISXB-543) +- Changed representation of GamepadButton enum values in Inspector to display aliased enum values as a single item to avoid confusion around selection and aliased value display when multiple enum items map to the same numerical value. [ISXB-543](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-543) ## [1.11.0] - 2024-09-10