Skip to content

Commit 7785b9b

Browse files
authored
Merge branch 'master' into NodeSettings
2 parents 8048197 + e5ed5ca commit 7785b9b

2 files changed

Lines changed: 37 additions & 12 deletions

File tree

Assets/com.alelievr.NodeGraphProcessor/Editor/Views/BaseNodeView.cs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

Assets/com.alelievr.NodeGraphProcessor/Runtime/Elements/BaseNode.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ public abstract class BaseNode
1717

1818
public virtual string layoutStyle => string.Empty;
1919

20-
//id
21-
public string GUID;
20+
public virtual bool unlockable => true;
21+
22+
public virtual bool isLocked => nodeLock;
23+
24+
//id
25+
public string GUID;
2226

2327
public int computeOrder = -1;
2428
public bool canProcess = true;
@@ -32,8 +36,9 @@ public abstract class BaseNode
3236
public Rect position;
3337
public bool expanded;
3438
public bool debug;
39+
public bool nodeLock;
3540

36-
public delegate void ProcessDelegate();
41+
public delegate void ProcessDelegate();
3742

3843
public event ProcessDelegate onProcessed;
3944

0 commit comments

Comments
 (0)