修改结算界面v0.2

增加水波纹效果
This commit is contained in:
2026-07-05 03:09:42 +08:00
parent 904f854774
commit f5883eb451
16 changed files with 1734 additions and 57 deletions
+108 -17
View File
@@ -27,7 +27,14 @@ namespace GameFramework
[SerializeField] private GameState gameState = GameState.Playing;
[Header("过场动画")]
[Header("过场动画 - 失败(光圈缩小)")]
[Tooltip("光源缩小的持续时间(秒)")]
[SerializeField] private float lightShrinkDuration = 2f;
[Tooltip("失败后黑色遮罩淡出持续时间(秒)")]
[SerializeField] private float lostFadeOutDuration = 1f;
[Header("过场动画 - 胜利(光源扩大 + 切场景)")]
[Tooltip("光源扩大的持续时间(秒)")]
[SerializeField] private float lightExpandDuration = 1.5f;
@@ -56,27 +63,76 @@ namespace GameFramework
}
/// <summary>
/// 死亡过场协程:禁用控制 → 光源放大 → 淡出 → 跳转 Scoring
/// 使用 unscaledDeltaTime 确保不受 timeScale 影响
/// 失败过场协程:禁用控制 → 光源缩小至 0 → 淡出黑色显示失败叠加层
/// 不切换场景,留在 Gameplay
/// </summary>
private IEnumerator DeathTransition()
{
// 等待一帧,让 HUD 先更新血量显示(最后一滴血消失)
// 等待一帧,让 HUD 先更新血量显示
yield return null;
// 1. 查找玩家并禁用控制
var player = GameObject.FindGameObjectWithTag("Player");
if (player != null)
{
// 禁用玩家移动
var playerController = player.GetComponent<PlayerController>();
if (playerController != null) playerController.enabled = false;
// 禁用相机跟随
var camFollow = Camera.main != null ? Camera.main.GetComponent<CameraFollow>() : null;
if (camFollow != null) camFollow.enabled = false;
// 2. 光源扩大
// 2. 光源缩小至完全不可见
var lightSource = player.GetComponent<LightSource>();
if (lightSource != null)
{
float startRadius = lightSource.Radius;
float startIntensity = lightSource.Intensity;
float elapsed = 0f;
while (elapsed < lightShrinkDuration)
{
elapsed += Time.unscaledDeltaTime;
float t = Mathf.Clamp01(elapsed / lightShrinkDuration);
float smoothT = t * t * (3f - 2f * t); // SmoothStep
lightSource.SetRadius(Mathf.Lerp(startRadius, 0.1f, smoothT));
lightSource.SetIntensity(Mathf.Lerp(startIntensity, 0f, smoothT));
yield return null;
}
lightSource.SetRadius(0.1f);
lightSource.SetIntensity(0f);
}
else
{
yield return new WaitForSecondsRealtime(lightShrinkDuration);
}
}
else
{
yield return new WaitForSecondsRealtime(lightShrinkDuration);
}
// 3. 淡出黑色 + 显示失败叠加层(不切场景)
yield return StartCoroutine(ShowLostOverlay());
}
/// <summary>
/// 胜利过场协程:光源扩大 → 淡出 → 跳转 Scoring。
/// </summary>
private IEnumerator VictoryTransition()
{
// 胜利使用光源扩散 + 淡出 + 切场景(与失败不同)
yield return null;
var player = GameObject.FindGameObjectWithTag("Player");
if (player != null)
{
var playerController = player.GetComponent<PlayerController>();
if (playerController != null) playerController.enabled = false;
var camFollow = Camera.main != null ? Camera.main.GetComponent<CameraFollow>() : null;
if (camFollow != null) camFollow.enabled = false;
var lightSource = player.GetComponent<LightSource>();
if (lightSource != null)
{
@@ -87,7 +143,7 @@ namespace GameFramework
{
elapsed += Time.unscaledDeltaTime;
float t = Mathf.Clamp01(elapsed / lightExpandDuration);
float smoothT = t * t * (3f - 2f * t); // SmoothStep
float smoothT = t * t * (3f - 2f * t);
lightSource.SetRadius(Mathf.Lerp(startRadius, lightExpandTargetRadius, smoothT));
yield return null;
}
@@ -96,31 +152,66 @@ namespace GameFramework
}
else
{
// 没有光源,等待同样时间
yield return new WaitForSecondsRealtime(lightExpandDuration);
}
}
else
{
// 没有玩家,等待同样时间
yield return new WaitForSecondsRealtime(lightExpandDuration);
}
// 3. 淡出到黑色
yield return StartCoroutine(FadeOutAndLoad());
}
/// <summary>
/// 胜利过场协程(与死亡相同,可后续扩展不同效果)
/// 失败叠加层:淡入黑色 → 显示"你已迷失"UI → 黑色稍微淡出露出暗黑场景
/// 不切换场景,留在 Gameplay。
/// </summary>
private IEnumerator VictoryTransition()
private IEnumerator ShowLostOverlay()
{
// 胜利也使用相同的光源扩散 + 淡出效果
yield return DeathTransition();
// 创建全屏黑色遮罩
var canvasObj = new GameObject("FadeOverlay");
var canvas = canvasObj.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvas.sortingOrder = 99999;
canvasObj.AddComponent<CanvasScaler>();
var overlay = canvasObj.AddComponent<Image>();
overlay.color = new Color(0, 0, 0, 0);
// 淡入到全黑
float elapsed = 0f;
while (elapsed < fadeOutDuration)
{
elapsed += Time.unscaledDeltaTime;
float t = Mathf.Clamp01(elapsed / fadeOutDuration);
overlay.color = new Color(0, 0, 0, t);
yield return null;
}
overlay.color = new Color(0, 0, 0, 1);
yield return null;
// 在全黑之上显示失败叠加层("你已迷失……" + 主界面按钮)
GameLostOverlay.Show();
// 等待一帧让 UI 渲染
yield return null;
// 黑色遮罩稍微淡出,露出一点暗黑场景(配合叠加层的暗色蒙版)
elapsed = 0f;
while (elapsed < lostFadeOutDuration)
{
elapsed += Time.unscaledDeltaTime;
float t = Mathf.Clamp01(elapsed / lostFadeOutDuration);
overlay.color = new Color(0, 0, 0, Mathf.Lerp(1f, 0.4f, t));
yield return null;
}
overlay.color = new Color(0, 0, 0, 0.4f);
}
/// <summary>
/// 创建全屏黑色遮罩并淡出,然后加载 Scoring 场景。
/// 创建全屏黑色遮罩并淡出,然后加载 Scoring 场景(仅胜利时使用)
/// </summary>
private IEnumerator FadeOutAndLoad()
{
@@ -148,7 +239,7 @@ namespace GameFramework
// 等待一帧确保淡出渲染完成
yield return null;
// 加载 Scoring 场景(直接使用 SceneManager,避免 SceneLoader 的异步加载可能卡住)
// 加载 Scoring 场景
Debug.Log("[GameManager] 过场完成,正在加载 Scoring 场景...");
SceneManager.LoadScene("Scoring");
}