/// <summary> /// 检查是否已在缓存 /// </summary> /// <param name="group">加载组</param> /// <param name="name">AssetBundle名称</param> /// <param name="onLoaded">完成回调</param> /// <param name="persistent">是否常驻</param> /// <param name="async">是否异步</param> /// <returns>已缓存(是-引用计数+1,并返回true, 否-返回false)</returns> public bool CheckAssetBundleInfo(LoaderGroup group, string name, LoadMgr.GroupLoadedCallback onLoaded, bool persistent, bool async) { AssetBundleInfo info = GetAssetBundleInfo(name, persistent); if (info == null) { AddAssetBundleInfo(name, persistent); return(false); } if (info.Bundle == null) { return(false); } if (onLoaded != null) { if (!async) { onLoaded(group, info); } else { m_task.AddAsyncCallback(onLoaded, group, info); } } return(true); }
// 加载AssetBundle(先从persistentData读,没有找到则从streamingAssets读,带后缀) private void LoadAssetBundle(LoaderGroup group, string path, GroupLoadedCallback onLoaded, bool async = true, bool persistent = false, bool manifest = true, LoadPriority priority = LoadPriority.Normal) { path = path.ToLower(); if (async && group == null) { group = m_task.PopGroup(priority); } if (manifest) { if (!HasBundle(path)) { // Manifest里没有这个AssetBundle,说明是一个错误的路径 Logger.LogError(string.Format("ab不存在:{0}", path)); if (onLoaded != null) { if (!async) { onLoaded(group, null); } else { m_task.AddAsyncCallback(onLoaded, group, null); } } return; } // 加载依赖 LoadDependencies(group, path, async, persistent); } // 检查是否有缓存 if (m_cache.CheckAssetBundleInfo(group, path, onLoaded, persistent, async)) { return; } // 添加加载任务 m_task.AddLoadTask(group, Loader.LoaderType.Bundle, path, null, (group1, data) => { AssetBundle ab = data as AssetBundle; AssetBundleInfo info = null; if (ab != null) { info = m_cache.SetAssetBundle(path, ab); #if UNITY_EDITOR RefreshShader(ab); #endif } // 加载回调 if (onLoaded != null) { onLoaded(group1, info); } }, async, priority); }