Esempio n. 1
0
        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));
            }
        }
Esempio n. 2
0
        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);
            }
        }