@@ -38,7 +38,9 @@ public class BaseNodeView : NodeView
3838
3939 protected virtual bool hasSettings => false ;
4040
41- readonly string baseNodeStyle = "GraphProcessorStyles/BaseNodeView" ;
41+ public bool initializing = false ; //Used for applying SetPosition on locked node at init.
42+
43+ readonly string baseNodeStyle = "GraphProcessorStyles/BaseNodeView" ;
4244
4345 bool settingsExpanded = false ;
4446
@@ -95,7 +97,9 @@ void InitializeView()
9597
9698 title = ( string . IsNullOrEmpty ( nodeTarget . name ) ) ? nodeTarget . GetType ( ) . Name : nodeTarget . name ;
9799
98- SetPosition ( nodeTarget . position ) ;
100+ initializing = true ;
101+
102+ SetPosition ( nodeTarget . position ) ;
99103 }
100104
101105 void InitializeSettings ( )
@@ -319,10 +323,14 @@ public virtual void OnCreated() {}
319323
320324 public override void SetPosition ( Rect newPos )
321325 {
322- base . SetPosition ( newPos ) ;
323-
324- Undo . RegisterCompleteObjectUndo ( owner . graph , "Moved graph node" ) ;
325- nodeTarget . position = newPos ;
326+ if ( initializing || ! nodeTarget . isLocked )
327+ {
328+ initializing = false ;
329+ base . SetPosition ( newPos ) ;
330+
331+ Undo . RegisterCompleteObjectUndo ( owner . graph , "Moved graph node" ) ;
332+ nodeTarget . position = newPos ;
333+ }
326334 }
327335
328336 public override bool expanded
@@ -335,14 +343,26 @@ public override bool expanded
335343 }
336344 }
337345
338- public override void BuildContextualMenu ( ContextualMenuPopulateEvent evt )
346+ public void ChangeLockStatus ( )
347+ {
348+ nodeTarget . nodeLock ^= true ;
349+ }
350+
351+ public override void BuildContextualMenu ( ContextualMenuPopulateEvent evt )
339352 {
340353 evt . menu . AppendAction ( "Open Node Script" , ( e ) => OpenNodeScript ( ) , OpenNodeScriptStatus ) ;
341354 evt . menu . AppendAction ( "Open Node View Script" , ( e ) => OpenNodeViewScript ( ) , OpenNodeViewScriptStatus ) ;
342355 evt . menu . AppendAction ( "Debug" , ( e ) => ToggleDebug ( ) , DebugStatus ) ;
343- }
356+ if ( nodeTarget . unlockable )
357+ evt . menu . AppendAction ( ( nodeTarget . isLocked ? "Unlock" : "Lock" ) , ( e ) => ChangeLockStatus ( ) , LockStatus ) ;
358+ }
359+
360+ Status LockStatus ( DropdownMenuAction action )
361+ {
362+ return Status . Normal ;
363+ }
344364
345- Status DebugStatus ( DropdownMenuAction action )
365+ Status DebugStatus ( DropdownMenuAction action )
346366 {
347367 if ( nodeTarget . debug )
348368 return Status . Checked ;
0 commit comments