Skip to content
Closed
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 @@ -68,6 +68,7 @@ however, it has to be formatted properly to pass verification tests.
- Fixed duplication of project wide input actions when loading/unloading scenes.
- Fixed an issue in the Input Action Editor window where entries being cut would be deleted instantly and not after being pasted.
- Fixed an issue where preloaded InputActionAsset objects added by a Unity developer could accidentally be selected as the project-wide actions asset instead of the configured asset in built players.
- Fixed an issue where aliased enum values for ´GamepadButton´ would be seemingly randomly picked from an Inspector value picker. This is resolved with a custom property drawer that maps to a designated aliased type. [ISXB-543](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-543).

## [1.8.0-pre.2] - 2023-11-09

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#if UNITY_EDITOR

using System;
using System.Collections.Generic;
using System.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;

protected abstract string GetNonAliasedNames(string enumValue);

private void Initialize()
{
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];
var aliasedName = GetNonAliasedNames(enumStringValues[i]);
if (!string.IsNullOrEmpty(aliasedName) && enumName != aliasedName)
enumName = $"{enumName} ({aliasedName})";

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)
{
if (m_EnumDisplayNames == null)
Initialize();

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,43 @@
#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 string GetNonAliasedNames(string name)
{
switch (name)
{
case nameof(GamepadButton.North):
case nameof(GamepadButton.Y):
case nameof(GamepadButton.Triangle):
return nameof(GamepadButton.North);

case nameof(GamepadButton.South):
case nameof(GamepadButton.A):
case nameof(GamepadButton.Cross):
return nameof(GamepadButton.South);

case nameof(GamepadButton.East):
case nameof(GamepadButton.B):
case nameof(GamepadButton.Circle):
return nameof(GamepadButton.East);

case nameof(GamepadButton.West):
case nameof(GamepadButton.X):
case nameof(GamepadButton.Square):
return nameof(GamepadButton.West);

default: return string.Empty;
}
}
}
}
#endif // UNITY_EDITOR

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.