33#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_UI_TK_ASSET_EDITOR
44using System ;
55using System . IO ;
6+ using System . Linq ;
67using UnityEditor ;
78using UnityEditor . Callbacks ;
89using UnityEngine . UIElements ;
@@ -23,6 +24,7 @@ static EnableUITKEditor()
2324 internal class InputActionsEditorWindow : EditorWindow
2425 {
2526 private static readonly string k_FileExtension = "." + InputActionAsset . Extension ;
27+ private int m_AssetId ;
2628
2729 [ OnOpenAsset ]
2830 public static bool OpenAsset ( int instanceId , int line )
@@ -42,14 +44,34 @@ public static bool OpenAsset(int instanceId, int line)
4244 if ( asset == null )
4345 return false ;
4446
45- var window = GetWindow < InputActionsEditorWindow > ( ) ;
47+
48+ var window = GetOrCreateWindow ( instanceId , out var isAlreadyOpened ) ;
49+ if ( isAlreadyOpened )
50+ {
51+ window . Focus ( ) ;
52+ return true ;
53+ }
54+ window . m_AssetId = instanceId ;
4655 window . titleContent = new GUIContent ( "Input Actions Editor" ) ;
4756 window . SetAsset ( asset ) ;
4857 window . Show ( ) ;
4958
5059 return true ;
5160 }
5261
62+ private static InputActionsEditorWindow GetOrCreateWindow ( int id , out bool isAlreadyOpened )
63+ {
64+ isAlreadyOpened = false ;
65+ if ( HasOpenInstances < InputActionsEditorWindow > ( ) )
66+ {
67+ var openWindows = Resources . FindObjectsOfTypeAll ( typeof ( InputActionsEditorWindow ) ) as InputActionsEditorWindow [ ] ;
68+ var alreadyOpenWindow = openWindows ? . ToList ( ) . FirstOrDefault ( window => window . m_AssetId . Equals ( id ) ) ;
69+ isAlreadyOpened = alreadyOpenWindow != null ;
70+ return isAlreadyOpened ? alreadyOpenWindow : CreateWindow < InputActionsEditorWindow > ( ) ;
71+ }
72+ return GetWindow < InputActionsEditorWindow > ( ) ;
73+ }
74+
5375 private void SetAsset ( InputActionAsset asset )
5476 {
5577 var serializedAsset = new SerializedObject ( asset ) ;
0 commit comments