-
Notifications
You must be signed in to change notification settings - Fork 328
CHANGE: Removed aliased values in Gamepad enum. (ISXB-543) #1983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
110e5c6
50f2a47
4035fe5
60640fb
3044d28
6e50417
e09b575
a964957
806f943
1318c70
5f1b160
e7e69d3
d85c1ed
dd2de37
d3fa10e
fc85832
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,7 +103,7 @@ public void Events_CanListenForEvents() | |
allButtonPresses.Clear(); | ||
|
||
Release(gamepad.buttonSouth); | ||
InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A, GamepadButton.B)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not expecting any changes needed to this file |
||
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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -424,7 +424,7 @@ public void State_CanUpdateButtonStateUsingEvent() | |
|
||
Assert.That(gamepad.buttonEast.isPressed, Is.False); | ||
|
||
var newState = new GamepadState {buttons = 1 << (int)GamepadButton.B}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not expecting any changes needed to this file |
||
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<Gamepad>(); | ||
|
||
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); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -942,7 +942,7 @@ public void Users_CanDetectUseOfUnpairedDevice() | |
|
||
++InputUser.listenForUnpairedDeviceActivity; | ||
|
||
InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(1, 0)}.WithButton(GamepadButton.A)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't need to change either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is due to my first pass where I removed the aliased values. Will revert |
||
InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(1, 0)}.WithButton(GamepadButton.South)); | ||
InputSystem.Update(); | ||
|
||
Assert.That(receivedControls, Has.Count.EqualTo(2)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,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. | ||
|
||
|
||
### Added | ||
- Added Hinge Angle sensor support for foldable devices. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,31 +255,31 @@ public enum GamepadButton | |
/// The upper action button on a gamepad. | ||
/// </summary> | ||
/// <remarks> | ||
/// Identical to <see cref="Y"/> and <see cref="Triangle"/> which are the Xbox and PlayStation controller names for this button. | ||
/// Identical to <see cref="North"/> and <see cref="North"/> which are the Xbox and PlayStation controller names for this button. | ||
|
||
/// </remarks> | ||
North = 4, | ||
|
||
/// <summary> | ||
/// The right action button on a gamepad. | ||
/// </summary> | ||
/// <remarks> | ||
/// Identical to <see cref="B"/> and <see cref="Circle"/> which are the Xbox and PlayStation controller names for this button. | ||
/// Identical to <see cref="East"/> and <see cref="East"/> which are the Xbox and PlayStation controller names for this button. | ||
/// </remarks> | ||
East = 5, | ||
|
||
/// <summary> | ||
/// The lower action button on a gamepad. | ||
/// </summary> | ||
/// <remarks> | ||
/// Identical to <see cref="A"/> and <see cref="Cross"/> which are the Xbox and PlayStation controller names for this button. | ||
/// Identical to <see cref="South"/> and <see cref="South"/> which are the Xbox and PlayStation controller names for this button. | ||
/// </remarks> | ||
South = 6, | ||
|
||
/// <summary> | ||
/// The left action button on a gamepad. | ||
/// </summary> | ||
/// <remarks> | ||
/// Identical to <see cref="X"/> and <see cref="Square"/> which are the Xbox and PlayStation controller names for this button. | ||
/// Identical to <see cref="West"/> and <see cref="West"/> which are the Xbox and PlayStation controller names for this button. | ||
/// </remarks> | ||
West = 7, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// Abstract base class for a generic property drawer for aliased enums. | ||
/// </summary> | ||
internal abstract class AliasedEnumPropertyDrawer<T> : 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<string, int>(); | ||
|
||
var enumDisplayNames = Enum.GetNames(typeof(T)); | ||
var enumValues = Enum.GetValues(typeof(T)).Cast<T>().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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#if UNITY_EDITOR | ||
|
||
using UnityEditor; | ||
using UnityEngine.InputSystem.LowLevel; | ||
|
||
namespace UnityEngine.InputSystem.Editor | ||
{ | ||
/// <summary> | ||
/// Property drawer for <see cref = "GamepadButton" /> | ||
/// </summary > | ||
[CustomPropertyDrawer(typeof(GamepadButton))] | ||
internal class GpadButtonPropertyDrawer : AliasedEnumPropertyDrawer<GamepadButton> | ||
{ | ||
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix shouldn't have any impact on existing tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hence I wouldn't expect any changes to any tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is due to my first pass where I removed the aliased values. Will revert