Make the score display a UIPage as well
This commit is contained in:
@@ -3,47 +3,117 @@ using Core;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using Minigames.DivingForPictures;
|
||||
using UI.Core;
|
||||
using Pixelplacement;
|
||||
|
||||
public class DivingGameOverScreen : MonoBehaviour
|
||||
namespace UI
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI finalScoreText;
|
||||
|
||||
void OnEnable()
|
||||
public class DivingGameOverScreen : UIPage
|
||||
{
|
||||
if (DivingGameManager.Instance != null)
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI finalScoreText;
|
||||
|
||||
[SerializeField]
|
||||
private CanvasGroup canvasGroup;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
int finalScore = DivingGameManager.Instance.PlayerScore;
|
||||
finalScoreText.text = $"{finalScore}";
|
||||
// Ensure we have a CanvasGroup for transitions
|
||||
if (canvasGroup == null)
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
if (canvasGroup == null)
|
||||
canvasGroup = gameObject.AddComponent<CanvasGroup>();
|
||||
|
||||
canvasGroup.alpha = 0f;
|
||||
canvasGroup.interactable = false;
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the page transitions in. Updates the score display.
|
||||
/// </summary>
|
||||
protected override void DoTransitionIn(Action onComplete)
|
||||
{
|
||||
// Update score when showing the screen
|
||||
if (DivingGameManager.Instance != null)
|
||||
{
|
||||
int finalScore = DivingGameManager.Instance.PlayerScore;
|
||||
finalScoreText.text = $"{finalScore}";
|
||||
}
|
||||
|
||||
if (canvasGroup != null)
|
||||
{
|
||||
canvasGroup.interactable = true;
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
canvasGroup.alpha = 0f;
|
||||
Tween.Value(0f, 1f, v => canvasGroup.alpha = v, transitionDuration, 0f,
|
||||
Tween.EaseInOut, Tween.LoopType.None, null, onComplete);
|
||||
}
|
||||
else
|
||||
{
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the page transitions out.
|
||||
/// </summary>
|
||||
protected override void DoTransitionOut(Action onComplete)
|
||||
{
|
||||
if (canvasGroup != null)
|
||||
{
|
||||
canvasGroup.interactable = false;
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
Tween.Value(canvasGroup.alpha, 0f, v => canvasGroup.alpha = v, transitionDuration, 0f,
|
||||
Tween.EaseInOut, Tween.LoopType.None, null, onComplete);
|
||||
}
|
||||
else
|
||||
{
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public async void PlayAgain()
|
||||
{
|
||||
// Pop this page from the stack before reloading
|
||||
if (UIPageController.Instance != null && UIPageController.Instance.CurrentPage == this)
|
||||
{
|
||||
UIPageController.Instance.PopPage();
|
||||
}
|
||||
|
||||
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
|
||||
await SceneManagerService.Instance.ReloadCurrentScene(progress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exits to the main menu scene.
|
||||
/// </summary>
|
||||
public async void ExitToAppleHills()
|
||||
{
|
||||
// Pop this page from the stack before switching scenes
|
||||
if (UIPageController.Instance != null && UIPageController.Instance.CurrentPage == this)
|
||||
{
|
||||
UIPageController.Instance.PopPage();
|
||||
}
|
||||
|
||||
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
|
||||
await SceneManagerService.Instance.SwitchSceneAsync("AppleHillsOverworld", progress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exits to the Quarry scene.
|
||||
/// </summary>
|
||||
public async void ExitToQuarry()
|
||||
{
|
||||
// Pop this page from the stack before switching scenes
|
||||
if (UIPageController.Instance != null && UIPageController.Instance.CurrentPage == this)
|
||||
{
|
||||
UIPageController.Instance.PopPage();
|
||||
}
|
||||
|
||||
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
|
||||
await SceneManagerService.Instance.SwitchSceneAsync("Quarry", progress);
|
||||
}
|
||||
}
|
||||
|
||||
public async void PlayAgain()
|
||||
{
|
||||
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
|
||||
await SceneManagerService.Instance.ReloadCurrentScene(progress);;
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exits to the main menu scene.
|
||||
/// </summary>
|
||||
public async void ExitToAppleHills()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
// Replace with the actual scene name as set in Build Settings
|
||||
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
|
||||
await SceneManagerService.Instance.SwitchSceneAsync("AppleHillsOverworld", progress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exits to the main menu scene.
|
||||
/// </summary>
|
||||
public async void ExitToQuarry()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
// Replace with the actual scene name as set in Build Settings
|
||||
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
|
||||
await SceneManagerService.Instance.SwitchSceneAsync("Quarry", progress);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user