Skip to content
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

Fixed GamepadButton.LeftTrigger and GamepadButton.RightTrigger enum v… #2100

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ however, it has to be formatted properly to pass verification tests.
## [Unreleased] - yyyy-mm-dd

### Fixed
- Fixed GamepadButton.LeftTrigger and GamepadButton.RightTrigger enum values not matching displayed dropdown values in editor when using GamepadButtonPropertyDrawer [ISXB-1270](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1270).
- Fixed an issue causing the Action context menu to not show on right click when right clicking an action in the Input Action Editor [ISXB-1134](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1134).
- Reverted changes from 0ddd534d8 (ISXB-746) which introduced a regression [ISXB-1127](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1127).
- Fixed `ArgumentNullException: Value cannot be null.` during the migration of Project-wide Input Actions from `InputManager.asset` to `InputSystem_Actions.inputactions` asset which lead do the lost of the configuration [ISXB-1105](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1105).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#if UNITY_EDITOR

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.InputSystem.LowLevel;
using UnityEditor;
using UnityEngine.UIElements;
using System;
using System.Collections.Generic;
using UnityEngine.InputSystem.LowLevel;
using UnityEditor;
using UnityEngine.UIElements;

#if UNITY_EDITOR
namespace UnityEngine.InputSystem.Editor
{
/// <summary>
Expand All @@ -32,17 +30,17 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten

if (property.propertyType == SerializedPropertyType.Enum)
{
property.intValue = EditorGUI.Popup(position, label.text, property.intValue, m_EnumDisplayNames);
property.intValue = m_EnumValues[EditorGUI.Popup(position, label.text, GetEnumIndex(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();
string[] enumDisplayNames = Enum.GetNames(typeof(GamepadButton));
var enumValues = Enum.GetValues(typeof(GamepadButton));
var enumNamesAndValues = new Dictionary<string, int>(enumDisplayNames.Length);

for (var i = 0; i < enumDisplayNames.Length; ++i)
{
Expand Down Expand Up @@ -76,12 +74,53 @@ private void CreateEnumList()
}
enumNamesAndValues.Add(enumName, (int)enumValues.GetValue(i));
}
var sortedEntries = enumNamesAndValues.OrderBy(x => x.Value);
SetEnumDisplayNames(enumNamesAndValues);
}

private void SetEnumDisplayNames(Dictionary<string, int> enumNamesAndValues)
{
m_EnumValues = new int[enumNamesAndValues.Count];

m_EnumDisplayNames = new string[enumNamesAndValues.Count];
int currentIndex = 0;

int tempInt;
string tempString;

m_EnumDisplayNames = sortedEntries.Select(x => x.Key).ToArray();
foreach (KeyValuePair<string, int> kvp in enumNamesAndValues)
{
int tempIndex = currentIndex;
m_EnumDisplayNames[currentIndex] = kvp.Key;
m_EnumValues[currentIndex] = kvp.Value;
while (tempIndex != 0 && m_EnumValues[currentIndex] < m_EnumValues[tempIndex - 1])
{
tempInt = m_EnumValues[tempIndex - 1];
m_EnumValues[tempIndex - 1] = m_EnumValues[currentIndex];
m_EnumValues[currentIndex] = tempInt;

tempString = m_EnumDisplayNames[tempIndex - 1];
m_EnumDisplayNames[tempIndex - 1] = m_EnumDisplayNames[currentIndex];
m_EnumDisplayNames[currentIndex] = tempString;
tempIndex--;
}
currentIndex++;
}
}

private int GetEnumIndex(int enumValue)
{
for (int i = 0; i<m_EnumValues.Length; i++)
{
if (enumValue == m_EnumValues[i])
{
return i;
}
}
return 0;
}

private int[] m_EnumValues;
private string[] m_EnumDisplayNames;
}
}
#endif // UNITY_EDITOR
}
}
#endif // UNITY_EDITOR
Loading