1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00

NodeGraphEditor: Make CreateNode return created node

This commit is contained in:
Woland 2019-04-08 21:29:53 +02:00
parent 8adc4fd459
commit 6aaad5e0cb

View File

@ -69,13 +69,14 @@ namespace XNodeEditor {
} }
/// <summary> Create a node and save it in the graph asset </summary> /// <summary> Create a node and save it in the graph asset </summary>
public virtual void CreateNode(Type type, Vector2 position) { public virtual XNode.Node CreateNode(Type type, Vector2 position) {
XNode.Node node = target.AddNode(type); XNode.Node node = target.AddNode(type);
node.position = position; node.position = position;
if (string.IsNullOrEmpty(node.name)) node.name = UnityEditor.ObjectNames.NicifyVariableName(type.Name); if (string.IsNullOrEmpty(node.name)) node.name = UnityEditor.ObjectNames.NicifyVariableName(type.Name);
AssetDatabase.AddObjectToAsset(node, target); AssetDatabase.AddObjectToAsset(node, target);
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets(); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
NodeEditorWindow.RepaintAll(); NodeEditorWindow.RepaintAll();
return node;
} }
/// <summary> Creates a copy of the original node in the graph </summary> /// <summary> Creates a copy of the original node in the graph </summary>
@ -112,4 +113,4 @@ namespace XNodeEditor {
} }
} }
} }
} }