protected virtual void Dispose(bool disposing) { if (!disposed) { try { if (this.loader != null) { /* Must be released in the main thread */ Executors.RunOnMainThread(() => { this.loader.Release(); this.loader = null; }); } } catch (System.Exception) { } finally { disposed = true; } } }
public LoadingTask(IProgressPromise <TProgress, TResult> result, IEnumerator routine, BundleLoader loader) { this.result = result; this.routine = routine; this.loader = loader; this.startTime = System.DateTime.Now.Ticks / 10000; }
protected virtual BundleLoader CreateBundleLoader(BundleInfo rootBundleInfo, BundleInfo bundleInfo, int priority) { BundleLoader loader = this.GetBundleLoader(bundleInfo.Name); if (loader != null) { loader.Priority = priority; return(loader); } List <BundleLoader> dependencies = new List <BundleLoader>(); foreach (BundleInfo info in this.bundleManifest.GetDependencies(bundleInfo.Name, false)) { if (info.Equals(rootBundleInfo)) { throw new LoopingReferenceException(string.Format("Error creating AssetBundle loader with name '{0}'.It has an unresolvable loop reference between '{0}' and '{1}'.", rootBundleInfo.Name, bundleInfo.Name)); } dependencies.Add(CreateBundleLoader(rootBundleInfo, info, priority)); } loader = this.loaderBuilder.Create(this, bundleInfo, dependencies.ToArray()); loader.Priority = priority; return(loader); }
public virtual void RemoveBundleLoader(BundleLoader loader) { if (this.loaders == null) { return; } this.loaders.Remove(loader.BundleInfo.Name); }
public virtual void AddBundleLoader(BundleLoader loader) { if (this.loaders == null) { return; } this.loaders.Add(loader.BundleInfo.Name, loader); }
protected virtual void Dispose(bool disposing) { if (!disposed) { this.loader = null; this.result = null; this.routine = null; this.disposed = true; } }
public virtual List <BundleLoader> GetOrCreateDependencies(BundleInfo bundleInfo, bool recursive, int priority) { List <BundleLoader> dependencies = new List <BundleLoader>(); BundleInfo[] bundleInfos = this.BundleManifest.GetDependencies(bundleInfo.Name, recursive); foreach (BundleInfo info in bundleInfos) { BundleLoader loader = this.GetOrCreateBundleLoader(info, priority); dependencies.Add(loader); } return(dependencies); }
public virtual IProgressResult <float, IBundle> LoadBundle(BundleInfo bundleInfo, int priority) { try { if (bundleInfo == null) { throw new ArgumentNullException("The bundleInfo is null!"); } BundleLoader loader = this.CreateBundleLoader(bundleInfo, priority); return(loader.Load()); } catch (Exception e) { return(new ImmutableProgressResult <float, IBundle>(e, 0f)); } }
public InternalBundleWrapper(BundleLoader loader, IBundle bundle) { this.loader = loader; this.bundle = bundle; this.loader.Retain(); }
protected virtual IEnumerator DoLoadBundle(IProgressPromise <float, IBundle[]> promise, BundleInfo[] bundleInfos, int priority) { List <IBundle> bundles = new List <IBundle>(); Exception exception = new Exception("unkown"); List <IProgressResult <float, IBundle> > bundleResults = new List <IProgressResult <float, IBundle> >(); for (int i = 0; i < bundleInfos.Length; i++) { try { BundleLoader loader = this.CreateBundleLoader(bundleInfos[i], priority); IProgressResult <float, IBundle> bundleResult = loader.Load(); bundleResult.Callbackable().OnCallback(r => { if (r.Exception != null) { exception = r.Exception; if (log.IsWarnEnabled) { log.WarnFormat("Loads Bundle failure! Error:{0}", r.Exception); } } else { bundles.Add(r.Result); } }); if (!bundleResult.IsDone) { bundleResults.Add(bundleResult); } } catch (Exception e) { exception = e; if (log.IsWarnEnabled) { log.WarnFormat("Loads Bundle '{0}' failure! Error:{1}", bundleInfos[i], e); } } } bool finished = false; float progress = 0f; int count = bundleResults.Count; while (!finished && count > 0) { yield return(null); progress = 0f; finished = true; for (int i = 0; i < count; i++) { var result = bundleResults[i]; if (!result.IsDone) { finished = false; } progress += result.Progress; } promise.UpdateProgress(progress / count); } promise.UpdateProgress(1f); if (bundles.Count > 0) { promise.SetResult(bundles.ToArray()); } else { promise.SetException(exception); } }
protected virtual IEnumerator DoLoadBundleAndDependencies(IProgressPromise <float, IBundle> promise) { this.startTime = Time.realtimeSinceStartup; List <IProgressResult <float, AssetBundle> > results = new List <IProgressResult <float, AssetBundle> >(); BundleLoader currLoader = manager.GetOrCreateBundleLoader(this.BundleInfo, this.Priority); currLoader.Retain(); loaders.Add(currLoader); IProgressResult <float, AssetBundle> currResult = currLoader.LoadAssetBundle(); if (!currResult.IsDone) { results.Add(currResult); } var dependencies = manager.GetOrCreateDependencies(this.BundleInfo, true, this.Priority); for (int i = 0; i < dependencies.Count; i++) { var dependency = dependencies[i]; dependency.Retain(); this.loaders.Add(dependency); var result = dependency.LoadAssetBundle(); if (!result.IsDone) { results.Add(result); } } bool finished = false; float progress = 0f; float timeProgress = 0f; int count = results.Count; while (!finished && count > 0) { yield return(null); progress = 0f; finished = true; for (int i = 0; i < count; i++) { var result = results[i]; if (!result.IsDone) { finished = false; } progress += result.Progress; } timeProgress = TIME_PROGRESS_WEIGHT * Mathf.Atan(Time.realtimeSinceStartup - this.startTime) * 2 / Mathf.PI; promise.UpdateProgress(timeProgress + (1.0f - TIME_PROGRESS_WEIGHT) * progress / count); } promise.UpdateProgress(1f); yield return(null); if (currResult.Exception != null) { promise.SetException(currResult.Exception); } else { this.assetBundle = currResult.Result; promise.SetResult(this); } }