1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 17:26:02 +08:00
xNode/Scripts/Editor/NodeEditorAssetModProcessor.cs
Thor Brigsted 5e68b6bcdc Big update.
Removal of scripts now also clears dependant nodes, to avoid null objects.
NodePorts now support fallback values.
UI Changes.
node.graph is now serialized as well.
2017-10-14 16:19:24 +02:00

35 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class NodeEditorAssetModProcessor : UnityEditor.AssetModificationProcessor {
public static AssetDeleteResult OnWillDeleteAsset(string path, RemoveAssetOptions options) {
UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(path);
if (!(obj is UnityEditor.MonoScript)) return AssetDeleteResult.DidNotDelete;
UnityEditor.MonoScript script = obj as UnityEditor.MonoScript;
System.Type scriptType = script.GetClass();
if (scriptType != typeof(Node) && !scriptType.IsSubclassOf(typeof(Node))) return AssetDeleteResult.DidNotDelete;
//Find ScriptableObjects using this script
string[] guids = AssetDatabase.FindAssets("t:" + scriptType);
for (int i = 0; i < guids.Length; i++) {
string assetpath = AssetDatabase.GUIDToAssetPath(guids[i]);
Object[] objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetpath);
for (int k = 0; k < objs.Length; k++) {
Node node = objs[k] as Node;
if (node.GetType() == scriptType) {
if (node != null && node.graph != null) {
Debug.LogWarning(node.name + " of " + node.graph + " depended on deleted script and has been removed automatically.", node.graph);
node.graph.RemoveNode(node);
}
}
}
}
return AssetDeleteResult.DidNotDelete;
}
}