wip : critical path - flash hallu
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Unheimlich.Features.Hallucination
|
||||
{
|
||||
/// <summary>
|
||||
/// Plays a full-screen image flash on the HUD canvas.
|
||||
/// Fades are handled via LeanTween.
|
||||
/// Call <see cref="Play"/> to trigger the flash.
|
||||
/// </summary>
|
||||
public class HallucinationFlash : MonoBehaviour
|
||||
{
|
||||
[Header("Target")]
|
||||
[SerializeField] private Image _image;
|
||||
|
||||
[Header("Timings")]
|
||||
[SerializeField, Min(0f)] private float _fadeIn = 0.1f;
|
||||
[SerializeField, Min(0f)] private float _hold = 0.2f;
|
||||
[SerializeField, Min(0f)] private float _fadeOut = 0.5f;
|
||||
|
||||
// ─── State ─────────────────────────────────────────────────────────────
|
||||
|
||||
private int _tweenId = -1;
|
||||
|
||||
// ─── Public API ────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Plays the flash sequence.
|
||||
/// Interrupts any flash already in progress.
|
||||
/// Safe to wire to any UnityEvent with no arguments.
|
||||
/// </summary>
|
||||
public void Play()
|
||||
{
|
||||
_image.color = new Color(_image.color.r, _image.color.g, _image.color.b, 0f);
|
||||
|
||||
CancelCurrent();
|
||||
|
||||
_tweenId = LeanTween.value(gameObject, 0f, 1f, _fadeIn)
|
||||
.setEase(LeanTweenType.easeOutQuad)
|
||||
.setOnUpdate(SetAlpha)
|
||||
.setOnComplete(() =>
|
||||
{
|
||||
_tweenId = LeanTween.value(gameObject, 1f, 1f, _hold)
|
||||
.setOnComplete(() =>
|
||||
{
|
||||
_tweenId = LeanTween.value(gameObject, 1f, 0f, _fadeOut)
|
||||
.setEase(LeanTweenType.easeInQuad)
|
||||
.setOnUpdate(SetAlpha)
|
||||
.id;
|
||||
}).id;
|
||||
}).id;
|
||||
}
|
||||
|
||||
// ─── Private ───────────────────────────────────────────────────────────
|
||||
|
||||
private void CancelCurrent()
|
||||
{
|
||||
if (_tweenId == -1) return;
|
||||
LeanTween.cancel(_tweenId);
|
||||
_tweenId = -1;
|
||||
}
|
||||
|
||||
private void SetAlpha(float alpha)
|
||||
{
|
||||
Color c = _image.color;
|
||||
c.a = alpha;
|
||||
_image.color = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user