-
Notifications
You must be signed in to change notification settings - Fork 320
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
FIX: ISXB-1221 input action binding discarded #2119
Changes from all commits
4c4e4bc
9f69adf
e48476e
f35d9f8
c255097
7e7e421
dbff69a
9dc97d8
bff9e60
5f55579
980d936
017782c
1a206ae
496fab1
a2063c5
7a5cbe8
1740639
373df10
9dab949
9092773
079d555
31b33c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,15 +30,17 @@ public InputControlPathEditor(SerializedProperty pathProperty, InputControlPicke | |
{ | ||
if (pathProperty == null) | ||
throw new ArgumentNullException(nameof(pathProperty)); | ||
|
||
this.pathProperty = pathProperty; | ||
// Update the static pathProperty variable to the most recent serializedProperty. | ||
// See comment on pathProperty for more information. | ||
s_pathProperty = pathProperty; | ||
this.onModified = onModified; | ||
m_PickerState = pickerState ?? new InputControlPickerState(); | ||
m_PathLabel = label ?? new GUIContent(pathProperty.displayName, pathProperty.GetTooltip()); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
s_pathProperty = null; | ||
m_PickerDropdown?.Dispose(); | ||
} | ||
|
||
|
@@ -89,10 +91,10 @@ public void OnGUI() | |
EditorGUILayout.EndHorizontal(); | ||
} | ||
|
||
//TODO: on next major version remove property argument. | ||
public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty property = null, Action modifiedCallback = null) | ||
{ | ||
var pathLabel = label ?? m_PathLabel; | ||
var serializedProperty = property ?? pathProperty; | ||
|
||
var lineRect = rect; | ||
var labelRect = lineRect; | ||
|
@@ -113,7 +115,7 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert | |
var path = String.Empty; | ||
try | ||
{ | ||
path = serializedProperty.stringValue; | ||
path = pathProperty.stringValue; | ||
} | ||
catch | ||
{ | ||
|
@@ -138,8 +140,8 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert | |
path = EditorGUI.DelayedTextField(bindingTextRect, path); | ||
if (EditorGUI.EndChangeCheck()) | ||
{ | ||
serializedProperty.stringValue = path; | ||
serializedProperty.serializedObject.ApplyModifiedProperties(); | ||
pathProperty.stringValue = path; | ||
pathProperty.serializedObject.ApplyModifiedProperties(); | ||
(modifiedCallback ?? onModified).Invoke(); | ||
} | ||
} | ||
|
@@ -148,9 +150,9 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert | |
// Dropdown that shows binding text and allows opening control picker. | ||
if (EditorGUI.DropdownButton(bindingTextRect, new GUIContent(displayName), FocusType.Keyboard)) | ||
{ | ||
SetExpectedControlLayoutFromAttribute(serializedProperty); | ||
SetExpectedControlLayoutFromAttribute(pathProperty); | ||
////TODO: for bindings that are part of composites, use the layout information from the [InputControl] attribute on the field | ||
ShowDropdown(bindingTextRect, serializedProperty, modifiedCallback ?? onModified); | ||
ShowDropdown(bindingTextRect, modifiedCallback ?? onModified); | ||
} | ||
} | ||
|
||
|
@@ -159,7 +161,7 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert | |
EditorStyles.miniButton); | ||
} | ||
|
||
private void ShowDropdown(Rect rect, SerializedProperty serializedProperty, Action modifiedCallback) | ||
private void ShowDropdown(Rect rect, Action modifiedCallback) | ||
{ | ||
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS | ||
InputActionsEditorSettingsProvider.SetIMGUIDropdownVisible(true, false); | ||
|
@@ -170,19 +172,13 @@ private void ShowDropdown(Rect rect, SerializedProperty serializedProperty, Acti | |
m_PickerState, | ||
path => | ||
{ | ||
serializedProperty.stringValue = path; | ||
pathProperty.stringValue = path; | ||
pathProperty.serializedObject.ApplyModifiedProperties(); | ||
m_PickerState.manualPathEditMode = false; | ||
modifiedCallback(); | ||
}); | ||
} | ||
|
||
m_PickerDropdown.SetPickedCallback(path => | ||
{ | ||
serializedProperty.stringValue = path; | ||
m_PickerState.manualPathEditMode = false; | ||
modifiedCallback(); | ||
}); | ||
|
||
m_PickerDropdown.SetControlPathsToMatch(m_ControlPathsToMatch); | ||
m_PickerDropdown.SetExpectedControlLayout(m_ExpectedControlLayout); | ||
|
||
|
@@ -200,7 +196,16 @@ private void SetExpectedControlLayoutFromAttribute(SerializedProperty property) | |
SetExpectedControlLayout(attribute.layout); | ||
} | ||
|
||
public SerializedProperty pathProperty { get; } | ||
// This static variable is a hack. Because the editor is rebuilt at unpredictable times with a new serializedObject, we need to keep updating | ||
// this variable with most up to date serializedProperty, so that the picker dropdown can access the correct serializedProperty. | ||
// The picker dropdown is a separate window and does not have access to the changed serializedObject reference. | ||
// This could be removed if the InputControlPathEditor is converted to UITK with a stable, persistent serializedObject backing this editor. | ||
// This property will be shared among multiple asset editor windows. | ||
private static SerializedProperty s_pathProperty { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This static SerializedProperty, wouldn't it leak memory? Its referencing a SerializedObject that was dynamically allocated and may/would be disposed from outside this editor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally this assumes there can only exist one InputControlPathEditor instance right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, there will be a dangling reference tht may hang around. I'll add some code to clean it up when the editor is closed. Yes, only one instance of the InputControlPathEditor will work at a time. I think this is ok, as it is a popup window, and disappears when it loses focus. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// This property will always return the most recent serializedProperty. | ||
public SerializedProperty pathProperty { get => s_pathProperty;} | ||
|
||
public Action onModified { get; } | ||
|
||
private GUIContent m_PathLabel; | ||
|
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 would recommend filing a JIRA ticket on this if/when this lands, otherwise it would be forgotten.