Skip to content

Commit 774190a

Browse files
committed
Address PR feedbacks, changelog changed, test name modified, comments added, made classes and enums internal and refactor.
1 parent a06e9d3 commit 774190a

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

Assets/Tests/InputSystem.Editor/CustomProcessorEnumTest.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS && UNITY_6000_0_OR_NEWER
1+
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
22

33
using System;
44
using NUnit.Framework;
@@ -11,18 +11,16 @@
1111
using UnityEngine.TestTools;
1212
using UnityEngine.UIElements;
1313

14-
public enum SomeEnum
14+
internal enum SomeEnum
1515
{
1616
OptionA = 10,
17-
OptionB = 20,
18-
OptionC = 50,
19-
OptionD = 100
17+
OptionB = 20
2018
}
2119

2220
#if UNITY_EDITOR
2321
[InitializeOnLoad]
2422
#endif
25-
public class CustomProcessor : InputProcessor<float>
23+
internal class CustomProcessor : InputProcessor<float>
2624
{
2725
public SomeEnum SomeEnum;
2826

@@ -72,38 +70,39 @@ public override IEnumerator UnitySetup()
7270
}
7371

7472
[UnityTest]
75-
public IEnumerator CustomProcessorEnum_SerialiseTheValue_InAsset()
73+
public IEnumerator ProcessorEnum_ShouldSerializeByValue_WhenSerializedToAsset()
7674
{
75+
// Serialize current asset to JSON, and check that initial JSON contains default enum value for OptionA
7776
var json = m_Window.currentAssetInEditor.ToJson();
7877

7978
Assert.That(json.Contains("Custom(SomeEnum=10)"), Is.True,
8079
"Serialized JSON does not contain the expected custom processor string for OptionA.");
81-
82-
var dropdownList = m_Window.rootVisualElement.Query<DropdownField>().Where(d => d.choices != null && d.choices.Contains("OptionA") && d.choices.Contains("OptionB")).ToList();
80+
81+
// Query the dropdown with exactly two enum choices and check that the drop down is present in the UI
82+
var dropdownList = m_Window.rootVisualElement.Query<DropdownField>().Where(d => d.choices.Count == 2).ToList();
8383
Assume.That(dropdownList.Count > 0, Is.True, "Enum parameter dropdown not found in the UI.");
8484

85+
// Determine the new value to be set in the dropdown, focus the dropdown before dispatching the change
8586
var dropdown = dropdownList.First();
86-
87-
var newIndex = dropdown.choices.IndexOf("OptionB");
88-
var oldValue = dropdown.value;
89-
var newValue = dropdown.choices[newIndex];
90-
87+
var newValue = dropdown.choices[1];
9188
dropdown.Focus();
9289
dropdown.value = newValue;
9390

94-
var changeEvent = ChangeEvent<Enum>.GetPooled(SomeEnum.OptionA, SomeEnum.OptionC);
91+
// Create and send a change event from OptionA to OptionB
92+
var changeEvent = ChangeEvent<Enum>.GetPooled(SomeEnum.OptionA, SomeEnum.OptionB);
9593
changeEvent.target = dropdown;
9694
dropdown.SendEvent(changeEvent);
9795

96+
// Find the save button in the window, focus and click the save button to persist the changes
9897
var saveButton = m_Window.rootVisualElement.Q<Button>("save-asset-toolbar-button");
9998
Assume.That(saveButton, Is.Not.Null, "Save Asset button not found in the UI.");
10099
saveButton.Focus();
101100
SimulateClickOn(saveButton);
102101

103102
Assert.That(dropdown.value, Is.EqualTo(newValue));
104103

104+
// Verify that the updated JSON contains the new enum value for OpitonB
105105
var updatedJson = m_Window.currentAssetInEditor.ToJson();
106-
107106
Assert.That(updatedJson.Contains("Custom(SomeEnum=20)"), Is.True, "Serialized JSON does not contain the updated custom processor string for OptionB.");
108107

109108
yield return null;

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ however, it has to be formatted properly to pass verification tests.
2222
- Fixed Inspector Window being refreshed all the time when a PlayerInput component is present with Invoke Unity Events nofication mode chosen [ISXB-1448](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1448)
2323
- Fixed an issue where an action with a name containing a slash "/" could not be found via `InputActionAsset.FindAction(string,bool)`. [ISXB-1306](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1306).
2424
- Fixed Gamepad stick up/down inputs that were not recognized in WebGL. [ISXB-1090](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1090)
25-
- Fixed Action with custom processor serialises enums by index rather than by value. [ISXB-1474](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1474)
25+
- Fixed an issue that caused input processors with enum properties to incorrectly serialise by index instead of by value [ISXB-1474](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1474)
2626

2727
## [1.14.0] - 2025-03-20
2828

0 commit comments

Comments
 (0)