127 lines
3.4 KiB
C#
127 lines
3.4 KiB
C#
// CockpitGateHUD.cs
|
|
// Zweck: Kleines HUD im Cockpit, das aktuell fokussierten Gate-Text einblendet (mit Reveal-Animation).
|
|
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class CockpitGateHUD : MonoBehaviour
|
|
{
|
|
[Header("Refs")]
|
|
[SerializeField] private TMP_Text label; // Textanzeige
|
|
[SerializeField] private CanvasGroup group; // Sichtbarkeit/Interaktion
|
|
[SerializeField] private AudioSource sfx; // optional
|
|
[SerializeField] private AudioClip revealSfx; // optional: kurzer Blip
|
|
|
|
[Header("Timings")]
|
|
[SerializeField] private float revealTime = 0.45f; // Dauer des Reveals
|
|
|
|
[Header("Curves")]
|
|
[SerializeField] private AnimationCurve scaleCurve = AnimationCurve.EaseInOut(0, 0.7f, 1, 1.02f);
|
|
[SerializeField] private AnimationCurve alphaCurve = AnimationCurve.EaseInOut(0, 0f, 1, 1f);
|
|
|
|
[Header("Debug")]
|
|
[SerializeField] private bool debugLogs = false;
|
|
|
|
private RectTransform _rt;
|
|
private Coroutine _revealCo;
|
|
private Vector3 _baseScale;
|
|
|
|
private void Awake()
|
|
{
|
|
if (!group) group = GetComponent<CanvasGroup>();
|
|
_rt = GetComponent<RectTransform>();
|
|
if (!_rt) _rt = gameObject.AddComponent<RectTransform>();
|
|
_baseScale = _rt.localScale;
|
|
|
|
// Startzustand: versteckt
|
|
if (group)
|
|
{
|
|
group.alpha = 0f;
|
|
group.interactable = false;
|
|
group.blocksRaycasts = false;
|
|
}
|
|
}
|
|
|
|
// Sofort anzeigen (ohne Reveal)
|
|
public void Show(string text)
|
|
{
|
|
if (debugLogs) Debug.Log($"[CockpitGateHUD] Show: \"{text}\"");
|
|
if (label) label.text = text;
|
|
StopReveal();
|
|
|
|
if (group)
|
|
{
|
|
group.alpha = 1f;
|
|
group.interactable = false;
|
|
group.blocksRaycasts = false;
|
|
}
|
|
|
|
if (_rt) _rt.localScale = _baseScale;
|
|
}
|
|
|
|
// Mit Reveal-Animation zeigen
|
|
public void ShowWithReveal(string text)
|
|
{
|
|
if (debugLogs) Debug.Log($"[CockpitGateHUD] ShowWithReveal: \"{text}\"");
|
|
if (label) label.text = text;
|
|
|
|
StopReveal();
|
|
_revealCo = StartCoroutine(Co_Reveal());
|
|
}
|
|
|
|
// Verstecken (sofort)
|
|
public void Hide()
|
|
{
|
|
if (debugLogs) Debug.Log("[CockpitGateHUD] Hide");
|
|
StopReveal();
|
|
|
|
if (group)
|
|
{
|
|
group.alpha = 0f;
|
|
group.interactable = false;
|
|
group.blocksRaycasts = false;
|
|
}
|
|
|
|
if (_rt) _rt.localScale = _baseScale;
|
|
}
|
|
|
|
private void StopReveal()
|
|
{
|
|
if (_revealCo != null) StopCoroutine(_revealCo);
|
|
_revealCo = null;
|
|
}
|
|
|
|
private IEnumerator Co_Reveal()
|
|
{
|
|
// Vorbereitung
|
|
if (group)
|
|
{
|
|
group.alpha = 0f;
|
|
group.interactable = false;
|
|
group.blocksRaycasts = false;
|
|
}
|
|
|
|
if (_rt) _rt.localScale = _baseScale * scaleCurve.Evaluate(0f);
|
|
|
|
// Sound
|
|
if (sfx && revealSfx) sfx.PlayOneShot(revealSfx, 0.6f);
|
|
|
|
float t = 0f;
|
|
while (t < revealTime)
|
|
{
|
|
t += Time.deltaTime;
|
|
float n = Mathf.Clamp01(t / revealTime);
|
|
|
|
if (group) group.alpha = alphaCurve.Evaluate(n);
|
|
if (_rt) _rt.localScale = _baseScale * scaleCurve.Evaluate(n);
|
|
|
|
yield return null;
|
|
}
|
|
|
|
if (group) group.alpha = 1f;
|
|
if (_rt) _rt.localScale = _baseScale;
|
|
|
|
_revealCo = null;
|
|
}
|
|
}
|