122 lines
3.0 KiB
C#
122 lines
3.0 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class EndingCanvas : MonoBehaviour
|
|
{
|
|
public static EndingCanvas Instance { get; private set; }
|
|
|
|
[Header("UI")]
|
|
[SerializeField] private CanvasGroup canvasGroup;
|
|
[SerializeField] private TMP_Text endLabel;
|
|
[SerializeField] private Image buttonIcon;
|
|
|
|
[Header("Input")]
|
|
[SerializeField] private InputActionReference returnAction; // e.g. A-Button
|
|
|
|
[Header("Flow")]
|
|
[SerializeField] private CockpitTransitionController transitionController;
|
|
[SerializeField] private ShipMovement shipMovement;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance != null && Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
HideImmediate();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (returnAction != null)
|
|
{
|
|
returnAction.action.performed += OnReturnPressed;
|
|
returnAction.action.Enable();
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (returnAction != null)
|
|
{
|
|
returnAction.action.performed -= OnReturnPressed;
|
|
returnAction.action.Disable();
|
|
}
|
|
}
|
|
|
|
public void Show(string message)
|
|
{
|
|
if (endLabel != null)
|
|
endLabel.text = message;
|
|
|
|
if (buttonIcon != null)
|
|
buttonIcon.enabled = true;
|
|
|
|
if (canvasGroup != null)
|
|
{
|
|
canvasGroup.alpha = 1f;
|
|
canvasGroup.interactable = false;
|
|
canvasGroup.blocksRaycasts = false;
|
|
}
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
if (canvasGroup != null)
|
|
{
|
|
canvasGroup.alpha = 0f;
|
|
canvasGroup.interactable = false;
|
|
canvasGroup.blocksRaycasts = false;
|
|
}
|
|
|
|
if (buttonIcon != null)
|
|
buttonIcon.enabled = false;
|
|
}
|
|
|
|
private void HideImmediate()
|
|
{
|
|
if (canvasGroup != null)
|
|
{
|
|
canvasGroup.alpha = 0f;
|
|
canvasGroup.interactable = false;
|
|
canvasGroup.blocksRaycasts = false;
|
|
}
|
|
|
|
if (buttonIcon != null)
|
|
buttonIcon.enabled = false;
|
|
}
|
|
|
|
private void OnReturnPressed(InputAction.CallbackContext ctx)
|
|
{
|
|
// Only react if the screen is actually visible
|
|
if (canvasGroup == null || canvasGroup.alpha < 0.9f)
|
|
return;
|
|
|
|
// Optional: stop the ship + reset pose (safety)
|
|
if (shipMovement != null)
|
|
{
|
|
shipMovement.SetActive(false);
|
|
shipMovement.ResetToStartPose();
|
|
}
|
|
|
|
// Optional: if you want to hard-reset questions right away:
|
|
// QuestionManager.Instance?.ResetToFirstQuestion();
|
|
// ScoreHUD.Instance?.ResetScore();
|
|
|
|
// Back to cockpit menu (reusing tutorial method is fine)
|
|
if (transitionController != null)
|
|
{
|
|
transitionController.EndTutorialReturnToMenu();
|
|
// or, if you prefer to add a dedicated method:
|
|
// transitionController.EndGameReturnToMenu();
|
|
}
|
|
|
|
Hide();
|
|
}
|
|
}
|