using System;
namespace UnityEditor.Rendering
{
///
/// Set of utilities for Material reimporting.
///
public static class AssetReimportUtils
{
///
/// Re-imports a given type of asset, and sends an analytic with the elapsed time
///
/// The elapsed time
/// The number of assets that have been re-imported
/// A delegate if you want to skip some asset to be re-imported
/// The asset type that will be re-imported
public static void ReimportAll(out double duration, out uint numberOfAssetsReimported, Func importNeedDelegate = null)
{
numberOfAssetsReimported = 0;
duration = 0.0;
using (TimedScope.FromRef(ref duration))
{
string[] distinctGuids = AssetDatabase
.FindAssets($"t:{typeof(TAsset).Name}", null);
try
{
AssetDatabase.StartAssetEditing();
for (int i = 0, total = distinctGuids.Length; i < total; ++i)
{
var path = AssetDatabase.GUIDToAssetPath(distinctGuids[i]);
EditorUtility.DisplayProgressBar($"{typeof(TAsset).Name} Upgrader re-import", $"({i} of {total}) {path}", (float)i / (float)total);
if (importNeedDelegate?.Invoke(path) ?? true)
{
AssetDatabase.ImportAsset(path);
numberOfAssetsReimported++;
}
}
}
finally
{
// Ensure the AssetDatabase knows we're finished editing
AssetDatabase.StopAssetEditing();
}
}
EditorUtility.ClearProgressBar();
}
}
}