using UnityEngine; using System.Collections.Generic; namespace UnityEditor.Polybrush { /// /// Store previews in an internal cache for quick access. /// internal static class PreviewsDatabase { /// /// Cache size. Also used to set the cache size of AssetPreview. /// static readonly int k_CacheSize = 128; /// /// Storage for previews. /// static Dictionary s_Cache = null; /// /// Clear and unload cache. /// internal static void UnloadCache() { if (s_Cache == null) return; s_Cache.Clear(); s_Cache = null; } /// /// Fetch preview from cache. Creates one if no cached preview is found /// for a given object. /// /// /// internal static Texture2D GetAssetPreview(Object obj) { if (s_Cache == null) { s_Cache = new Dictionary(k_CacheSize); AssetPreview.SetPreviewTextureCacheSize(k_CacheSize); } if (s_Cache.ContainsKey(obj) == false) s_Cache.Add(obj, new MeshPreview(obj)); MeshPreview preview = s_Cache[obj]; preview.UpdatePreview(); return preview.previewTexture; } } }