public void AddBundleToLoaded(string bundleName, AssetBundle bundle) { AssetMap map; if (bundleLoadTypeMap.TryGetValue(bundleName, out map)) { if (map.type == AssetMap.LoadType.Limited) { if (!limitedBundleCache.ContainsKey(bundleName)) { limitedBundleCache.Add(bundleName, new BundleInfo(bundle, bundleName)); } } else { if (!bundleCache.ContainsKey(bundleName)) { bundleCache.Add(bundleName, new BundleInfo(bundle, bundleName)); } } } else { map = new AssetMap(); map.name = bundleName; map.type = AssetMap.LoadType.None; bundleLoadTypeMap.Add(bundleName, map); if (!bundleCache.ContainsKey(bundleName)) { bundleCache.Add(bundleName, new BundleInfo(bundle, bundleName)); } } }
public IEnumerator PreloadShaderAndFont() { if (!AppConst.AssetBundleMode) { yield break; } string dataPath = Util.DataPath; //数据目录 string resPath = AppPathUtils.StreamingPathFormat(LuaConst.osDir); //游戏包资源目录 //加载shader.ab string shaderABName = "shader.ab"; string shaderFile = Path.Combine(resPath, shaderABName); string outFile = Path.Combine(dataPath, shaderABName); AssetMap map = new AssetMap(); map.name = shaderABName; map.type = AssetMap.LoadType.Preload; bundleLoadTypeMap.Add(shaderABName, map); yield return(preload(shaderFile, outFile, shaderABName)); //加载font.ab string fontABName = "font.ab"; string fontFile = Path.Combine(resPath, fontABName); outFile = Path.Combine(dataPath, fontABName); map = new AssetMap(); map.name = fontABName; map.type = AssetMap.LoadType.Preload; bundleLoadTypeMap.Add(fontABName, map); yield return(preload(fontFile, outFile, fontABName)); font = GetBundleFromLoaded(fontABName).LoadAsset("FZCuYuan") as Font; shaderAssets = GetBundleFromLoaded(shaderABName).LoadAllAssets(); Shader.WarmupAllShaders(); }
private void LoadAssetbundleMap() { var content = File.ReadAllBytes(string.Format("{0}/bundlemap.ab", Util.DataPath)); var decryptoStrs = Encoding.GetString(Crypto.Decode(content)).Split('\n'); for (int i = 0; i < decryptoStrs.Length; ++i) { if (!string.IsNullOrEmpty(decryptoStrs[i])) { var temp = decryptoStrs[i].Split('|'); Debug.Assert(temp.Length == 3); if (assetbundleMap.ContainsKey(temp[0])) { throw new ArgumentException(string.Format("{0} is already exists", temp[0])); } if (temp[0].CustomStartsWith("atlas/")) { assetbundleMap[temp[0].Split('-')[0]] = temp[1]; } else { assetbundleMap[temp[0]] = temp[1]; } if (!bundleLoadTypeMap.ContainsKey(temp[1])) { AssetMap map = new AssetMap(); map.name = temp[1]; map.type = (AssetMap.LoadType)(Convert.ToInt32(temp[2].Trim())); bundleLoadTypeMap[map.name] = map; } //if (temp[2].Trim() == "1" && !preloadAssets.Contains(temp[1])) // preloadAssets.Add(temp[1]); } } }
private void LoadManifest() { string path = string.Format("{0}{1}.ab", Util.DataPath, LuaConst.osDir.ToLower()); if (!File.Exists(path)) { Debug.LogError(string.Format("no manifest file exists in {0}", path)); return; } var allBundle = AssetBundle.LoadFromFile(path); if (allBundle) { allBundleManifest = allBundle.LoadAsset("AssetBundleManifest") as AssetBundleManifest; allBundle.Unload(false); var bundles = allBundleManifest.GetAllAssetBundles(); for (int i = 0; i < bundles.Length; ++i) { AssetMap map; if (bundleLoadTypeMap.TryGetValue(bundles[i], out map)) { var deps = GetAllDependencies(bundles[i]); for (int k = 0; k < deps.Count; ++k) { if (deps[k].Contains("tmp/")) { continue; } if (map.type == AssetMap.LoadType.Preload && !IsBundleLoaded(deps[k])) { AssetMap depMap; if (!bundleLoadTypeMap.TryGetValue(deps[k], out depMap)) { depMap = new AssetMap(); depMap.name = deps[k]; depMap.type = AssetMap.LoadType.Preload; bundleLoadTypeMap[deps[k]] = depMap; } else if (depMap.type != AssetMap.LoadType.Preload) { AssetMap tmp = new AssetMap(); tmp.name = depMap.name; tmp.type = AssetMap.LoadType.Preload; bundleLoadTypeMap[deps[k]] = tmp; } } } } } } }