Example #1
0
 public void TryRelease()
 {
     bh.TryRelease();
 }
Example #2
0
    public IEnumerator AsyncLoadBundle(string path, LoadBundleDelegate lbd)
    {
        if (bundles.ContainsKey(path))
        {
            BundleHolder bh = bundles[path];
            if (bh.bundle)
            {
                lbd?.Invoke(bh);
            }
            else
            {
                bh.afterLoad += lbd;
            }
        }
        else
        {
            BundleHolder bh = new BundleHolder();
            bh.br         = this;
            bh.bundleName = path;
            AddBundle(path, bh);

            bool fail     = false;
            int  depCount = 0;
            if (depMap.ContainsKey(path))
            {
                List <string> depList = depMap[path];
                depCount = depList.Count;
                foreach (string depName in depList)
                {
                    StartCoroutine(AsyncLoadBundle(depName, delegate(BundleHolder bh1)
                    {
                        if (bh1 == null)
                        {
                            fail = true;
                            return;
                        }

                        if (fail)
                        {
                            bh1.TryRelease();
                        }
                        else
                        {
                            BundleRef br = new BundleRef();
                            br.bh        = bh1;
                            bh.AddRef(br);
                        }
                    }));
                }
            }

            string readPath = Path.Combine(Application.dataPath, "../../Bundle", path);
            AssetBundleCreateRequest abcr = AssetBundle.LoadFromFileAsync(readPath);

            while (true)
            {
                if (fail)
                {
                    bh.TryRelease();
                    lbd?.Invoke(null);
                    bh.AfterLoad(null);
                    yield break;
                }
                else
                {
                    if (bh.bundleRefs.Count == depCount)
                    {
                        if (abcr.isDone)
                        {
                            AssetBundle ab = abcr.assetBundle;
                            if (ab != null)
                            {
                                bh.bundle = ab;
                                lbd?.Invoke(bh);
                                bh.AfterLoad(bh);
                                yield break;
                            }
                            else
                            {
                                bh.TryRelease();
                                lbd?.Invoke(null);
                                bh.AfterLoad(null);
                                yield break;
                            }
                        }
                        else
                        {
                            yield return(null);
                        }
                    }
                    else
                    {
                        yield return(null);
                    }
                }
            }
        }
    }