public static void CacheProjectReferences(bool showProgress = true) { AssetDatabase.SaveAssets(); AssetFinderCache.RestorePendingFiles(); if (AssetFinderCache.usages != null) { return; } try { if (showProgress == true) { EditorUtility.DisplayProgressBar(NGAssetFinderWindow.Title + " - Project", "Loading cache from disk...", 0F); } if (AssetFinderCache.LoadCache(AssetFinderCache.GetCachePath()) == false) { AssetFinderCache.usagesFiles = new Dictionary <string, string[]>(); } AssetFinderCache.usages = new Dictionary <string, List <string> >((int)(AssetFinderCache.usagesFiles.Count * .375F)); // Approximation of an average used assets. EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo(); if (showProgress == true) { EditorUtility.DisplayProgressBar(NGAssetFinderWindow.Title + " - Project", "Fetching all asset paths...", 0F); } double time = EditorApplication.timeSinceStartup; string[] assets = AssetDatabase.GetAllAssetPaths(); int cacheHits = 0; for (int i = 0; i < assets.Length; i++) { if ((assets[i].StartsWith("Assets/") == false && assets[i].StartsWith("ProjectSettings/") == false && assets[i].StartsWith("Library/") == false) || Directory.Exists(assets[i]) == true) { continue; } if (showProgress == true && (i % 18) == 0) { string progressBarTitle = NGAssetFinderWindow.Title + " - Project (" + (i + 1) + " / " + assets.Length + ")"; string progressBarContent = "Caching..."; float progressBarRate = (float)(i + 1) / (float)assets.Length; if (EditorUtility.DisplayCancelableProgressBar(progressBarTitle, progressBarContent, progressBarRate) == true) { throw new BreakException(); } } string[] IDs; long ticks = -1; if (AssetFinderCache.usagesFiles.TryGetValue(assets[i], out IDs) == true) { ticks = File.GetLastWriteTime(assets[i]).Ticks; if (ticks == long.Parse(IDs[0])) { ++cacheHits; for (int j = 1; j < IDs.Length; j++) { List <string> cache; if (AssetFinderCache.usages.TryGetValue(IDs[j], out cache) == false) { cache = new List <string>(); AssetFinderCache.usages.Add(IDs[j], cache); } if (cache.Contains(assets[i]) == false) { cache.Add(assets[i]); } } continue; } else { AssetFinderCache.usagesFiles.Remove(assets[i]); } } AssetFinderCache.ExtractReferences(assets[i], true, ticks); } InternalNGDebug.VerboseLogFormat("[AssetFinderCache] Constructed cache in {0} seconds. ({1} cache hits, {2} elements)", EditorApplication.timeSinceStartup - time, cacheHits, AssetFinderCache.usages.Count); } finally { if (showProgress == true) { EditorUtility.ClearProgressBar(); } } }
public static void ClearCache() { AssetFinderCache.usages = null; AssetFinderCache.usagesFiles = null; File.Delete(AssetFinderCache.GetCachePath()); }