121 lines
3.6 KiB
C#
121 lines
3.6 KiB
C#
// CockpitMenuController.cs
|
|
// Zweck: Cockpit-Menü anzeigen/verstecken via Animator; Buttons starten Modi oder beenden Spiel.
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class CockpitMenuController : MonoBehaviour
|
|
{
|
|
[Header("References")]
|
|
[SerializeField] private CanvasGroup canvasGroup; // Block für Interaktion/Sichtbarkeit
|
|
[SerializeField] private CockpitTransitionController transition; // Modus-Start
|
|
[SerializeField] private Animator screenAnim; // Animator des Panels
|
|
|
|
[Header("Animator parameters (must match Animator)")]
|
|
[SerializeField] private string showTrigger = "showScreen";
|
|
[SerializeField] private string hideTrigger = "hideScreen";
|
|
[SerializeField] private string hideStateName = "Armature|HideAction";
|
|
[SerializeField] private string showStateName = "Armature|ShowAction";
|
|
|
|
[Header("UI timing")]
|
|
[SerializeField, Range(0f, 1f)] private float hideAlphaAt = 0.9f; // ab wann während "Hide" die Alpha auf 0 geht
|
|
|
|
private float showLen;
|
|
private float hideLen;
|
|
private Coroutine alphaCoroutine;
|
|
|
|
private void Awake()
|
|
{
|
|
CacheClipLengths();
|
|
HideMenuImmediate(); // Start im versteckten Zustand
|
|
}
|
|
|
|
private void CacheClipLengths()
|
|
{
|
|
if (!screenAnim || screenAnim.runtimeAnimatorController == null) return;
|
|
|
|
foreach (var clip in screenAnim.runtimeAnimatorController.animationClips)
|
|
{
|
|
if (clip.name == showStateName) showLen = clip.length;
|
|
else if (clip.name == hideStateName) hideLen = clip.length;
|
|
}
|
|
|
|
if (showLen == 0f || hideLen == 0f)
|
|
Debug.LogWarning("[CockpitMenuController] Animationsclips nicht gefunden. State-/Clipnamen prüfen.");
|
|
}
|
|
|
|
public void ShowMenu()
|
|
{
|
|
if (screenAnim)
|
|
{
|
|
screenAnim.ResetTrigger(hideTrigger);
|
|
screenAnim.SetTrigger(showTrigger);
|
|
}
|
|
|
|
if (alphaCoroutine != null) StopCoroutine(alphaCoroutine);
|
|
if (canvasGroup)
|
|
{
|
|
canvasGroup.alpha = 1f;
|
|
canvasGroup.interactable = true;
|
|
canvasGroup.blocksRaycasts = true;
|
|
}
|
|
}
|
|
|
|
public void HideMenu()
|
|
{
|
|
if (screenAnim)
|
|
{
|
|
screenAnim.ResetTrigger(showTrigger);
|
|
screenAnim.SetTrigger(hideTrigger);
|
|
}
|
|
|
|
if (canvasGroup)
|
|
{
|
|
canvasGroup.interactable = false;
|
|
canvasGroup.blocksRaycasts = false;
|
|
|
|
if (alphaCoroutine != null) StopCoroutine(alphaCoroutine);
|
|
float delay = hideLen > 0f ? hideLen * hideAlphaAt : 0f;
|
|
alphaCoroutine = StartCoroutine(AlphaOffAfter(delay));
|
|
}
|
|
}
|
|
|
|
private IEnumerator AlphaOffAfter(float delay)
|
|
{
|
|
if (delay > 0f) yield return new WaitForSeconds(delay);
|
|
if (canvasGroup) canvasGroup.alpha = 0f;
|
|
}
|
|
|
|
private void HideMenuImmediate()
|
|
{
|
|
if (screenAnim) screenAnim.Play(hideStateName, 0, 1f);
|
|
|
|
if (canvasGroup)
|
|
{
|
|
canvasGroup.alpha = 0f;
|
|
canvasGroup.interactable = false;
|
|
canvasGroup.blocksRaycasts = false;
|
|
}
|
|
}
|
|
|
|
// --- Spielmodus-Passthrus ---
|
|
public void StartTutorialMode() => transition?.StartTutorialMode();
|
|
|
|
public void StartModeSequential()
|
|
{
|
|
GameModeManager.Instance.SelectedMode = GameMode.Default;
|
|
transition?.StartSequentialMode();
|
|
}
|
|
|
|
public void StartModeParallel()
|
|
{
|
|
GameModeManager.Instance.SelectedMode = GameMode.Linear;
|
|
transition?.StartParallelMode();
|
|
}
|
|
|
|
public void QuitGame()
|
|
{
|
|
Debug.Log("Quit requested");
|
|
Application.Quit();
|
|
}
|
|
}
|