103 lines
2.9 KiB
C#
103 lines
2.9 KiB
C#
// CockpitTutorialUI.cs
|
|
// Zweck: Kurztexte im Cockpit vor Moduswahl, Seitenweise per Input weiterklicken, bei Ende Menü triggern.
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class CockpitTutorialUI : MonoBehaviour
|
|
{
|
|
[SerializeField] private CanvasGroup canvasGroup; // Sichtbarkeit/Interaktion
|
|
[SerializeField] private TMP_Text bodyText; // Textfeld
|
|
[SerializeField] private InputActionReference advanceAction; // Eingabe (weiter)
|
|
[SerializeField] private float fadeSpeed = 6f; // Fade-Out
|
|
[SerializeField] private CockpitTransitionController transition;
|
|
|
|
[TextArea(2, 4)]
|
|
[SerializeField]
|
|
private List<string> pages = new()
|
|
{
|
|
"Willkommen im <b>Cockpit</b>! Falls du noch nicht weißt, wie man das Schiff steuert, schau dir am besten erst das kurze <b>Tutorial</b> an.",
|
|
"Nicht, dass du noch einen Unfall baust.",
|
|
"Wenn du schon alles kennst, starte direkt mit einem der Spielmodi.",
|
|
"Du wählst einen Spielmodus im Menü mit Hilfe des linken Triggers aus.",
|
|
"Beeilen wir uns, bevor noch mehr Worte in Vergessenheit geraten!"
|
|
};
|
|
|
|
private int pageIndex = -1;
|
|
private bool visible;
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (advanceAction != null)
|
|
{
|
|
advanceAction.action.performed += OnAdvance;
|
|
advanceAction.action.Enable();
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (advanceAction != null)
|
|
{
|
|
advanceAction.action.performed -= OnAdvance;
|
|
advanceAction.action.Disable();
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!canvasGroup) return;
|
|
|
|
float target = visible ? 1f : 0f;
|
|
canvasGroup.alpha = Mathf.MoveTowards(canvasGroup.alpha, target, fadeSpeed * Time.deltaTime);
|
|
bool interactable = canvasGroup.alpha > 0.95f;
|
|
canvasGroup.interactable = interactable;
|
|
canvasGroup.blocksRaycasts = interactable;
|
|
}
|
|
|
|
public void BeginTutorial()
|
|
{
|
|
visible = true;
|
|
if (canvasGroup)
|
|
{
|
|
canvasGroup.alpha = 1f;
|
|
canvasGroup.interactable = true;
|
|
canvasGroup.blocksRaycasts = true;
|
|
}
|
|
|
|
pageIndex = -1;
|
|
ShowNextPage();
|
|
}
|
|
|
|
public void CloseTutorial()
|
|
{
|
|
visible = false;
|
|
if (canvasGroup)
|
|
{
|
|
canvasGroup.interactable = false;
|
|
canvasGroup.blocksRaycasts = false;
|
|
}
|
|
pageIndex = -1;
|
|
}
|
|
|
|
private void OnAdvance(InputAction.CallbackContext _)
|
|
{
|
|
if (!visible) return;
|
|
ShowNextPage();
|
|
}
|
|
|
|
private void ShowNextPage()
|
|
{
|
|
pageIndex++;
|
|
if (pageIndex >= pages.Count)
|
|
{
|
|
CloseTutorial();
|
|
if (transition) transition.OnTutorialFinished();
|
|
return;
|
|
}
|
|
|
|
if (bodyText) bodyText.text = pages[pageIndex];
|
|
}
|
|
}
|