mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +08:00
Better asset handling on add/remove node
This commit is contained in:
parent
9dd3e1db75
commit
cd1864fce3
BIN
Example/ExampleNodeGraph.asset
Normal file
BIN
Example/ExampleNodeGraph.asset
Normal file
Binary file not shown.
9
Example/ExampleNodeGraph.asset.meta
Normal file
9
Example/ExampleNodeGraph.asset.meta
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5398d565241ec2d489f41c368ca6cf24
|
||||||
|
timeCreated: 1507498811
|
||||||
|
licenseType: Free
|
||||||
|
NativeFormatImporter:
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -18,7 +18,10 @@ public abstract class NodeGraph : ScriptableObject, ISerializationCallbackReceiv
|
|||||||
public virtual Node AddNode(Type type) {
|
public virtual Node AddNode(Type type) {
|
||||||
Node node = ScriptableObject.CreateInstance(type) as Node;
|
Node node = ScriptableObject.CreateInstance(type) as Node;
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
UnityEditor.AssetDatabase.AddObjectToAsset(node, this);
|
if (!Application.isPlaying) {
|
||||||
|
UnityEditor.AssetDatabase.AddObjectToAsset(node, this);
|
||||||
|
UnityEditor.AssetDatabase.SaveAssets();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
nodes.Add(node);
|
nodes.Add(node);
|
||||||
node.graph = this;
|
node.graph = this;
|
||||||
@ -29,6 +32,12 @@ public abstract class NodeGraph : ScriptableObject, ISerializationCallbackReceiv
|
|||||||
/// <param name="node"></param>
|
/// <param name="node"></param>
|
||||||
public void RemoveNode(Node node) {
|
public void RemoveNode(Node node) {
|
||||||
node.ClearConnections();
|
node.ClearConnections();
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (!Application.isPlaying) {
|
||||||
|
DestroyImmediate(node, true);
|
||||||
|
UnityEditor.AssetDatabase.SaveAssets();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
nodes.Remove(node);
|
nodes.Remove(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user