mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Added fix for rename bug with v2 AssetDatabase (#239)
* Added fix for NodeGraph rename bug with v2 AssetDatabase where renaming a graph asset can sometimes result in it being swapped as the main asset with one of the node sub assets.
This commit is contained in:
parent
9a6746a898
commit
9add4e11b2
35
Scripts/Editor/GraphRenameFixAssetProcessor.cs
Normal file
35
Scripts/Editor/GraphRenameFixAssetProcessor.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using UnityEditor;
|
||||||
|
using XNode;
|
||||||
|
|
||||||
|
namespace XNodeEditor {
|
||||||
|
/// <summary>
|
||||||
|
/// This asset processor resolves an issue with the new v2 AssetDatabase system present on 2019.3 and later. When
|
||||||
|
/// renaming a <see cref="XNode.NodeGraph"/> asset, it appears that sometimes the v2 AssetDatabase will swap which asset
|
||||||
|
/// is the main asset (present at top level) between the <see cref="XNode.NodeGraph"/> and one of its <see cref="XNode.Node"/>
|
||||||
|
/// sub-assets. As a workaround until Unity fixes this, this asset processor checks all renamed assets and if it
|
||||||
|
/// finds a case where a <see cref="XNode.Node"/> has been made the main asset it will swap it back to being a sub-asset
|
||||||
|
/// and rename the node to the default name for that node type.
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class GraphRenameFixAssetProcessor : AssetPostprocessor {
|
||||||
|
private static void OnPostprocessAllAssets(
|
||||||
|
string[] importedAssets,
|
||||||
|
string[] deletedAssets,
|
||||||
|
string[] movedAssets,
|
||||||
|
string[] movedFromAssetPaths) {
|
||||||
|
for (int i = 0; i < movedAssets.Length; i++) {
|
||||||
|
Node nodeAsset = AssetDatabase.LoadMainAssetAtPath(movedAssets[i]) as Node;
|
||||||
|
|
||||||
|
// If the renamed asset is a node graph, but the v2 AssetDatabase has swapped a sub-asset node to be its
|
||||||
|
// main asset, reset the node graph to be the main asset and rename the node asset back to its default
|
||||||
|
// name.
|
||||||
|
if (nodeAsset != null && AssetDatabase.IsMainAsset(nodeAsset)) {
|
||||||
|
AssetDatabase.SetMainObject(nodeAsset.graph, movedAssets[i]);
|
||||||
|
AssetDatabase.ImportAsset(movedAssets[i]);
|
||||||
|
|
||||||
|
nodeAsset.name = NodeEditorUtilities.NodeDefaultName(nodeAsset.GetType());
|
||||||
|
EditorUtility.SetDirty(nodeAsset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Scripts/Editor/GraphRenameFixAssetProcessor.cs.meta
Normal file
11
Scripts/Editor/GraphRenameFixAssetProcessor.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 65da1ff1c50a9984a9c95fd18799e8dd
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
x
Reference in New Issue
Block a user