UI
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace ProjectM.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Pure HUD presentation math (unit-tested, no ECS / no UnityEngine.Object). Drives the low-health screen
|
||||
/// vignette + the transient hurt-flash so the damage feedback is deterministic and testable. Used by the
|
||||
/// client-only observe-only <see cref="HudSystem"/> in PresentationSystemGroup; the flash decay runs on the
|
||||
/// wall-frame <c>SystemAPI.Time.DeltaTime</c>, which is correct in a presentation system (the dt-trap only
|
||||
/// applies to plain simulation systems).
|
||||
/// </summary>
|
||||
public static class HudVisualMath
|
||||
{
|
||||
/// <summary>Below this health fraction the low-health vignette starts to ramp in.</summary>
|
||||
public const float LowHealthThreshold = 0.35f;
|
||||
|
||||
/// <summary>Maximum steady vignette opacity at 0 HP.</summary>
|
||||
public const float MaxVignetteOpacity = 0.55f;
|
||||
|
||||
/// <summary>Opacity boost added by a fresh hit (a hurt flash), decaying back to the steady vignette.</summary>
|
||||
public const float HurtFlashKick = 0.40f;
|
||||
|
||||
/// <summary>Seconds for a full hurt-flash kick to decay to zero.</summary>
|
||||
public const float HurtFlashDuration = 0.40f;
|
||||
|
||||
/// <summary>0 at/above the low-health threshold, ramping to 1 as the health fraction falls to 0.</summary>
|
||||
public static float VignetteIntensity(float healthFrac)
|
||||
{
|
||||
float f = Mathf.Clamp01(healthFrac);
|
||||
if (f >= LowHealthThreshold) return 0f;
|
||||
return Mathf.Clamp01((LowHealthThreshold - f) / LowHealthThreshold);
|
||||
}
|
||||
|
||||
/// <summary>Steady low-health vignette opacity (no flash) from the current health fraction.</summary>
|
||||
public static float VignetteOpacity(float healthFrac) => VignetteIntensity(healthFrac) * MaxVignetteOpacity;
|
||||
|
||||
/// <summary>Decay an active hurt-flash boost toward 0 over <paramref name="dt"/> seconds (clamped, never negative).</summary>
|
||||
public static float DecayFlash(float flash, float dt)
|
||||
=> Mathf.Max(0f, flash - (HurtFlashKick / HurtFlashDuration) * Mathf.Max(0f, dt));
|
||||
|
||||
/// <summary>Final overlay opacity: the steady low-health vignette plus the current flash boost, clamped to 1.</summary>
|
||||
public static float CombinedOpacity(float healthFrac, float flash)
|
||||
=> Mathf.Clamp01(VignetteOpacity(healthFrac) + Mathf.Clamp01(flash));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user