Пример #1
0
        private void LoadPartial(CascadeLoading cascade, List <IProcess> processList, IEnumerable <DependencyNode> assetBundles, bool async)
        {
            foreach (var assetBundleNode in assetBundles)
            {
                string assetBundle = assetBundleNode.assetBundleName;
                if (_loading.ContainsKey(assetBundle))
                {
                    //loading at this moment
                    var loader = _loading[assetBundle];
                    cascade.AddFuture(loader);

                    processList?.Add(loader);
                    _loaded[assetBundle].loadedCount++;
                }
                else
                {
                    if (_loaded.ContainsKey(assetBundle) && !_loading.ContainsKey(assetBundle))
                    {
                        //already downloaded
                        _loaded[assetBundle].loadedCount++;
                        continue;
                    }

                    //first load
                    var node   = repository[assetBundle];
                    var loader = new LoadAssetBundlePromise(assetBundle, assetBundlesUrl, assetBundleNode.parentNode != null, node.hash, node.crc32, async);
                    _loading.Add(assetBundle, loader);
                    _loaded.Add(assetBundle, new AssetBundleRef(assetBundle, assetBundleNode.parentNode != null));
                    string bundle = assetBundle;

                    loader.AddListener(future =>
                    {
                        loadedPackedSize += repository[bundle].packedSize;
                        _loading.Remove(bundle);
                        var ab         = _loaded[bundle];
                        ab.allAssets   = loader.GetAssets();
                        ab.assetBundle = loader.assetBundle;
                        ab.request     = loader.request;
                    });

                    cascade.AddFuture(loader);
                    processList?.Add(loader);
                }
            }
        }
Пример #2
0
        public IFuture Load(string mainAssetBundle, out List <IProcess> processList, bool async = true)
        {
            var cascade = new CascadeLoading();
            var node    = new DependencyNode(mainAssetBundle, null);

            CollectDependencies(node);
            var assetBundles = new List <DependencyNode>();

            processList = new List <IProcess>();
            while (!GetLatestDependencies(node, assetBundles))
            {
                LoadPartial(cascade, processList, assetBundles, async);
                assetBundles.Clear();
                cascade.Next();
            }

            return(new CascadeLoadingPromise(cascade).Run());
        }