Skip to content

Commit 5e75444

Browse files
committed
fix: Started skipping assembly reimport if we were not able to fix the assembly previously
1 parent 2247f7b commit 5e75444

2 files changed

Lines changed: 39 additions & 29 deletions

File tree

Editor/GenericTypesAnalyzer/FailedAssembliesChecker.cs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
internal static class FailedAssembliesChecker
1010
{
11-
private const string FailedAssemblyGuids = "FailedAssemblyGuids";
11+
private const string PreviouslyFailedAssemblyGuidsKey = "PreviouslyFailedAssemblyGuids";
12+
private const string NewFailedAssemblyGuidsKey = "NewFailedAssemblyGuids";
1213

1314
public static readonly List<string> FailedAssemblyPaths = new List<string>();
1415

@@ -19,51 +20,49 @@ public static void ReimportFailedAssemblies()
1920
return;
2021
}
2122

22-
var failedAssemblyGuids = new List<string>();
23+
var previouslyFailedAssemblies = PersistentStorage.GetFromPlayerPrefs<List<string>>(PreviouslyFailedAssemblyGuidsKey);
24+
var newFailedAssemblyGuids = new List<string>();
2325

2426
using (new DisabledAssetDatabase(true))
2527
{
26-
foreach (string assemblyPath in FailedAssemblyPaths)
27-
{
28-
AssetDatabase.ImportAsset(assemblyPath, ImportAssetOptions.ForceUpdate);
29-
30-
string assemblyGuid = AssetDatabase.AssetPathToGUID(assemblyPath);
31-
32-
if (!string.IsNullOrEmpty(assemblyGuid))
33-
failedAssemblyGuids.Add(assemblyGuid);
28+
var failedAssemblyPathsAndGuids = FailedAssemblyPaths.Select(path => (path, AssetDatabase.AssetPathToGUID(path)))
29+
.Where(pathAndGuid => !string.IsNullOrEmpty(pathAndGuid.Item2)).ToList();
3430

31+
foreach ((string path, string guid) in failedAssemblyPathsAndGuids)
32+
{
33+
// Reimport only the assemblies that did not fail previously
34+
if (previouslyFailedAssemblies.Contains(guid))
35+
continue;
3536

37+
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
38+
newFailedAssemblyGuids.Add(guid);
3639
}
40+
41+
// Remove all the assemblies that failed but were fixed from previously failed ones.
42+
previouslyFailedAssemblies = previouslyFailedAssemblies.Intersect(failedAssemblyPathsAndGuids.Select(pathAndGuid => pathAndGuid.Item2)).ToList();
3743
}
3844

39-
if (failedAssemblyGuids.Count != 0)
40-
{
41-
PersistentStorage.SaveData(FailedAssemblyGuids, failedAssemblyGuids);
45+
PersistentStorage.SaveToPlayerPrefs(PreviouslyFailedAssemblyGuidsKey, previouslyFailedAssemblies);
46+
PersistentStorage.SaveToPlayerPrefs(NewFailedAssemblyGuidsKey, newFailedAssemblyGuids);
47+
48+
if (newFailedAssemblyGuids.Count != 0)
4249
PersistentStorage.ExecuteOnScriptsReload(ReimportCreatedAssets);
43-
}
4450

4551
AssetDatabase.Refresh();
4652
}
4753

4854
private static void ReimportCreatedAssets()
4955
{
50-
try
51-
{
52-
var failedAssemblyGuids = PersistentStorage.GetData<List<string>>(FailedAssemblyGuids);
53-
54-
using (new DisabledAssetDatabase(true))
55-
{
56-
var assetPaths = failedAssemblyGuids
57-
.SelectMany(assemblyGuid => AssetDatabase.FindAssets($"t:ConcreteClass_{assemblyGuid}"))
58-
.Select(AssetDatabase.GUIDToAssetPath);
56+
var failedAssemblyGuids = PersistentStorage.GetFromPlayerPrefs<List<string>>(NewFailedAssemblyGuidsKey);
5957

60-
foreach (string assetPath in assetPaths)
61-
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
62-
}
63-
}
64-
finally
58+
using (new DisabledAssetDatabase(true))
6559
{
66-
PersistentStorage.DeleteData(FailedAssemblyGuids);
60+
var assetPaths = failedAssemblyGuids
61+
.SelectMany(assemblyGuid => AssetDatabase.FindAssets($"t:ConcreteClass_{assemblyGuid}"))
62+
.Select(AssetDatabase.GUIDToAssetPath);
63+
64+
foreach (string assetPath in assetPaths)
65+
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
6766
}
6867

6968
AssetDatabase.Refresh();

Editor/Util/EditorCoroutineHelper.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)