Beispiel #1
0
 public void UnloadAssetBundle(string assetName)
 {
     if (m_AllAssets.ContainsKey(assetName))
     {
         AssetPack assetPack = m_AllAssets[assetName];
         if (assetPack.AssetReady)
         {
             assetPack.UnloadAssetBundle(false);
         }
     }
 }
Beispiel #2
0
        private IEnumerator LoadingAsset(string assetName, bool isOnlyDownLoad, DownLoadOrderType downLoadOrderType)
        {
            if (m_AllAssets.ContainsKey(assetName))
            {
                AssetPack assetPack = m_AllAssets[assetName];

                string strNetLoadName = assetName + m_strAssetExtension;
                if (WWWDownLoaderConfig.CheckResNeedUpdate(strNetLoadName))                //检查版本,区分是加载or下载;
                {
                    DownLoadPack downloadPack = WWWDownLoader.InsertDownLoad(strNetLoadName, m_strAssetNetDir + strNetLoadName, DownLoadAssetType.AssetBundle, null, null, downLoadOrderType);
                    if (downloadPack != null)
                    {
                        while (!downloadPack.AssetReady)
                        {
                            assetPack.State = downloadPack.State;
                            yield return(null);
                        }

                        //资源交给AssetLoader;结束后删除wwwdownloader的任务;
                        assetPack.m_AssetBundle = downloadPack.Bundle;
                        assetPack.State         = downloadPack.State;
                    }
                    else
                    {
                        assetPack.State = AssetState.Finish;                            //临时处理,若不下载直接标记该资源已经被释放
                    }

                    WWWDownLoader.RemoveDownLoad(strNetLoadName, null);

                    if (isOnlyDownLoad)                    //如果预下载流程;
                    {
                        assetPack.UnloadAssetBundle(true); //only下载,下载完卸载资源,结束后删除wwwdownloader的任务;
                    }
                }
                else
                {
                    if (!isOnlyDownLoad)
                    {
                        IEnumerator itor = assetPack.LoadAsset(m_strAssetWWWDir, m_strAssetDir, m_strInAssetWWWDir, m_strAssetExtension);
                        while (itor.MoveNext())
                        {
                            yield return(null);
                        }
                    }
                    else
                    {
                        assetPack.State = AssetState.Finish;
                    }
                }

                if (assetPack.m_CallBack != null)
                {
                    assetPack.m_CallBack(assetName);
                }

                //下载完后判断是不是需要自主卸载,keepLoading的情况;
                assetPack.m_nKeepLoadingRefer = 0;
                if (!assetPack.m_IsResident && assetPack.m_AssetRefer <= 0 && assetPack.m_nKeepLoadingRefer <= 0)                //非常驻资源,没有外部使用,并且下载完成的情况下;
                {
                    ReleaseAsset(assetName, null, false);
                }
                else
                {
                    ReleaseDownLoadCoroutine(assetName);
                }
            }
            else
            {
                Debug.LogError("AssetLoader LoadingAsset, m_AllAssets dont has key : " + assetName);
            }
        }