Example #1
0
 private void _CleanRequest()
 {
     for (int i = 0; i < m_loadRequest.Count; ++i)
     {
         BundleLoadRequest request = m_loadRequest[i];
         request.OnRelease();
     }
     m_loadRequest.Clear();
 }
Example #2
0
        private void _AddDependAb(BundleLoadRequest request)
        {
            if (!request.info.HasDependBundle())
            {
                return;
            }

            for (int i = 0; i < request.info.dependBundle.Count; ++i)
            {
                bool       needLoad   = true;
                BundleInfo dependInfo = m_assetCfg.GetBundleInfo(request.info.dependBundle[i]);
                //find cache
                BundleCache bundle = null;
                if (m_bundleCache.TryGetValue(dependInfo.name, out bundle))
                {
                    needLoad = false;
                    request.OnAssetBundleLoadFinished(dependInfo.name, bundle);
                }
                else
                {
                    //find request
                    for (int k = 0; k < m_loadRequest.Count; ++k)
                    {
                        if (m_loadRequest[k].name.Equals(dependInfo.name))
                        {
                            needLoad = false;
                            break;
                        }
                    }
                }

                if (needLoad)
                {
                    //add depend ab
                    BundleLoadRequest depRequest = new BundleLoadRequest(dependInfo.name, dependInfo, null);

                    _AddDependAb(depRequest);

                    //add self
                    m_loadRequest.Add(depRequest);
                }
            }
        }
Example #3
0
        public void LoadAssetBundleAsync(string name, Action <string, BundleCache> callback)
        {
            BundleInfo info = m_assetCfg.GetBundleInfo(name);

            if (info == null)
            {
                if (callback != null)
                {
                    callback(name, null);
                }
                return;
            }

            //find cache
            BundleCache bundle = null;

            if (m_bundleCache.TryGetValue(name, out bundle))
            {
                bundle.Access();
                callback(name, bundle);
                return;
            }

            //find request
            for (int i = 0; i < m_loadRequest.Count; ++i)
            {
                if (m_loadRequest[i].name.Equals(name))
                {
                    m_loadRequest[i].finishedCallback += callback;
                    return;
                }
            }

            //add depend ab
            BundleLoadRequest request = new BundleLoadRequest(name, info, callback);

            _AddDependAb(request);

            //add self
            m_loadRequest.Add(request);
        }
Example #4
0
        public void OnTick()
        {
            bool isIdle = true;

            //load ab
            for (int i = 0; i < m_loadRequest.Count; ++i)
            {
                if (m_loadRequest[i].GetStatus() == AssetLoadStatus.Wait ||
                    m_loadRequest[i].GetStatus() == AssetLoadStatus.Downloaded)
                {
                    string      name  = m_loadRequest[i].name;
                    BundleCache cache = null;
                    if (m_bundleCache.TryGetValue(name, out cache))
                    {
                        m_loadRequest[i].OnAssetBundleLoadFinished(name, cache);
                        continue;
                    }
                    AssetBundle ab = _LoadAssetBundleSync(name);
                    if (ab == null)
                    {
                        bool isFaild = true;
                        if (m_useDownload && m_loadRequest[i].GetStatus() != AssetLoadStatus.Downloaded)
                        {
                            isFaild = !m_loadRequest[i].DownLoad();
                        }

                        if (isFaild)
                        {
                            m_loadRequest[i].OnAssetBundleLoadFinished(name, null);
                        }
                    }
                    else
                    {
                        isIdle = false;

                        cache        = new BundleCache();
                        cache.name   = name;
                        cache.info   = m_loadRequest[i].info;
                        cache.bundle = ab;
                        cache.Access();
                        m_bundleCache.Add(name, cache);
                        m_loadRequest[i].OnAssetBundleLoadFinished(name, cache);
                        break;  //do one!
                    }
                }
            }

            //check
            for (int i = 0; i < m_loadRequest.Count; ++i)
            {
                if (m_loadRequest[i].GetStatus() == AssetLoadStatus.Loading)
                {
                    isIdle = false;
                    List <string> unRefDepend = m_loadRequest[i].GetUnRefDependName();
                    if (unRefDepend != null)
                    {
                        for (int k = 0; k < unRefDepend.Count; ++k)
                        {
                            BundleCache cache = null;
                            if (m_bundleCache.TryGetValue(unRefDepend[k], out cache))
                            {
                                m_loadRequest[i].OnAssetBundleLoadFinished(unRefDepend[k], cache);
                            }
                        }
                    }
                }
            }

//__end:
            //clear finished request
            for (int i = 0; i < m_loadRequest.Count;)
            {
                BundleLoadRequest request = m_loadRequest[i];
                if (request.GetStatus() == AssetLoadStatus.Finished)
                {
                    request.OnRelease();
                    m_loadRequest.RemoveAt(i);
                }
                else
                {
                    ++i;
                }
            }

            if (isIdle)
            {
                _ReleaseAb(false);
            }
        }