Skip to content

Commit

Permalink
Add sanity check for asset cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Krysiek committed Jan 5, 2024
1 parent a325221 commit 6a1bf8a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Packages/pl.krysiek.cutedancer/Editor/Utils/AssetCleanup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;

public class AssetCleanup : MonoBehaviour
{
public static bool RemoveOrphans(string assetPath)
{
if (AssetDatabase.GetMainAssetTypeAtPath(assetPath) != typeof(AnimatorController)) {
// AnimatorController structure is flat. There are bunch of elements referencing each other by fileID.
// Main element contains reference to itself, so it won't be removed.

// Other assets usually have one top element without any internal reference to it.
// In this case this code can completely remove content of the asset, so better break here.
return false;
}

string rawData = File.ReadAllText(assetPath);
string[] rawLines = File.ReadAllLines(assetPath);

Expand Down Expand Up @@ -39,7 +49,7 @@ public static bool RemoveOrphans(string assetPath)
}

bool ok = EditorUtility.DisplayDialog(
"Orphans removal",
"Asset cleanup",
"Orphans found in the file:\n\n" + info,
"Remove", "Cancel");

Expand Down

0 comments on commit 6a1bf8a

Please sign in to comment.