mirror of
https://github.com/Siccity/xNode.git
synced 2026-03-26 22:49:02 +08:00
Merge afab16c3c02ee488464273213f404a6de4a3d465 into 2291531ceb6ae0c6335f61349c20bec3878522b7
This commit is contained in:
commit
4f801b3112
@ -18,46 +18,55 @@ namespace XNode {
|
|||||||
|
|
||||||
/// <summary> Add a node to the graph by type </summary>
|
/// <summary> Add a node to the graph by type </summary>
|
||||||
public virtual Node AddNode(Type type) {
|
public virtual Node AddNode(Type type) {
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
UnityEditor.Undo.RecordObject(this, "Add Node " + type.ToString());
|
||||||
|
#endif
|
||||||
Node node = ScriptableObject.CreateInstance(type) as Node;
|
Node node = ScriptableObject.CreateInstance(type) as Node;
|
||||||
|
nodes.Add(node);
|
||||||
|
node.graph = this;
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (!Application.isPlaying) {
|
if (!Application.isPlaying) {
|
||||||
UnityEditor.AssetDatabase.AddObjectToAsset(node, this);
|
UnityEditor.AssetDatabase.AddObjectToAsset(node, this);
|
||||||
UnityEditor.AssetDatabase.SaveAssets();
|
|
||||||
node.name = UnityEditor.ObjectNames.NicifyVariableName(node.name);
|
node.name = UnityEditor.ObjectNames.NicifyVariableName(node.name);
|
||||||
}
|
}
|
||||||
|
UnityEditor.EditorUtility.SetDirty(this);
|
||||||
#endif
|
#endif
|
||||||
nodes.Add(node);
|
|
||||||
node.graph = this;
|
|
||||||
return node;
|
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>
|
||||||
public virtual Node CopyNode(Node original) {
|
public virtual Node CopyNode(Node original) {
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
UnityEditor.Undo.RecordObject(this, "Copy Node");
|
||||||
|
#endif
|
||||||
Node node = ScriptableObject.Instantiate(original);
|
Node node = ScriptableObject.Instantiate(original);
|
||||||
node.ClearConnections();
|
node.ClearConnections();
|
||||||
|
nodes.Add(node);
|
||||||
|
node.graph = this;
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (!Application.isPlaying) {
|
if (!Application.isPlaying) {
|
||||||
UnityEditor.AssetDatabase.AddObjectToAsset(node, this);
|
UnityEditor.AssetDatabase.AddObjectToAsset(node, this);
|
||||||
UnityEditor.AssetDatabase.SaveAssets();
|
|
||||||
node.name = UnityEditor.ObjectNames.NicifyVariableName(node.name);
|
node.name = UnityEditor.ObjectNames.NicifyVariableName(node.name);
|
||||||
}
|
}
|
||||||
|
UnityEditor.EditorUtility.SetDirty(this);
|
||||||
#endif
|
#endif
|
||||||
nodes.Add(node);
|
|
||||||
node.graph = this;
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Safely remove a node and all its connections </summary>
|
/// <summary> Safely remove a node and all its connections </summary>
|
||||||
/// <param name="node"></param>
|
/// <param name="node"></param>
|
||||||
public void RemoveNode(Node node) {
|
public void RemoveNode(Node node) {
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
UnityEditor.Undo.RecordObject(this, "Remove Node");
|
||||||
|
#endif
|
||||||
node.ClearConnections();
|
node.ClearConnections();
|
||||||
|
nodes.Remove(node);
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (!Application.isPlaying) {
|
if (!Application.isPlaying) {
|
||||||
DestroyImmediate(node, true);
|
DestroyImmediate(node, true);
|
||||||
UnityEditor.AssetDatabase.SaveAssets();
|
|
||||||
}
|
}
|
||||||
|
UnityEditor.EditorUtility.SetDirty(this);
|
||||||
#endif
|
#endif
|
||||||
nodes.Remove(node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Remove all nodes and connections from the graph </summary>
|
/// <summary> Remove all nodes and connections from the graph </summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user