(client) feat:做了初始化加载动画。 fix:修复定义加载列表和加载枚举时的错误识别
This commit is contained in:
104
Client/Assets/Scripts/Base/Launcher.cs
Normal file
104
Client/Assets/Scripts/Base/Launcher.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using System.Collections;
|
||||
using Logging;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Base
|
||||
{
|
||||
public class Launcher : MonoBehaviour
|
||||
{
|
||||
public Gradient progressBar; // 渐变色条
|
||||
public TMP_Text describeText; // 描述文本
|
||||
|
||||
private float _currentProgress = 0f; // 当前进度
|
||||
private float duration = 0.5f; // 过渡时间
|
||||
|
||||
private string[] _loadingSteps =
|
||||
{
|
||||
"初始化日志", "正在载入定义", "正在加载图片资源", "正在切割瓦片", "正在加载区分派系",
|
||||
"正在加载物品"
|
||||
};
|
||||
|
||||
public float progress
|
||||
{
|
||||
set
|
||||
{
|
||||
_currentProgress = value;
|
||||
if (value < 0.5f)
|
||||
{
|
||||
progressBar.color2 = Color.Lerp(Color.black, Color.white, value * 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
progressBar.color2 = Color.white;
|
||||
progressBar.color1 = Color.Lerp(Color.black, Color.white, (value - 0.5f) * 2);
|
||||
}
|
||||
progressBar.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
StartCoroutine(LoadAllManagers());
|
||||
}
|
||||
|
||||
private IEnumerator LoadAllManagers()
|
||||
{
|
||||
for (var i = 0; i < _loadingSteps.Length; i++)
|
||||
{
|
||||
// 更新描述文本
|
||||
describeText.text = _loadingSteps[i];
|
||||
|
||||
// 获取当前阶段的目标进度
|
||||
var targetProgress = (float)(i + 1) / _loadingSteps.Length;
|
||||
|
||||
// 平滑过渡到下一个阶段
|
||||
yield return SmoothTransitionTo(targetProgress);
|
||||
|
||||
// 初始化对应的管理器
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
UnityLogger.Init();
|
||||
break;
|
||||
case 1:
|
||||
Managers.DefineManager.Instance.Init();
|
||||
break;
|
||||
case 2:
|
||||
Managers.PackagesImageManager.Instance.Init();
|
||||
break;
|
||||
case 3:
|
||||
Managers.TileManager.Instance.Init();
|
||||
break;
|
||||
case 4:
|
||||
Managers.AffiliationManager.Instance.Init();
|
||||
break;
|
||||
case 5:
|
||||
Managers.ItemResourceManager.Instance.Init();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 加载完成后的处理
|
||||
describeText.text = "加载完成!";
|
||||
progress = 1f;
|
||||
}
|
||||
|
||||
private IEnumerator SmoothTransitionTo(float targetProgress)
|
||||
{
|
||||
var startProgress = _currentProgress;
|
||||
var elapsedTime = 0f;
|
||||
|
||||
while (elapsedTime < duration)
|
||||
{
|
||||
elapsedTime += Time.deltaTime;
|
||||
var t = Mathf.SmoothStep(0f, 1f, elapsedTime / duration); // 使用 SmoothStep 实现平滑过渡
|
||||
progress = Mathf.Lerp(startProgress, targetProgress, t);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// 确保最终进度达到目标值
|
||||
progress = targetProgress;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user