-
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
110e5c6
ISXB-543 Implemented custom drawer base for enums as well as on spe…
adrian-koretski-unity3d 50f2a47
Removed custom enum drawer.
adrian-koretski-unity3d 4035fe5
Added changes to changelog.
adrian-koretski-unity3d 60640fb
Merge branch 'develop' into isxb-543
adrian-koretski-unity3d 3044d28
Re-added aliased enums into GamepadButton for compatibility with exis…
adrian-koretski-unity3d 6e50417
Merge branch 'develop' of https://github.com/Unity-Technologies/Input…
adrian-koretski-unity3d e09b575
Ran the formatter on commit changes.
adrian-koretski-unity3d a964957
Merge branch 'develop' into isxb-543
adrian-koretski-unity3d 806f943
Merge branch 'develop' into isxb-543
adrian-koretski-unity3d 1318c70
Revert "ISXB-543 Implemented custom drawer base for enums as well a…
adrian-koretski-unity3d 5f1b160
Merge branch 'isxb-543' of https://github.com/Unity-Technologies/Inpu…
adrian-koretski-unity3d e7e69d3
Reworked GpadButtonPropertyDrawer according to feedback.
adrian-koretski-unity3d d85c1ed
Merge branch 'develop' into isxb-543
adrian-koretski-unity3d dd2de37
Fixed GamepadButtonPropertyDrawer issues based on PR feedback.
adrian-koretski-unity3d d3fa10e
Moved changelog entry for ISXB-543 into correct version and added lin…
adrian-koretski-unity3d fc85832
Changed jira link in changelog for ISXB-543 to public issue tracker.
adrian-koretski-unity3d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...s/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GamepadButtonPropertyDrawer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#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 GamepadButtonPropertyDrawer : PropertyDrawer | ||
{ | ||
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<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; | ||
switch (enumDisplayNames[i]) | ||
{ | ||
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): | ||
continue; | ||
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: | ||
enumName = enumDisplayNames[i]; | ||
break; | ||
} | ||
enumNamesAndValues.Add(enumName, (int)enumValues.GetValue(i)); | ||
} | ||
var sortedEntries = enumNamesAndValues.OrderBy(x => x.Value); | ||
|
||
m_EnumDisplayNames = sortedEntries.Select(x => x.Key).ToArray(); | ||
} | ||
|
||
private string[] m_EnumDisplayNames; | ||
} | ||
} | ||
#endif // UNITY_EDITOR |
11 changes: 11 additions & 0 deletions
11
....unity.inputsystem/InputSystem/Editor/PropertyDrawers/GamepadButtonPropertyDrawer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Changelog entry in the wrong version and no bug issue link