public BundleLoadRequest(IBundleDownloadRequest downloadRequest) { dependenciesQueue = new Queue <AsyncOperation>(); downloadRequest.Completed += () => { isMainBundleLoaded = true; Bundle = downloadRequest.Bundle; if (IsLoaded()) { if (onCompleteCallback != null) { onCompleteCallback.Invoke(Bundle); } } }; }
/// <summary> /// Asynchronously load an asset bundle and its dependencies /// </summary> /// <param name="bundleName"></param> /// <returns></returns> public BundleLoadRequest LoadBundleAsync(string bundleName) { AssetBundle loadedBundle; if (assetBundleCache.TryGetBundle(bundleName, out loadedBundle)) { return(new BundleLoadRequest(loadedBundle)); } if (remoteProvider != null && remoteProvider.IsRemoteBundle(bundleName)) { BundleLoadRequest bundleLoadRequest; if (currentDLCDownloadRequests.TryGetValue(bundleName, out bundleLoadRequest)) { return(bundleLoadRequest); } IBundleDownloadRequest downloadRequest = remoteProvider.DownloadBundle(bundleName); bundleLoadRequest = new BundleLoadRequest(downloadRequest); bundleLoadRequest.OnComplete += bundle => { currentDLCDownloadRequests.Remove(bundleName); if (bundle != null) { assetBundleCache.AddBundle(bundleName, bundle, false); } }; currentDLCDownloadRequests.Add(bundleName, bundleLoadRequest); return(bundleLoadRequest); } var request = LoadBundleFromFileAsync(bundleName, false); var dependencies = LoadBundleDependenciesAsync(bundleName); return(new BundleLoadRequest(request, dependencies)); }