Skip to content

Commit 9a7f611

Browse files
committed
Added a callback when the graph asset is deleted on disk
1 parent ca8c590 commit 9a7f611

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using UnityEngine;
1+
using UnityEngine;
42
using UnityEditor;
5-
using UnityEditor.Callbacks;
63

74
namespace GraphProcessor
85
{
@@ -11,16 +8,20 @@ public class DeleteCallback : UnityEditor.AssetModificationProcessor
118
{
129
static AssetDeleteResult OnWillDeleteAsset(string path, RemoveAssetOptions options)
1310
{
14-
var graph = AssetDatabase.LoadAssetAtPath(path, typeof(BaseGraph));
11+
var objects = AssetDatabase.LoadAllAssetsAtPath(path);
1512

16-
if (graph != null)
13+
foreach (var obj in objects)
1714
{
18-
foreach (var graphWindow in Resources.FindObjectsOfTypeAll< BaseGraphWindow >())
19-
graphWindow.OnGraphDeleted();
15+
if (obj is BaseGraph b)
16+
{
17+
foreach (var graphWindow in Resources.FindObjectsOfTypeAll< BaseGraphWindow >())
18+
graphWindow.OnGraphDeleted();
19+
20+
b.OnAssetDeleted();
21+
}
2022
}
2123

2224
return AssetDeleteResult.DidNotDelete;
2325
}
2426
}
25-
2627
}

Assets/com.alelievr.NodeGraphProcessor/Runtime/Graph/BaseGraph.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ protected virtual void OnDisable()
214214
node.DisableInternal();
215215
}
216216

217+
public virtual void OnAssetDeleted() {}
218+
217219
/// <summary>
218220
/// Adds a node to the graph
219221
/// </summary>

0 commit comments

Comments
 (0)