-
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 12 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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#if UNITY_EDITOR | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEngine.InputSystem.LowLevel; | ||
using UnityEditor; | ||
using UnityEngine.UIElements; | ||
|
||
namespace UnityEngine.InputSystem.Editor | ||
{ | ||
/// <summary> | ||
/// Property drawer for <see cref = "GamepadButton" /> | ||
/// </summary > | ||
[CustomPropertyDrawer(typeof(GamepadButton))] | ||
internal class GpadButtonPropertyDrawer : PropertyDrawer | ||
|
||
{ | ||
private string[] m_EnumDisplayNames; | ||
|
||
public override VisualElement CreatePropertyGUI(SerializedProperty property) | ||
{ | ||
var enumNamesAndValues = new Dictionary<string, int>(); | ||
var enumDisplayNames = Enum.GetNames(typeof(GamepadButton)); | ||
var enumValues = Enum.GetValues(typeof(GamepadButton)).Cast<GamepadButton>().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) | ||
{ | ||
EditorGUI.BeginProperty(position, label, property); | ||
|
||
if (property.propertyType == SerializedPropertyType.Enum) | ||
{ | ||
property.intValue = EditorGUI.Popup(position, label.text, property.intValue, m_EnumDisplayNames); | ||
} | ||
|
||
EditorGUI.EndProperty(); | ||
} | ||
} | ||
} | ||
#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.
This should be reverted as well, suggest to change to something like e.g. "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."