public IPromise <BundleLoadData> LoadBundle(BundleLoadData loadData) { Promise <BundleLoadData> promise = new Promise <BundleLoadData>(); _promisesMap.Add(loadData, promise); if (_pathDataMap.ContainsKey(loadData.Path)) { var predata = _pathDataMap[loadData.Path]; // Debug.Log(loadData.Path + " already loaded."); promise.Resolve(predata); } else { if (!_isBusy) { _isBusy = true; LoadBundleInner(loadData); } else { // Debug.Log("Queued " + loadData.Name); _queue.Enqueue(loadData); } } return(promise); }
public IPromise <BundleLoadData> LoadBundle(string name, string path, bool load = false) { var loadData = new BundleLoadData { Name = name, Load = load, Path = path, Vers = (uint)versionBase }; return(LoadBundle(loadData)); }
protected void LoadBundleInner(BundleLoadData data) { if (_pathDataMap.ContainsKey(data.Path)) { // _promisesMap[data].Reject(new BundleAlreadyLoadedException(data)); _promisesMap[data].Resolve(_pathDataMap[data.Path]); CheckQueue(); return; } _isBusy = true; root.StartCoroutine(LoadBundleWithUrl(data)); }
protected IEnumerator LoadBundleWithUrl(BundleLoadData data) { while (!Caching.ready) { yield return(null); } //Debug.Log(data.Path); using (UnityWebRequest www = new UnityWebRequest(data.Path)) { DownloadHandlerAssetBundle handler = new DownloadHandlerAssetBundle(www.url, data.Vers, 0); //DownloadHandlerAssetBundle handler = new DownloadHandlerAssetBundle(www.url, data.Vers, 0); www.downloadHandler = handler; yield return(www.SendWebRequest()); if (www.error != null) { var exception = new Exception(www.error); _promisesMap[data].Reject(exception); Debug.LogWarning(data.Name + " bundle loading problem. " + www.error + " " + data.Path); CheckQueue(); yield break; } data.Bundle = handler.assetBundle; Clear(data.Name); _pathDataMap.Add(data.Path, data); _bundleMap.Add(data.Name, data); if (data.Load && data.Bundle != null) { AsyncOperation loadOperation = data.Bundle.LoadAllAssetsAsync(); if (loadOperation != null) { while (!loadOperation.isDone) { yield return(null); } } } CheckQueue(); //Load Success _promisesMap[data].Resolve(data); } }