/// <summary> /// 自定义加载图片 /// 走缓存池 /// </summary> /// <param name="key">缓存键,若为空则取消加载</param> /// <param name="customLoader">自定义加载器</param> /// <param name="callback">图片加载完成回调</param> /// <param name="cacheLevel">缓存优先级</param> public static void Load(string key, ICustomTextureLoader customLoader, Action <Texture2D> callback, CacheLevel cacheLevel = CacheLevel.Cache_0) { if (string.IsNullOrEmpty(key) || customLoader == null) { callback?.Invoke(null); return; } string keyword = ConvertKey(key); Texture2D tex = null; if (_memPool.Get(keyword, out tex)) { callback?.Invoke(tex); } else if (_diskPool.Get(keyword, out tex)) { callback?.Invoke(tex); _memPool.Cache(keyword, tex, cacheLevel); } else { customLoader.Load(key, (resTex) => { callback?.Invoke(resTex); if (resTex != null) { _memPool.Cache(keyword, resTex, cacheLevel); _diskPool.Cache(keyword, resTex, cacheLevel); } }); } }
/// <summary> /// 异步加载任务队列 /// 分帧加载 /// 自定义图片加载 /// </summary> public static void LoadByTask(string key, ICustomTextureLoader customLoader, Action <Texture2D> callback, CacheLevel cacheLevel = CacheLevel.Cache_0) { if (_asyncTask == null) { _asyncTask = Task.CreateTask(AsyncTask()); } _asyncTaskItems.Enqueue(new AsyncItem() { key = key, callback = callback, cacheLevel = cacheLevel, customLoader = customLoader }); }