Пример #1
0
    /// <summary>
    /// 下载资源
    /// </summary>
    /// <param name="url">url</param>
    /// <param name="handle">下载完成回调</param>
    /// <param name="timeout">超时时间</param>
    /// <param name="errorCall">超时或错误回调</param>
    /// <returns></returns>
        private IEnumerator Download(string url, long length, HandleFinishDownload handle, int timeout = 10000, HandleDownloadError errorCall = null)
    {
        DebugConsole.Log("==>Download url = " + url);
        //创建download info
        curDownload.url           = url;
        curDownload.length        = length;
        curDownload.timeout       = timeout;
        curDownload.errorCallback = errorCall;
        curDownload.flag          = true;
        curDownload.www           = new WWW(url);         //打开下载路径

        //DebugConsole.Log("new www");
        yield return(curDownload.www);            //等待下载完成

        //下载完成后
        DebugConsole.Log("<==www return url = " + url);

        WWW doneWWW = curDownload.www;  //保存下载好的info

        curDownloadLength += curDownload.length;
        //重置curDownload参数
        curDownload.Reset();

        if (string.IsNullOrEmpty(doneWWW.error))
        {
            if (handle != null)              //回调不为空
            {
                handle(doneWWW);             //传递下载信息
            }
            doneWWW.Dispose();               //释放资源
            //doneInfo.Reset();
            doneWWW = null;
        }
        else
        {
            DebugConsole.LogError("WWW Error = " + doneWWW.error);

            try
            {
                if (errorCall != null)
                {
                    errorCall.Invoke();
                }
            }
            catch (System.Exception ex)
            {
                DebugConsole.LogError("Error Handle Callback Exception!");
                DebugConsole.LogError(ex.Message);
                DebugConsole.LogError(ex.StackTrace);
            }
        }
    }
Пример #2
0
 //错误回调
 public void InvokeErrorCallback()
 {
     try
     {
         if (errorCallback != null)
         {
             errorCallback.Invoke();
         }
     }
     catch (System.Exception ex)
     {
         DebugConsole.LogError(ex.Message);
         DebugConsole.LogError(ex.StackTrace);
     }
 }