Пример #1
0
    /// <summary>
    /// 每秒计算下载速度,每帧更新进度条
    /// </summary>
    void OnUpdateProgress()
    {
        long downloadFinish = (long)(downloadTemp + downloadNow);

        totalProgress = KTool.GetPercent(downloadFinish, downloadTotalSize) - zipPercent;
        totalProgress = Mathf.Max(totalProgress, 0.0f);

        if (Time.time > last_time)
        {
            last_time = Time.time + 1.0f;
            time_per  = 0;
            // 下载速度 = 前1秒下载量 / 1s ,总下载=下载中 + 已下载
            speed              = downloadFinish - downloadLastSecond;
            speed              = (long)Mathf.Max(speed, 0);
            remainTime         = KTool.GetPercent(downloadTotalSize - downloadFinish, speed);
            downloadLastSecond = downloadFinish;
            lastTotalProgress  = totalProgress;
        }
        var panel = UIModule.Instance.GetExistUI <LoadingPanel>();

        if (panel != null)
        {
            string strSize  = $"{KTool.FormatFileSize(downloadFinish)}/{KTool.FormatFileSize(downloadTotalSize)}";
            string strSpeed = (speed / 1024f).ToString("0.##");
            time_per += Time.deltaTime;
            var progress = Mathf.Lerp(lastTotalProgress, totalProgress, time_per);
            panel.SetProgress(I18N.Get("download_speed", strSize, strSpeed, KTool.HumanizeTimeString((int)remainTime)), progress);
        }
    }