/// <summary> /// 同步加载 /// </summary> /// <param name="fullPath"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public T Load <T>(string path) where T : UnityEngine.Object { //BDebug.Log("加载:" + path); //1.依赖路径 var dependAssets = config.Manifest.GetDirectDependenciesByName(path); if (dependAssets == null) { return(null); } //同步加载 foreach (var res in dependAssets) { //1.判断是否有多个ab在1个Package中 var item = config.Manifest.GetManifestItemByHash(res); var realPath = res; //如果有package if (item != null && !string.IsNullOrEmpty(item.Package)) { realPath = item.Package; } if (!assetbundleMap.ContainsKey(realPath)) { var p = FindAsset(realPath); var ab = AssetBundle.LoadFromFile(p); //添加 AddAssetBundle(realPath, ab); } else { AssetBundleWapper abw = null; if (assetbundleMap.TryGetValue(realPath, out abw)) { abw.Use(); } else { return(null); } } } return(LoadFormAssetBundle <T>(dependAssets.Last())); }
/// <summary> /// 加载AssetBundle /// </summary> /// <param name="path"></param> /// <returns></returns> private AssetBundle LoadAssetBundle(string path) { if (AssetbundleMap.ContainsKey(path)) { AssetBundleWapper abw = null; if (AssetbundleMap.TryGetValue(path, out abw)) { abw.Use(); return(abw.AssetBundle); } } else { var p = FindAsset(path); var ab = AssetBundle.LoadFromFile(p); //添加 AddAssetBundle(path, ab); return(ab); } return(null); }