Esempio n. 1
0
 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;
         }
     }
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public virtual void RemoveBundleLoader(BundleLoader loader)
        {
            if (this.loaders == null)
            {
                return;
            }

            this.loaders.Remove(loader.BundleInfo.Name);
        }
Esempio n. 5
0
        public virtual void AddBundleLoader(BundleLoader loader)
        {
            if (this.loaders == null)
            {
                return;
            }

            this.loaders.Add(loader.BundleInfo.Name, loader);
        }
Esempio n. 6
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         this.loader   = null;
         this.result   = null;
         this.routine  = null;
         this.disposed = true;
     }
 }
Esempio n. 7
0
        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);
        }
Esempio n. 8
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. 9
0
 public InternalBundleWrapper(BundleLoader loader, IBundle bundle)
 {
     this.loader = loader;
     this.bundle = bundle;
     this.loader.Retain();
 }
Esempio n. 10
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);
            }
        }
Esempio n. 11
0
        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);
            }
        }