Пример #1
0
        public void Update(float elapseSeconds, float realElapseSeconds)
        {
            if (m_DownloadCounterNodes.Count <= 0)
            {
                return;
            }

            m_Accumulator += realElapseSeconds;
            if (m_Accumulator > m_RecordInterval)
            {
                m_Accumulator = m_RecordInterval;
            }

            m_TimeLeft -= realElapseSeconds;
            foreach (DownloadCounterNode downloadCounterNode in m_DownloadCounterNodes)
            {
                downloadCounterNode.Update(elapseSeconds, realElapseSeconds);
            }

            while (m_DownloadCounterNodes.Count > 0)
            {
                DownloadCounterNode downloadCounterNode = m_DownloadCounterNodes.First.Value;
                if (downloadCounterNode.ElapseSeconds < m_RecordInterval)
                {
                    break;
                }

                ReferencePool.Release(downloadCounterNode);
                m_DownloadCounterNodes.RemoveFirst();
            }

            if (m_DownloadCounterNodes.Count <= 0)
            {
                Reset();
                return;
            }

            if (m_TimeLeft <= 0f)
            {
                int totalDownloadLength = 0;
                foreach (DownloadCounterNode downloadCounterNode in m_DownloadCounterNodes)
                {
                    totalDownloadLength += downloadCounterNode.DownloadedLength;
                }

                m_CurrentSpeed = m_Accumulator > 0f ? totalDownloadLength / m_Accumulator : 0f;
                m_TimeLeft    += m_UpdateInterval;
            }
        }
Пример #2
0
        public void RecordDownloadedLength(int downloadedLength)
        {
            if (downloadedLength <= 0)
            {
                return;
            }

            if (m_DownloadCounterNodes.Count > 0)
            {
                DownloadCounterNode downloadCounterNode = m_DownloadCounterNodes.Last.Value;
                if (downloadCounterNode.ElapseSeconds < m_UpdateInterval)
                {
                    downloadCounterNode.AddDownloadedLength(downloadedLength);
                    return;
                }
            }

            m_DownloadCounterNodes.AddLast(DownloadCounterNode.Create(downloadedLength));
        }