using System.IO; using UnityEditor; using UnityEngine; public static class FixGhostAsset { [MenuItem("Tools/Fix Ghost Asset")] public static void Fix() { const string ghost = "Assets/ResourcesOut/Sprite/HeroDebutHero_510016/HeroDebutSkinTabInfo_5100161.png"; var guid = AssetDatabase.AssetPathToGUID(ghost); var type = AssetDatabase.GetMainAssetTypeAtPath(ghost); Debug.Log($"[Ghost] path={ghost}\n GUID={guid}\n Type={type}"); // 直接让 Unity 从索引里删掉 var ok = AssetDatabase.DeleteAsset(ghost); Debug.Log($"[Ghost] DeleteAsset -> {ok}"); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); } /// /// 删除 YooAsset 的 AssetDependencyDB 依赖缓存。 /// 当出现 "Found invalid asset : ..." 这类指向已删除资源的报错时调用。 /// 该 DB 缓存了旧的 GUID→AssetPath 映射,磁盘文件删除后它不会自动失效, /// 删除文件后 YooAsset 会在下次打包时自动重建。 /// [MenuItem("Tools/Clear YooAsset DependencyDB")] public static void ClearYooAssetDependencyDB() { string projectRoot = Path.GetFullPath(Path.Combine(Application.dataPath, "..")); string dbPath = Path.Combine(projectRoot, "Library", "AssetDependencyDB"); if (File.Exists(dbPath)) { try { File.Delete(dbPath); Debug.Log($"[FixGhostAsset] 已删除 YooAsset 依赖缓存: {dbPath}\n下次打包将自动重建。"); } catch (System.Exception ex) { Debug.LogError($"[FixGhostAsset] 删除 AssetDependencyDB 失败: {ex.Message}"); } } else { Debug.Log($"[FixGhostAsset] AssetDependencyDB 不存在(可能已删除或尚未生成): {dbPath}"); } } }