internal override void Load() { bundle = Bundles.Load(assetBundleName); var assetName = Path.GetFileName(url); asset = bundle.assetBundle.LoadAsset(assetName, assetType); }
public void Update() { for (var i = 0; i < _assets.Count; i++) { var item = _assets[i]; if (item.Update() || !item.IsUnused()) { continue; } _unusedAssets.Add(item); _assets.RemoveAt(i); i--; } for (var i = 0; i < _unusedAssets.Count; i++) { var item = _unusedAssets[i]; item.Unload(); LWDebug.Log("Unload->" + item.url); } _unusedAssets.Clear(); Bundles.Update(); }
internal override void Load() { if (!string.IsNullOrEmpty(assetBundleName)) { bundle = Bundles.LoadAsync(assetBundleName); loadState = LoadState.LoadAssetBundle; } else { _request = SceneManager.LoadSceneAsync(sceneName, loadSceneMode); loadState = LoadState.LoadAsset; } }
internal override void Load() { if (!string.IsNullOrEmpty(assetBundleName)) { bundle = Bundles.Load(assetBundleName); if (bundle != null) { SceneManager.LoadScene(sceneName, loadSceneMode); } } else { SceneManager.LoadScene(sceneName, loadSceneMode); } }
internal override void Load() { bundle = Bundles.LoadAsync(assetBundleName); loadState = LoadState.LoadAssetBundle; }
public string[] GetAllDependencies(string path) { string assetBundleName; return(GetAssetBundleName(path, out assetBundleName) ? Bundles.GetAllDependencies(assetBundleName) : null); }
/** * public void Initialize(Action onSuccess, Action<string> onError) * { * * if (string.IsNullOrEmpty(LWUtility.dataPath)) LWUtility.dataPath = Application.streamingAssetsPath; * * LWDebug.Log(string.Format("Init->assetBundleMode: {0} | dataPath :{1}| connServer :{2}", LWUtility.GlobalConfig.assetBundleMode, LWUtility.dataPath, LWUtility.GlobalConfig.connServer), LogColor.green); * * if (LWUtility.GlobalConfig.assetBundleMode) * { * updatePath = LWUtility.updatePath; * var platform = LWUtility.GetPlatform(); * //默认资源路径 * var path = Path.Combine(LWUtility.dataPath, Path.Combine(LWUtility.AssetBundles, platform)) + * Path.DirectorySeparatorChar; * Bundles.OverrideBaseDownloadingUrl += Bundles_overrideBaseDownloadingURL; * * Bundles.Initialize(path, platform, () => * { * var asset = LoadAsync(LWUtility.AssetsManifestAsset, typeof(Manifest)); * asset.completed += obj => * { * var manifest = obj.asset as Manifest; * if (manifest == null) * { * if (onError != null) onError("manifest == null"); * return; * } * * if (string.IsNullOrEmpty(LWUtility.downloadURL)) //将下载地址放在全局配置文件中 * LWUtility.downloadURL = manifest.downloadURL; * Bundles.activeVariants = manifest.activeVariants; * _bundles = manifest.bundles; * var dirs = manifest.dirs; * _bundleAssets = new Dictionary<string, int>(manifest.assets.Length); * for (int i = 0, max = manifest.assets.Length; i < max; i++) * { * var item = manifest.assets[i]; * _bundleAssets[string.Format("{0}/{1}", dirs[item.dir], item.name)] = item.bundle; * } * * if (onSuccess != null) * onSuccess(); * obj.Release(); * }; * }, onError); * } * else * { * if (onSuccess != null) * onSuccess(); * } * } * */ public async UniTask <AssetsManagerRequest> InitializeAsync() { AssetsManagerRequest assetsManagerRequest = new AssetsManagerRequest { isSuccess = true }; if (string.IsNullOrEmpty(LWUtility.dataPath)) { LWUtility.dataPath = Application.streamingAssetsPath; } LWDebug.Log(string.Format("Init->assetBundleMode {0} | dataPath {1}", LWUtility.GlobalConfig.assetBundleMode, LWUtility.dataPath), LogColor.green); //判断当前是否为AB模式 if (LWUtility.GlobalConfig.assetBundleMode) { updatePath = LWUtility.updatePath; var platform = LWUtility.GetPlatform(); //默认资源路径 var path = Path.Combine(LWUtility.dataPath, Path.Combine(LWUtility.AssetBundles, platform)) + Path.DirectorySeparatorChar; Bundles.OverrideBaseDownloadingUrl += Bundles_overrideBaseDownloadingURL; //初始化Bundles BundleRequest bundleRequest = await Bundles.Initialize(path, platform); //Bundle加载出错 if (bundleRequest.error != null) { assetsManagerRequest.isSuccess = false; assetsManagerRequest.error = bundleRequest.error; bundleRequest.Release(); bundleRequest = null; return(assetsManagerRequest); } else { //加载资源的Manifest文件 var assetRequest = await LoadAsyncTask <Manifest>(LWUtility.AssetsManifestAsset); var manifest = assetRequest.asset as Manifest; if (manifest == null) { assetsManagerRequest.isSuccess = false; assetsManagerRequest.error = "manifest == null"; return(assetsManagerRequest); } //设置资源的下载地址,在编辑器下会读取当前Assets下的Manifest。 if (string.IsNullOrEmpty(LWUtility.downloadURL)) { LWUtility.downloadURL = manifest.downloadURL; } Bundles.activeVariants = manifest.activeVariants; _bundles = manifest.bundles; var dirs = manifest.dirs; _bundleAssets = new Dictionary <string, int>(manifest.assets.Length); for (int i = 0, max = manifest.assets.Length; i < max; i++) { var item = manifest.assets[i]; _bundleAssets[string.Format("{0}/{1}", dirs[item.dir], item.name)] = item.bundle; } assetRequest.Release(); bundleRequest.Release(); bundleRequest = null; return(assetsManagerRequest); } } else { return(assetsManagerRequest); } }