(Feat) Laoding Screen

This commit is contained in:
2026-06-25 08:25:32 +02:00
parent 57a27103e1
commit c933e226b9
6 changed files with 621 additions and 162 deletions
+77
View File
@@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using DG.Tweening;
using Ashwild.Player;
@@ -55,6 +56,30 @@ namespace Ashwild.UI
[Tooltip("Cross-fade duration when swapping one quote for the next.")]
[SerializeField] private float quoteFadeDuration = 0.4f;
[Header("Progress Bar")]
[Tooltip("Filled Image (Image Type = Filled) that fills as a loading-percentage indicator. " +
"Optional — leave unassigned to disable the bar entirely.")]
[SerializeField] private Image progressFill;
[Tooltip("Optional label that mirrors the slider as a whole-number percentage (e.g. \"42%\").")]
[SerializeField] private TextMeshProUGUI percentLabel;
[Tooltip("Time the bar takes to ramp from empty to the fill cap while the network load runs. " +
"The load has no real progress signal, so the bar fills steadily toward the cap and " +
"only completes to 100% once the ready signal arrives.")]
[SerializeField] private float fillDuration = 8f;
[Tooltip("Value (01) the ramp stalls at while loading, leaving headroom so the bar never sits " +
"at 100% before the scene is actually ready.")]
[Range(0f, 1f)]
[SerializeField] private float fillCap = 0.9f;
[Tooltip("Time the bar takes to rush from the cap to 100% once the ready signal arrives, played " +
"during the curtain's hold before it fades out.")]
[SerializeField] private float fillCompleteDuration = 0.35f;
[SerializeField] private Ease fillEase = Ease.OutSine;
#endregion
#region State
@@ -90,6 +115,7 @@ namespace Ashwild.UI
private Tween curtainTween;
private Sequence quoteSequence;
private Tween progressTween;
#endregion
@@ -156,6 +182,7 @@ namespace Ashwild.UI
{
curtainTween?.Kill();
quoteSequence?.Kill();
progressTween?.Kill();
if (instance == this) instance = null;
}
@@ -255,6 +282,7 @@ namespace Ashwild.UI
ShowNextQuote(instant: true);
StartQuoteCycle();
StartProgress();
}
/// <summary>
@@ -271,6 +299,8 @@ namespace Ashwild.UI
float elapsed = Time.unscaledTime - shownAt;
float delay = Mathf.Max(settleDelay, minimumDisplayTime - elapsed);
CompleteProgress();
curtainTween?.Kill();
curtainTween = canvasGroup.DOFade(0f, fadeOutDuration)
.SetDelay(delay)
@@ -286,6 +316,53 @@ namespace Ashwild.UI
#endregion
#region Progress Bar
/// <summary>
/// Resets the bar to empty and starts the steady ramp toward <see cref="fillCap"/> over
/// <see cref="fillDuration"/>. The network load exposes no real progress, so this is a paced
/// estimate that deliberately stops short of full — <see cref="CompleteProgress"/> finishes it
/// once the scene is genuinely ready. Runs on unscaled time so it keeps moving while the load
/// freezes the timescale. No-op when no slider is assigned.
/// </summary>
private void StartProgress()
{
if (progressFill == null) return;
progressTween?.Kill();
SetProgress(0f);
progressTween = DOTween.To(SetProgress, 0f, fillCap, fillDuration)
.SetEase(fillEase)
.SetUpdate(true);
}
/// <summary>
/// Rushes the bar from wherever the ramp stalled up to 100%, played during the curtain's hold
/// before it fades out so the bar reads as a completed load. No-op when no slider is assigned.
/// </summary>
private void CompleteProgress()
{
if (progressFill == null) return;
progressTween?.Kill();
progressTween = DOTween.To(SetProgress, progressFill.fillAmount, 1f, fillCompleteDuration)
.SetEase(Ease.OutSine)
.SetUpdate(true);
}
/// <summary>
/// Writes a 01 value to the filled image's fillAmount and mirrors it onto the optional
/// percentage label.
/// </summary>
private void SetProgress(float value)
{
if (progressFill != null) progressFill.fillAmount = value;
if (percentLabel != null) percentLabel.text = $"{Mathf.RoundToInt(value * 100f)}%";
}
#endregion
#region Quotes
/// <summary>