protected override void OnBundleLoaded(UBundle bundle) { if (_disposed) { Complete(); return; } // assert (bundle == _bundle) var assetBundle = _bundle.GetAssetBundle(); if (assetBundle != null) { if ((_hints & EAssetHints.Synchronized) == 0) { _bundle._LoadAsset(_LoadAsync(assetBundle)); } else { _LoadSync(assetBundle); } } else { Complete(); // failed } }
// open file stream (file must be listed in manifest) private void OpenBundle(UBundle bundle) { var filename = bundle.name; if (LoadBundleFile(bundle, _localPathRoot)) { return; } // 无法打开现有文件, 下载新文件 bundle.AddRef(); AddDownloadTask(DownloadTask.Create( bundle.name, bundle.checksum, bundle.size, bundle.priority, _urls, _localPathRoot, -1, 10, self => { _tasks.Remove(self); _runningTasks--; Schedule(); if (!LoadBundleFile(bundle, _localPathRoot)) { bundle.Load(null); } bundle.RemoveRef(); })); }
// open file stream (file must be listed in manifest) private void OpenBundle(UBundle bundle) { var filename = bundle.name; if (LoadBundleFile(bundle, _localPathRoot)) { return; } if (_streamingAssets != null && _streamingAssets.Contains(bundle.name, bundle.checksum, bundle.size)) { bundle.AddRef(); JobScheduler.DispatchCoroutine( _streamingAssets.LoadBundle(bundle.name, stream => { if (stream != null) { bundle.Load(stream); } else { PrintLog($"read from streamingassets failed: {bundle.name}"); DownloadBundleFile(bundle); } bundle.RemoveRef(); }) ); return; } DownloadBundleFile(bundle); }
private void OnDependedBundleLoaded(UBundle bundle) { if (_loaded && _IsDependenciesLoaded()) { OnLoaded(); } }
private void OnBundleLoaded(UBundle bundle) { if (_disposed) { return; } Complete(); }
protected virtual void OnBundleLoaded(UBundle bundle) { if (_disposed) { return; } Complete(); }
protected virtual void OnBundleLoaded(UBundle bundle) { if (_disposed) { return; } // _bundle.ReadAllBytes(_assetPath); Complete(); }
private bool LoadBundleFile(UBundle bundle, string localPathRoot) { var fullPath = Path.Combine(localPathRoot, bundle.name); var fileStream = Utils.Helpers.GetBundleStream(fullPath, bundle.bundleInfo); if (fileStream != null) { bundle.Load(fileStream); // 生命周期转由 UAssetBundleBundle 管理 return(true); } return(false); }
private void OnDependedBundleLoaded(UBundle bundle) { if (_disposed) { return; } if (_loaded && _IsDependenciesLoaded()) { OnLoaded(); } }
private void DownloadBundleFile(UBundle bundle) { // 无法打开现有文件, 下载新文件 bundle.AddRef(); AddDownloadTask(DownloadTask.Create(bundle.bundleInfo, _urls, _localPathRoot, -1, 10, self => { RemoveDownloadTask(self); if (!LoadBundleFile(bundle, _localPathRoot)) { bundle.Load(null); } bundle.RemoveRef(); }), true); }
private bool LoadBundleFile(UBundle bundle) { var fullPath = Path.Combine(_localPathRoot, bundle.name); var fileStream = Utils.Helpers.GetBundleStream(fullPath, bundle.bundleInfo); if (fileStream != null) { // Stream 生命周期转由 UAssetBundleBundle 管理 bundle.Load(Utils.Helpers.GetDecryptStream(fileStream, bundle.bundleInfo, _password)); return(true); } return(false); }
//TODO: hints private UBundle GetBundle(Manifest.BundleInfo bundleInfo, EAssetHints hints) { if (_closed) { return(null); } UBundle bundle = null; if (bundleInfo != null) { var bundleName = bundleInfo.name; if (!_bundles.TryGetValue(bundleName, out bundle)) { switch (bundleInfo.type) { case Manifest.BundleType.AssetBundle: bundle = new UAssetBundleBundle(this, bundleInfo, hints); break; case Manifest.BundleType.ZipArchive: bundle = new UZipArchiveBundle(this, bundleInfo); break; case Manifest.BundleType.FileList: bundle = new UFileListBundle(this, bundleInfo); break; } if (bundle != null) { _bundles.Add(bundleName, bundle); _AddDependencies(bundle, hints, bundle.bundleInfo.dependencies); // 第一次访问 UBundle 时进入此处逻辑, 但这之前可能已经使用 EnsureBundles 等方式发起文件下载 // 优先检查是否已经存在下载中的任务, 如果已经存在下载任务, 任务完成时将自动调用 UBundle.Load(stream) var bundleJob = _FindDownloadJob(bundle.name); if (bundleJob == null) { if (!LoadBundleFile(bundle)) { DownloadBundleFile(bundle.bundleInfo, null); } } } } } return(bundle); }
protected override void OnBundleLoaded(UBundle bundle) { // assert (bundle == _bundle) var assetBundle = _bundle.GetAssetBundle(); if (assetBundle != null) { var request = assetBundle.LoadAssetAsync(_assetPath); request.completed += OnAssetLoaded; } else { Complete(); // failed } }
private void _AddDependencies(UBundle bundle, EAssetHints hints, string[] dependencies) { if (dependencies != null) { for (int i = 0, size = dependencies.Length; i < size; i++) { var depBundleInfo = dependencies[i]; var depBundle = GetBundle(depBundleInfo, hints); if (bundle.AddDependency(depBundle)) { _AddDependencies(bundle, hints, depBundle.bundleInfo.dependencies); } } } }
private bool LoadBundleFile(UBundle bundle) { try { var fullPath = Path.Combine(_localPathRoot, bundle.name); var fileStream = Utils.Helpers.GetBundleStream(fullPath, bundle.bundleInfo); if (fileStream != null) { // Stream 生命周期转由 UAssetBundleBundle 管理 bundle.Load(Utils.Helpers.GetDecryptStream(fileStream, bundle.bundleInfo, _password)); return(true); } } catch (Exception exception) { Debug.LogErrorFormat("LoadBundleFile({0}) exception\n{1}", bundle.name, exception); } return(false); }
protected override void OnBundleLoaded(UBundle bundle) { if (_disposed) { Complete(); return; } // assert (bundle == _bundle) var assetBundle = _bundle.GetAssetBundle(); if (assetBundle != null) { _bundle._LoadAsset(_Load(assetBundle)); } else { Complete(); // failed } }
private void OnRelease() { if (!_disposed) { _disposed = true; GC.Collect(); var count = _bundles.Count; if (count > 0) { var bundles = new UBundle[count]; _bundles.Values.CopyTo(bundles, 0); for (var i = 0; i < count; i++) { var bundle = bundles[i]; // PrintLog($"关闭管理器, 强制释放资源包 {bundle.name}"); bundle.Release(); } } } }
protected override void OnBundleLoaded(UBundle bundle) { if (_disposed) { Complete(); return; } // assert (bundle == _bundle) var assetBundle = _bundle.GetAssetBundle(); if (assetBundle != null) { var request = _type != null?assetBundle.LoadAssetAsync(_assetPath, _type) : assetBundle.LoadAssetAsync(_assetPath); request.completed += OnAssetLoaded; } else { Complete(); // failed } }
// 添加依赖资源包 public bool AddDependency(UBundle bundle) { if (bundle != this) { if (_denpendencies == null) { _denpendencies = new List <UBundle>(); } else { if (_denpendencies.Contains(bundle)) { return(false); } } bundle.AddRef(); _denpendencies.Add(bundle); bundle.completed += OnDependedBundleLoaded; return(true); } return(false); }
protected virtual void OnBundleLoaded(UBundle bundle) { // assert (bundle == _bundle) Complete(); // failed }
private void _OnClosing() { // 终止所有任务 _jobs.Clear(); _worker.Abort(); _idleWorker.Abort(); // while (_assetLoaders.Count > 1) // { // _assetLoaders.RemoveLast(); // } // // while (_bundleLoaders.Count > 1) // { // _bundleLoaders.RemoveLast(); // } // // // 等待加载中的资源完成 // while (_assetLoaders.Count == 1) // { // yield return null; // } // // while (_bundleLoaders.Count == 1) // { // yield return null; // } _assetLoaders.Clear(); _bundleLoaders.Clear(); var assetCount = _assets.Count; if (assetCount > 0) { var assets = new WeakReference[assetCount]; _assets.Values.CopyTo(assets, 0); for (var i = 0; i < assetCount; i++) { var weak = assets[i]; if (weak.IsAlive) { var asset = weak.Target as UAsset; asset?.Dispose(); } } _assets.Clear(); } var bundleCount = _bundles.Count; if (bundleCount > 0) { var bundles = new UBundle[bundleCount]; _bundles.Values.CopyTo(bundles, 0); for (var i = 0; i < bundleCount; i++) { var bundle = bundles[i]; // PrintLog($"关闭管理器, 强制释放资源包 {bundle.name}"); bundle.Release(); } _bundles.Clear(); } }
protected void Unload(UBundle bundle) { _bundles.Remove(bundle.name); // Debug.LogFormat("bundle unloaded: {0}", bundle.name); }
protected void Unload(UBundle bundle) { _bundles.Remove(bundle.name); PrintLog($"bundle unloaded: {bundle.name}"); }
protected virtual void OnBundleLoaded(UBundle bundle) { // _bundle.ReadAllBytes(_assetPath); Complete(); }
protected virtual void OnBundleLoaded(UBundle bundle) { Complete(); }
private void OnBundleLoaded(UBundle bundle) { Complete(); }