using UnityEngine; using UnityEngine.UI; namespace Unheimlich.Features.Hallucination { /// /// Plays a full-screen image flash on the HUD canvas. /// Fades are handled via LeanTween. /// Call to trigger the flash. /// 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 ──────────────────────────────────────────────────────── /// /// Plays the flash sequence. /// Interrupts any flash already in progress. /// Safe to wire to any UnityEvent with no arguments. /// 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; } } }