mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
Update NodeGraphEditor.cs
- Handled null nodes coming out of AddNode() both in CreateNode() and AddContextMenuItems()
This commit is contained in:
parent
71a6ba87a4
commit
9ca798957d
@ -103,7 +103,7 @@ namespace XNodeEditor {
|
|||||||
if (disallowed) menu.AddItem(new GUIContent(path), false, null);
|
if (disallowed) menu.AddItem(new GUIContent(path), false, null);
|
||||||
else menu.AddItem(new GUIContent(path), false, () => {
|
else menu.AddItem(new GUIContent(path), false, () => {
|
||||||
XNode.Node node = CreateNode(type, pos);
|
XNode.Node node = CreateNode(type, pos);
|
||||||
NodeEditorWindow.current.AutoConnect(node);
|
if (node != null) NodeEditorWindow.current.AutoConnect(node); // handle null nodes to avoid nullref exceptions
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
menu.AddSeparator("");
|
menu.AddSeparator("");
|
||||||
@ -213,6 +213,7 @@ namespace XNodeEditor {
|
|||||||
public virtual XNode.Node CreateNode(Type type, Vector2 position) {
|
public virtual XNode.Node CreateNode(Type type, Vector2 position) {
|
||||||
Undo.RecordObject(target, "Create Node");
|
Undo.RecordObject(target, "Create Node");
|
||||||
XNode.Node node = target.AddNode(type);
|
XNode.Node node = target.AddNode(type);
|
||||||
|
if (node == null) return null; // handle null nodes to avoid nullref exceptions
|
||||||
Undo.RegisterCreatedObjectUndo(node, "Create Node");
|
Undo.RegisterCreatedObjectUndo(node, "Create Node");
|
||||||
node.position = position;
|
node.position = position;
|
||||||
if (node.name == null || node.name.Trim() == "") node.name = NodeEditorUtilities.NodeDefaultName(type);
|
if (node.name == null || node.name.Trim() == "") node.name = NodeEditorUtilities.NodeDefaultName(type);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user