Skip to content

Commit 872662e

Browse files
committed
fixup warnings with Unity 6.4 relating to the instanceId -> entityId migration
1 parent f5bf847 commit 872662e

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

Packages/com.unity.inputsystem/InputSystem/Editor/AssetEditor/InputActionEditorWindow.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,41 @@ static InputActionEditorWindow()
4242
InputActionAssetEditor.RegisterType<InputActionEditorWindow>();
4343
}
4444

45+
// Unity 6.4 changed signature of OpenAsset, and now it accepts entity id instead of instance id.
46+
[OnOpenAsset]
47+
#if UNITY_6000_4_OR_NEWER
48+
public static bool OpenAsset(EntityId entityId, int line)
49+
{
50+
if (!InputActionImporter.IsInputActionAssetPath(AssetDatabase.GetAssetPath(entityId)))
51+
return false;
52+
53+
return OpenAsset(EditorUtility.EntityIdToObject(entityId));
54+
}
55+
#else
56+
public static bool OpenAsset(int instanceId, int line)
57+
{
58+
if (!InputActionImporter.IsInputActionAssetPath(AssetDatabase.GetAssetPath(instanceId)))
59+
return false;
60+
61+
return OpenAsset(EditorUtility.InstanceIDToObject(instanceId));
62+
}
63+
#endif
64+
4565
/// <summary>
4666
/// Open window if someone clicks on an .inputactions asset or an action inside of it.
4767
/// </summary>
48-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "line", Justification = "line parameter required by OnOpenAsset attribute")]
49-
[OnOpenAsset]
50-
public static bool OnOpenAsset(int instanceId, int line)
68+
private static bool OpenAsset(Object obj)
5169
{
5270
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
5371
if (!InputSystem.settings.useIMGUIEditorForAssets)
5472
return false;
5573
#endif
56-
var path = AssetDatabase.GetAssetPath(instanceId);
57-
if (!InputActionImporter.IsInputActionAssetPath(path))
58-
return false;
59-
6074
string mapToSelect = null;
6175
string actionToSelect = null;
6276

6377
// Grab InputActionAsset.
6478
// NOTE: We defer checking out an asset until we save it. This allows a user to open an .inputactions asset and look at it
6579
// without forcing a checkout.
66-
var obj = EditorUtility.InstanceIDToObject(instanceId);
6780
var asset = obj as InputActionAsset;
6881
if (asset == null)
6982
{

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,34 @@ static InputActionsEditorWindow()
4848
m_Analytics ??= new InputActionsEditorSessionAnalytic(
4949
InputActionsEditorSessionAnalytic.Data.Kind.EditorWindow);
5050

51+
// Unity 6.4 changed signature of OpenAsset, and now it accepts entity id instead of instance id.
5152
[OnOpenAsset]
52-
public static bool OpenAsset(int instanceId, int line)
53+
#if UNITY_6000_4_OR_NEWER
54+
public static bool OpenAsset(EntityId entityId, int line)
5355
{
54-
if (InputSystem.settings.IsFeatureEnabled(InputFeatureNames.kUseIMGUIEditorForAssets))
56+
if (!InputActionImporter.IsInputActionAssetPath(AssetDatabase.GetAssetPath(entityId)))
5557
return false;
58+
59+
return OpenAsset(EditorUtility.EntityIdToObject(entityId));
60+
}
61+
#else
62+
public static bool OpenAsset(int instanceId, int line)
63+
{
5664
if (!InputActionImporter.IsInputActionAssetPath(AssetDatabase.GetAssetPath(instanceId)))
5765
return false;
66+
67+
return OpenAsset(EditorUtility.InstanceIDToObject(instanceId));
68+
}
69+
#endif
70+
71+
private static bool OpenAsset(Object obj)
72+
{
73+
if (InputSystem.settings.IsFeatureEnabled(InputFeatureNames.kUseIMGUIEditorForAssets))
74+
return false;
5875

5976
// Grab InputActionAsset.
6077
// NOTE: We defer checking out an asset until we save it. This allows a user to open an .inputactions asset and look at it
6178
// without forcing a checkout.
62-
var obj = EditorUtility.InstanceIDToObject(instanceId);
6379
var asset = obj as InputActionAsset;
6480

6581
string actionMapToSelect = null;

Packages/com.unity.inputsystem/InputSystem/InputSystem.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,8 +3592,7 @@ internal static void InitializeInEditor(IInputRuntime runtime = null)
35923592
}
35933593

35943594
Debug.Assert(settings != null);
3595-
Debug.Assert(EditorUtility.InstanceIDToObject(settings.GetInstanceID()) != null,
3596-
"InputSettings has lost its native object");
3595+
Debug.Assert(MiscHelpers.HasNativeObject(settings), "InputSettings has lost its native object");
35973596

35983597
// If native backends for new input system aren't enabled, ask user whether we should
35993598
// enable them (requires restart). We only ask once per session and don't ask when
@@ -3707,7 +3706,7 @@ private static void OnProjectChange()
37073706
// temporary settings object.
37083707
// NOTE: We access m_Settings directly here to make sure we're not running into asserts
37093708
// from the settings getter checking it has a valid object.
3710-
if (EditorUtility.InstanceIDToObject(s_Manager.m_Settings.GetInstanceID()) == null)
3709+
if (MiscHelpers.HasNativeObject(s_Manager.m_Settings))
37113710
{
37123711
var newSettings = ScriptableObject.CreateInstance<InputSettings>();
37133712
newSettings.hideFlags = HideFlags.HideAndDontSave;

Packages/com.unity.inputsystem/InputSystem/Utilities/MiscHelpers.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using UnityEditor;
23

34
namespace UnityEngine.InputSystem.Utilities
45
{
@@ -36,5 +37,15 @@ public static int IndexOf<TValue>(this IEnumerable<TValue> enumerable, TValue va
3637
++index;
3738
return -1;
3839
}
40+
41+
// We have this function to hide away instanceId -> entityId migration that happened in Unity 6.4
42+
public static bool HasNativeObject(Object obj)
43+
{
44+
#if UNITY_6000_4_OR_NEWER
45+
return EditorUtility.EntityIdToObject(obj.GetEntityId()) != null;
46+
#else
47+
return EditorUtility.InstanceIDToObject(obj.GetInstanceID()) != null;
48+
#endif
49+
}
3950
}
4051
}

0 commit comments

Comments
 (0)