Exemplo n.º 1
0
        private void OnDownloadAgentHelperComplete(object sender, DownloadAgentHelperCompleteEventArgs e)
        {
            m_WaitTime         = 0f;
            m_DownloadedLength = e.Length;
            if (m_SavedLength != CurrentLength)
            {
                Debug.LogError("Internal download error.");
            }

            m_Helper.Reset();
            m_FileStream.Close();
            m_FileStream = null;

            if (File.Exists(m_Task.DownloadPath))
            {
                File.Delete(m_Task.DownloadPath);
            }

            File.Move(string.Format("{0}.download", m_Task.DownloadPath), m_Task.DownloadPath);

            m_Task.Status = DownloadTaskStatus.Done;

            if (DownloadAgentSuccess != null)
            {
                DownloadAgentSuccess(this, e.Length);
            }

            m_Task.Done = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建下载代理辅助器完成事件。
        /// </summary>
        /// <param name="length">下载的数据大小。</param>
        /// <returns>创建的下载代理辅助器完成事件。</returns>
        public static DownloadAgentHelperCompleteEventArgs Create(int length)
        {
            if (length < 0)
            {
                Debug.LogError("Length is invalid.");
            }

            DownloadAgentHelperCompleteEventArgs downloadAgentHelperCompleteEventArgs = ReferencePool.Acquire <DownloadAgentHelperCompleteEventArgs>();

            downloadAgentHelperCompleteEventArgs.Length = length;
            return(downloadAgentHelperCompleteEventArgs);
        }
Exemplo n.º 3
0
        private void Update()
        {
            if (m_WWW == null)
            {
                return;
            }

            int deltaLength = m_WWW.bytesDownloaded - m_LastDownloadedSize;

            if (deltaLength > 0)
            {
                m_LastDownloadedSize = m_WWW.bytesDownloaded;
                DownloadAgentHelperUpdateLengthEventArgs downloadAgentHelperUpdateLengthEventArgs = DownloadAgentHelperUpdateLengthEventArgs.Create(deltaLength);
                m_DownloadAgentHelperUpdateLengthEventHandler(this, downloadAgentHelperUpdateLengthEventArgs);
                ReferencePool.Release(downloadAgentHelperUpdateLengthEventArgs);
            }

            if (m_WWW == null)
            {
                return;
            }

            if (!m_WWW.isDone)
            {
                return;
            }

            if (!string.IsNullOrEmpty(m_WWW.error))
            {
                DownloadAgentHelperErrorEventArgs dodwnloadAgentHelperErrorEventArgs = DownloadAgentHelperErrorEventArgs.Create(m_WWW.error.StartsWith(RangeNotSatisfiableErrorCode.ToString()), m_WWW.error);
                m_DownloadAgentHelperErrorEventHandler(this, dodwnloadAgentHelperErrorEventArgs);
                ReferencePool.Release(dodwnloadAgentHelperErrorEventArgs);
            }
            else
            {
                byte[] bytes = m_WWW.bytes;
                DownloadAgentHelperUpdateBytesEventArgs downloadAgentHelperUpdateBytesEventArgs = DownloadAgentHelperUpdateBytesEventArgs.Create(bytes, 0, bytes.Length);
                m_DownloadAgentHelperUpdateBytesEventHandler(this, downloadAgentHelperUpdateBytesEventArgs);
                ReferencePool.Release(downloadAgentHelperUpdateBytesEventArgs);

                DownloadAgentHelperCompleteEventArgs downloadAgentHelperCompleteEventArgs = DownloadAgentHelperCompleteEventArgs.Create(bytes.Length);
                m_DownloadAgentHelperCompleteEventHandler(this, downloadAgentHelperCompleteEventArgs);
                ReferencePool.Release(downloadAgentHelperCompleteEventArgs);
            }
        }
        public override void Update(float elapseSeconds, float realElapseSeconds)
        {
            if (m_UnityWebRequest == null)
            {
                return;
            }

            if (!m_UnityWebRequest.isDone)
            {
                return;
            }


            bool isError = false;

#if UNITY_2017_1_OR_NEWER
            isError = m_UnityWebRequest.isNetworkError || m_UnityWebRequest.isHttpError;
#else
            isError = m_UnityWebRequest.isError;
#endif
            if (isError)
            {
                DownloadAgentHelperErrorEventArgs downloadAgentHelperErrorEventArgs = DownloadAgentHelperErrorEventArgs.Create(m_UnityWebRequest.responseCode == RangeNotSatisfiableErrorCode, m_UnityWebRequest.error);
                m_DownloadAgentHelperErrorEventHandler(this, downloadAgentHelperErrorEventArgs);
                ReferencePool.Release(downloadAgentHelperErrorEventArgs);
            }
            else
            {
                //DownloadAgentHelperProgressEventArgs downloadAgentHelperProgressEventArgs = DownloadAgentHelperProgressEventArgs.Create(1.0f);
                //m_DownloadAgentHelperProgressEventHandler(this, downloadAgentHelperProgressEventArgs);
                //ReferencePool.Release(downloadAgentHelperProgressEventArgs);

                DownloadAgentHelperCompleteEventArgs downloadAgentHelperCompleteEventArgs = DownloadAgentHelperCompleteEventArgs.Create((int)m_UnityWebRequest.downloadedBytes);
                m_DownloadAgentHelperCompleteEventHandler(this, downloadAgentHelperCompleteEventArgs);
                ReferencePool.Release(downloadAgentHelperCompleteEventArgs);
            }
        }