@@ -83,23 +83,20 @@ internal static T CreateAsset<T>(T asset, string relativePath) where T : Scripta
8383 return asset ;
8484 }
8585
86- public static VisualElement CreateMakeActiveGui < T > ( Func < T > getCurrent , T target , string targetName , string entity , Action < T > apply , bool allowAssignActive = true )
86+ public static VisualElement CreateMakeActiveGui < T > ( Func < T > getCurrent , T target , string targetName , string entity ,
87+ Action < T > apply , Action < Action > subscribeToChanges , Action < Action > unsubscribeFromChanges ,
88+ bool allowAssignActive = true )
8789 where T : ScriptableObject
8890 {
8991 var container = new VisualElement ( ) ;
90- var lastKnownCurrent = getCurrent ( ) ;
91- PopulateMakeActiveGui ( container , lastKnownCurrent , target , entity , apply , allowAssignActive ) ;
9292
93- // Poll for external changes to the active asset (e.g. from Project Settings or Undo).
94- // The scheduled item is automatically stopped when the element leaves the panel.
95- container . schedule . Execute ( ( ) =>
96- {
97- var current = getCurrent ( ) ;
98- if ( current == lastKnownCurrent )
99- return ;
100- lastKnownCurrent = current ;
101- PopulateMakeActiveGui ( container , current , target , entity , apply , allowAssignActive ) ;
102- } ) . Every ( 500 ) ;
93+ void Refresh ( ) => PopulateMakeActiveGui ( container , getCurrent ( ) , target , entity , apply , allowAssignActive ) ;
94+
95+ Refresh ( ) ;
96+
97+ // Subscribe for as long as the element is part of a panel, matching the pattern used in InputParameterEditor.
98+ container . RegisterCallback < AttachToPanelEvent > ( _ => subscribeToChanges ( Refresh ) ) ;
99+ container . RegisterCallback < DetachFromPanelEvent > ( _ => unsubscribeFromChanges ( Refresh ) ) ;
103100
104101 return container ;
105102 }
0 commit comments