コード例 #1
0
ファイル: AssetLoader.cs プロジェクト: happylays/tbb2
        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);
            }
        }
コード例 #2
0
ファイル: AssetLoader.cs プロジェクト: happylays/tbb2
        /// <summary>
        /// 内部下载接口;
        /// </summary>
        private void LoadAsset(string assetName, bool bResident, Callback <string> callBack, bool isOnlyDownLoad, DownLoadOrderType downLoadOrderType, bool isKeepLoading)
        {
            AssetPack assetPack = null;

            if (m_AllAssets.ContainsKey(assetName))
            {
                assetPack = m_AllAssets[assetName];
                if (!assetPack.m_IsResident)
                {
                    if (bResident)
                    {
                        assetPack.m_IsResident = true;
                        assetPack.m_AssetRefer = 0;
                    }
                    else
                    {
                        if (isKeepLoading)                        //如果外部设置为KeepLoading,那么资源会切换为KeepLoading状态;
                        {
                            assetPack.m_nKeepLoadingRefer++;
                        }
                        assetPack.m_AssetRefer++;
                    }
                }
                assetPack.m_CallBack += callBack;

                if (assetPack.AssetReady)
                {
                    if (callBack != null)
                    {
                        callBack(assetName);
                    }
                }
            }
            else
            {
                assetPack = new AssetPack(assetName, bResident, isKeepLoading);
                m_AllAssets.Add(assetName, assetPack);
                assetPack.m_CallBack += callBack;

                DownLoadCoroutine gtDLC = GetAssetLoadCoroutine(assetName);
                if (gtDLC != null)
                {
                    gtDLC.StartCoroutine(LoadingAsset(assetName, isOnlyDownLoad, downLoadOrderType));
                }
                else
                {
                    Debug.LogError("AssetLoader LoadAssetAsync,Coroutine Obj can not be null.");
                }
            }
        }
コード例 #3
0
ファイル: AssetLoader.cs プロジェクト: happylays/tbb2
        /// <summary>
        /// 对外接口同步下载;
        /// </summary>
        public IEnumerator LoadAssetSync(string assetName, bool bResident, bool isOnlyDownLoad, DownLoadOrderType downLoadOrderType, bool isKeepLoading)
        {
            LoadAsset(assetName, bResident, null, isOnlyDownLoad, downLoadOrderType, isKeepLoading);

            while (!ChechLoadReady(assetName))
            {
                yield return(null);
            }

            Messenger.Broadcast(MessangerEventDef.LOAD_ONEASSET_FINISH, MessengerMode.DONT_REQUIRE_LISTENER);
        }
コード例 #4
0
ファイル: AssetLoader.cs プロジェクト: happylays/tbb2
 /// <summary>
 /// 对外接口异步下载;
 /// </summary>
 public void LoadAssetAsync(string assetName, bool bResident, Callback <string> callBack, bool isOnlyDownLoad, DownLoadOrderType downLoadOrderType, bool isKeepLoading)
 {
     LoadAsset(assetName, bResident, callBack, isOnlyDownLoad, downLoadOrderType, isKeepLoading);
 }
コード例 #5
0
ファイル: WWWDownloader.cs プロジェクト: happylays/tbb2
        /// <summary>
        /// 下载任务;
        /// </summary>
        /// <param name="strName">资源唯一key;</param>
        /// <param name="strURL">资源下载完整URL(包含资源名,由外部组合. 不包含服务器IP地址)</param>
        /// <param name="assetType">资源类型;</param>
        /// <param name="callBack">外部的回调;</param>
        /// <param name="exData">附加信息(音效提取有附加参数);</param>
        static public DownLoadPack InsertDownLoad(string strName, string strURL, DownLoadAssetType assetType, Callback <object> callBack, object exData, DownLoadOrderType downLoadOrderType, bool debugError)
        {
            DownLoadPack pack = null;

            if (!m_IgnoreDownLoad)
            {
                pack = AddDownLoadAssetPack(strName, strURL, assetType, callBack, exData, debugError);

                switch (downLoadOrderType)
                {
                case DownLoadOrderType.Head:
                {
                    if (m_AssetPackNameList.Contains(strName))                                    //重复情况,重新插入队首;
                    {
                        m_AssetPackNameList.Remove(strName);
                    }
                    m_AssetPackNameList.Insert(0, strName);
                }
                break;

                case DownLoadOrderType.AfterRunning:
                {
                    int          nIndex     = 0;                        //第一个等待下载的资源索引;
                    DownLoadPack curResPack = null;

                    for (nIndex = 0; nIndex < m_AssetPackNameList.Count; nIndex++)
                    {
                        if (m_AssetPackMap.ContainsKey(strName))
                        {
                            DownLoadPack gtPack = m_AssetPackMap[m_AssetPackNameList[nIndex]];
                            if (gtPack == null)
                            {
                                Debug.LogWarning("WWWDownLoader InsertDownLoadToWaittingBegin, gtPack can not be null.");
                                continue;
                            }
                            else
                            {
                                //获取第一个等待下载的资源的索引;
                                if (gtPack.State == AssetState.Waitting || gtPack.State == AssetState.HasRelease)
                                {
                                    break;
                                }

                                //从下载队列里面获取目标资源;
                                if (gtPack.AssetInfo.m_strName.Equals(strName))
                                {
                                    curResPack = gtPack;
                                }
                            }
                        }
                    }

                    if (curResPack == null || curResPack.State != AssetState.DownLoading)
                    {
                        if (m_AssetPackNameList.Contains(strName))
                        {
                            m_AssetPackNameList.Remove(strName);
                        }
                        m_AssetPackNameList.Insert(nIndex, strName);
                    }
                }
                break;

                default:
                    Debug.LogError("WWWDownLoader InsertDownLoad, error name : " + strName + " ,downLoadOrderType: " + downLoadOrderType);
                    break;
                }

                if (m_IsShowTipsBox)
                {
                    m_WaittingAssetPackList.Add(strName);
                    Messenger <Callback, Callback> .Broadcast(MessangerEventDef.DOWNLOAD_MOBILE_TIPSBOX, TipBoxCallBackYes, TipBoxCallBackNo);
                }
                else
                {
                    StartAll();
                }
            }

            return(pack);
        }
コード例 #6
0
ファイル: WWWDownloader.cs プロジェクト: happylays/tbb2
 static public DownLoadPack InsertDownLoad(string strName, string strURL, DownLoadAssetType assetType, Callback <object> callBack, object exData, DownLoadOrderType downLoadOrderType)
 {
     return(InsertDownLoad(strName, strURL, assetType, callBack, exData, downLoadOrderType, false));
 }