using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Gameplay { /// /// 加载表现类 /// public class LoadingDisplay { /// /// 进度变化的插值时间 /// private float changeProgressTime; /// /// 上次获取时间 /// private float preGetTime; /// /// 目标进度 /// private float targerProgress; /// /// 开始进度 /// private float beginProgress; /// /// 加载完成的等待时间 /// public float LoadingCompleteWaitTime { get; private set; } /// /// 表现进度 /// public float ShowProgress { get; private set; } public void SetInfo(float changeProgressTime, float loadingCompleteWaitTime) { this.changeProgressTime = Mathf.Max(0f, changeProgressTime); LoadingCompleteWaitTime = Mathf.Max(0f, loadingCompleteWaitTime); preGetTime = Time.realtimeSinceStartup; beginProgress = 0f; targerProgress = 0f; ShowProgress = 0f; } public void Update(float realProgress) { if (0f >= changeProgressTime) // 没有插值时间 { targerProgress = realProgress; preGetTime = Time.realtimeSinceStartup; ShowProgress = targerProgress; return; } float realtimeSinceStartup = Time.realtimeSinceStartup; if (!Mathf.Approximately(targerProgress, realProgress)) { preGetTime = realtimeSinceStartup; beginProgress = ShowProgress; targerProgress = realProgress; } float timer = realtimeSinceStartup - preGetTime; ShowProgress = Mathf.Lerp(beginProgress, targerProgress, Mathf.Clamp01(timer / changeProgressTime)); } } }