1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-21 01:36:03 +08:00
xNode/Scripts/Editor/NodeEditorAssetModProcessor.cs
Thor Brigsted c6a4735c71 Renamed to xNode
Added XNode and XNodeEDitor namespaces
Removed unnecessary usings
2017-11-05 23:42:31 +01:00

36 lines
1.6 KiB
C#

using UnityEditor;
using UnityEngine;
using XNode;
namespace XNodeEditor {
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;
}
}
}