コード例 #1
0
        IEnumerator ErrorOcurredRepeat(AssetTask task)
        {
            bool   errorOcurred    = false;
            string assetBundleName = task.AssetBundleName;


            ConsoleEx.DebugLog("   in    error occrredddd     ");
            string url    = ResourceSetting.ConverToFtpPath(assetBundleName);
            int    verNum = Core.Data.sourceManager.getNewNum(assetBundleName + ".unity3d");

            WWW www = null;

            try {
                www = WWW.LoadFromCacheOrDownload(url, verNum);
            } catch (Exception ex) {
                errorOcurred = true;
                // ConsoleEx.DebugLog("LoadFromCacheOrDownload Error : " + ex.ToString());
                if (task.LoadError != null)
                {
                    task.LoadError("[" + assetBundleName + "]:" + ex.ToString());
                }
            }

            if (!errorOcurred)
            {
                if (!dicLoadingReq.ContainsKey(assetBundleName))
                {
                    dicLoadingReq.Add(assetBundleName, www);
                }
                while (www.isDone == false)
                {
                    if ((task.LoadType == AssetTask.loadType.Only_Download || task.LoadType == AssetTask.loadType.Both_Download_loadlocal) &&
                        task.reportProgress != null)
                    {
                        task.reportProgress(www.progress);
                    }
                    yield return(null);
                }

                // Print the error to the console
                if (!String.IsNullOrEmpty(www.error))
                {
                    //ConsoleEx.DebugLog("["+assetBundleName+"]"+www.error);
                    //Debug.LogError ("[" + assetBundleName + "]" + www.error);
                    if (task.LoadError != null)
                    {
                        task.LoadError(www.error);
                    }
                    ConsoleEx.DebugLog("     still   error   ");
                    dicLoadingReq.Remove(assetBundleName);
                    errorOcurred = true;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// According to LoadType, it will download or load local sync
        /// 把AssetBundle载入内存,之后再异步Load出来,之后再次删除Assetbundle内存镜像.
        /// </summary>
        /// <returns>The load coroutine.</returns>
        /// <param name="task">Task.</param>
        private IEnumerator AsyncLoadCoroutine(AssetTask task)
        {
            bool errorOcurred = false;

            string assetBundleName = task.AssetBundleName;


            string url    = ResourceSetting.ConverToFtpPath(assetBundleName);
            int    verNum = 1;//Core.Data.sourceManager.getNewNum(assetBundleName + ".unity3d");

            // 添加引用
            RefAsset(assetBundleName);

            if (Caching.IsVersionCached(url, verNum) == false)
            {
                //ConsoleEx.DebugLog("Version Is not Cached, which will download from net!");
            }

            WWW www = null;

            try {
                www = WWW.LoadFromCacheOrDownload(url, verNum);
            } catch (Exception ex) {
                errorOcurred = true;
                // ConsoleEx.DebugLog("LoadFromCacheOrDownload Error : " + ex.ToString());
                if (task.LoadError != null)
                {
                    task.LoadError("[" + assetBundleName + "]:" + ex.ToString());
                }
            }

            if (!errorOcurred)
            {
                dicLoadingReq.Add(assetBundleName, www);
                while (www.isDone == false)
                {
                    if ((task.LoadType == AssetTask.loadType.Only_Download || task.LoadType == AssetTask.loadType.Both_Download_loadlocal) &&
                        task.reportProgress != null)
                    {
                        task.reportProgress(www.progress);
                    }
                    yield return(null);
                }

                // Print the error to the console
                if (!String.IsNullOrEmpty(www.error))
                {
                    //ConsoleEx.DebugLog("["+assetBundleName+"]"+www.error);
                    Debug.LogError("[" + assetBundleName + "]" + www.error);

                    if (task.LoadError != null)
                    {
                        task.LoadError(www.error);
                    }
                    dicLoadingReq.Remove(assetBundleName);
                    errorOcurred = true;
                }

                bool TaskEnd = false;

                if (task.LoadType == AssetTask.loadType.Only_loadlocal || task.LoadType == AssetTask.loadType.Both_Download_loadlocal)
                {
                    if (!errorOcurred)
                    {
                        AssetBundleRequest req = www.assetBundle.LoadAsync(task.PrefabName, task.UType);
                        while (req.isDone == false)
                        {
                            yield return(null);
                        }

                        dicAsset.Add(assetBundleName, req.asset);
                        task.Obj = req.asset;
                        dicLoadingReq.Remove(assetBundleName);
                        www.assetBundle.Unload(false);

                        //--- load local finished ---
                        TaskEnd = true;
                    }
                }
                else
                {
                    dicLoadingReq.Remove(assetBundleName);

                    //--- Downloading finished ---
                    TaskEnd = true;
                }

                //release memeory
                if (www != null)
                {
                    www.Dispose();
                    www = null;
                }

                //start to callback
                if (TaskEnd)
                {
                    LoadEnd();
                    if (task.LoadFinished != null)
                    {
                        task.LoadFinished(task);
                    }
                }
            }
        }