-
Notifications
You must be signed in to change notification settings - Fork 323
NEW: Object picker for InputActionReference combining results from Project-wide Input Actions Asset and Project Input Actions Assets #1768
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
Conversation
…cking InputReference
…ed project-wide actions icon to use sub-asset icon from InputActionImporter
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.
Overall this is what I was expecting from the original task on this area
(https://jira.unity3d.com/browse/ISX-1321)
So looks good IMO.
I would generally approved the PR with a small comment on some duplicate code.
We do need to agree where backend data is stored asset vs project settings as we still have other issues with this project settings storage
- the bug with the UI when storing data in project settings (https://jira.unity3d.com/browse/ISX-1600)
- the issue with code generation requiring a file in the assets folder (in part https://jira.unity3d.com/browse/ISX-1635)
- potential standardisation for users with storing data as an asset.
- Issue with template file showing up in asset selectors (https://jira.unity3d.com/browse/ISX-1588)
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
using System.Collections; |
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.
3 duplicated lines here
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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AssetSearchProviders.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AssetSearchProviders.cs
Outdated
Show resolved
Hide resolved
asset.GetInstanceID().ToString(), | ||
label, | ||
$"{AssetDatabase.GetAssetPath(asset)} ({label})", | ||
(thumbnail == null) ? AssetDatabase.GetCachedIcon(ProjectWideActionsAsset.kAssetPath) as Texture2D : thumbnail, |
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.
I like that we have a new icon to indicate the project wide ones
These icons seem to update at I'm viewing the UI which is a bit distracting.
(Would be nice if it was at least blank before updating to reduce distraction.)
I think this is potentially a UI issue outside the scope of this PR though.
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.
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.
Thing is we do not have any new icons, I just used the one registered with asset database. The icon (blue+orange) is the .inputactions icon registered by InputActionImporter. This should really be the way to fetch it (the default value handling I have in the code). However the "Flash icon" is what is I currently set for the Project-wide in this search. That is currently used with .inputactions sub-assets (InputActions), but it could be debated what to use. I see the choice of icon as minor for this PR and could be addressed separately. However I propose here to differentiate assets and project-wide for increased visual cue.
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.
The magnifying glass is a default icon from the SearchProvider
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.
@lyndon-unity Do you see Input Action Icon (Flash) in Project-Wide Input Actions search group?
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.
I like that we have a new icon to indicate the project wide ones
These icons seem to update at I'm viewing the UI which is a bit distracting. (Would be nice if it was at least blank before updating to reduce distraction.)
I think this is potentially a UI issue outside the scope of this PR though.
Not sure was this was referring to? I need to understand this to address it I believe
@@ -29,8 +29,8 @@ internal class InputActionImporter : ScriptedImporter | |||
{ | |||
private const int kVersion = 13; | |||
|
|||
private const string kActionIcon = "Packages/com.unity.inputsystem/InputSystem/Editor/Icons/InputAction.png"; | |||
private const string kAssetIcon = "Packages/com.unity.inputsystem/InputSystem/Editor/Icons/InputActionAsset.png"; | |||
internal const string kActionIcon = "Packages/com.unity.inputsystem/InputSystem/Editor/Icons/InputAction.png"; |
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.
Thinking about it, it likely makes sense to either have internal access on importer to load/fetch Texture2D instead or move these or such logic to its own class.
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.
Even better is relying on AssetDatabase.GetCachedIcon but this doesn't seem to do the job for sub-assets. Might need more investigation.
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.
Requesting a change of whats listed
Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AssetSearchProviders.cs
Outdated
Show resolved
Hide resolved
…Reduced scopes and made internal dependencies restricted in scope. Moved icon handling out of InputActionAssetImporter.
@@ -10,18 +10,18 @@ namespace UnityEngine.InputSystem.Editor | |||
{ | |||
internal static class ProjectWideActionsAsset |
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 refactoring doesn't provide value for the PR other than that it reduces use of internals and eliminates redundant similar code.
…detail moved to ProjectWideInputActionsAsset
…stem into inspector-poc
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.
Updates looks good
Going to comment on this myself, this branch needs auto-tests to verify behaviour. |
Transitioning this back to work-in-progress again unfortunately since I have detected issues with UI behavior that needs follow-up. Seems to be possible to work around but needs verification that we are not relying on side-effects from Search-related bugs. |
[Test] | ||
[Category("Actions")] | ||
public void Actions_CanResolveActionReference_WhenUsingToInputActionToConstructANewReference() | ||
{ | ||
var map = new InputActionMap("map"); | ||
map.AddAction("action1"); | ||
var action2 = map.AddAction("action2"); | ||
var asset = ScriptableObject.CreateInstance<InputActionAsset>(); | ||
asset.AddActionMap(map); | ||
|
||
var reference = ScriptableObject.CreateInstance<InputActionReference>(); | ||
reference.Set(asset, "map", "action2"); | ||
|
||
var copy1 = InputActionReference.Create(reference.action); | ||
var copy2 = InputActionReference.Create(reference.ToInputAction()); | ||
|
||
// Expecting action to be the same | ||
Assert.That(reference.action, Is.SameAs(copy1.action)); | ||
Assert.That(reference.action, Is.SameAs(copy2.action)); | ||
} | ||
|
||
[Test] | ||
[Category("Actions")] | ||
public void Actions_CanImplicitlyConvertReferenceToAction_WhenAssigningActionFromReference() | ||
{ | ||
var reference = ScriptableObject.CreateInstance<InputActionReference>(); | ||
InputAction action = reference; // implicit conversion | ||
Assert.That(reference.action, Is.Null); | ||
} |
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.
It's unclear to me why these tests are needed in this PR as they seem to be unrelated to the object picker. Maybe I'm missing something or this is just being used for testing.
…ovider Instead of relying in the default provider, a "custom" provider was created to search input action references on all assets in the asset DB.
// TODO Instead we likely need to integrate all reference management into each step of the editor. | ||
internal class InputActionReferenceValidator | ||
{ | ||
public static void ValidateReferences(InputActionAsset asset) |
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.
Can we split this method up a bit to make it more readable?
Maybe just outsource some code to methods with meaningful names like "HandleAddedOrRemovedActions()"?
// Look for first duplicate reference referencing the same action and eliminate this reference | ||
// if duplicates exist (Should not happen, basically corrupt asset). Additional duplicates are | ||
// covered since this is evaluated for each element. | ||
for (var j = i - 1; j >= 0; --j) |
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.
for example here: calling a method like "EleminateDuplicateReferences" could help explain a lot without reading a comment
Majority of this PR was picked up in another PR attempting to resolve this issue. given #1834 these changes are no longer relevant so will close this PR. |
1 similar comment
Majority of this PR was picked up in another PR attempting to resolve this issue. given #1834 these changes are no longer relevant so will close this PR. |
Description
This PR provides a new object picker for InputActionReference that allows selecting Input Actions from regular .inputaction assets combined with matches from Project-Wide actions. The intention with this PR is to support the workflow with Project Settings based input actions and map.
Changes made
Implemented an object picker based on SearchProvider with the support and guidance of @lochrist that allows using a single object picker (Search window) to select
InputActionReference
assets from Project Settings folder asset and from regular .inputactions assets governed by the AssetDatabase. The functionality is wrapped intoInputReferencePropertyDrawer
which allows including it as an object picker in the Inspector. The component relies on UITK for property drawer.Note that all property drawers above are conditionally included based on the feature flag for project wide action functionality. If this feature is not enabled, behaviour should be similar to prior this PR and default to existing or default object prickers and property drawers.
Extracted code from
InputActionAssetImported
relating to icons into new classInputActionAssetIconProvider
to be able to reference this functionality without caring about implementation details from importer and also from new search/property drawers.Notes
Impact on existing property drawers:
InputActionProperty doesn't require any modifications since it exposes an editor for a InputActionReference when it is configured to use a reference. When configured to represent an InputAction there is no implication on the property drawer by Project Wide actions.

InputActionMap property drawer remains unaffected since its similar to InputAction drawer and allows creating and editing a map owned by the component and not providing support for indirect references.
There currently is no InputActionMapReference support in Input System but if there was, such a picker could be implemented the same way as the InputActionReferencePropertyDrawer part of this PR with little effort.
Open issues:
There seems to be some exceptions entering playmode where aIt seems this must have been related to something in /Library while working on this. Haven't seen it since I cleaned up the /Library folder.null
serialised property is reported in UI code. Not sure what is wrong here at the moment. This seems to be related to IMGUI since the UITK variant of this doesn't seem to suffer from the same issue. Needs more investigation.Open issues (likely bugs) found in SearchProvider functionality - currently being investigated
(PENDING) Issue with description - scenarios:
...the given description is derived via fetchDescription at all times regardless of Window zoom-level.
...the given description to CreateItem is used as description for all zoom-levels of the Window.
...the given description to CreateItem is used as description for all zoom-levels of the Window EXCEPT minimum zoom-level where fetchDescription is used instead.
Based on this behaviour (3) should be used to provide desired behaviour but it is needed to verify that this undocumented behaviour is not a bug to be reliable.
(PENDING) Incorrect documentation.
SearchProvider.CreateItem has incorrect documentation for
data
argument which says its a thumbnail when it really is a "user-provided reference passed to function callbacks". This should be reported and correct.Checklist
Before review:
Changed
,Fixed
,Added
sections.([case %number%](https://issuetracker.unity3d.com/issues/...))
.Area_CanDoX
,Area_CanDoX_EvenIfYIsTheCase
,Area_WhenIDoX_AndYHappens_ThisIsTheResult
.During merge:
NEW: ___
.FIX: ___
.DOCS: ___
.CHANGE: ___
.RELEASE: 1.1.0-preview.3
.