Skip to content

Instantly share code, notes, and snippets.

@Syjgin
Created January 20, 2022 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Syjgin/34c83f77e41000b9d0500c0aa141089c to your computer and use it in GitHub Desktop.
Save Syjgin/34c83f77e41000b9d0500c0aa141089c to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
using Zenject;
using Components;
using UnityEngine.Localization;
using Constants;
using Data;
using Dialogues;
using Dialogues.PopupQueue;
namespace UI
{
public class GameOverUI : BaseDialogue
{
[SerializeField] private LocalizedString _localizedCause;
[SerializeField] private Text _causeText;
[Inject] private SceneLoadHandler _sceneLoadHandler;
protected override void OnEnable()
{
_closeButton.onClick.AddListener(OpenMenu);
InputHandler.PopupStateChanged += OnPopupStateChanged;
}
private void OnDestroy()
{
_closeButton.onClick.RemoveListener(OpenMenu);
}
protected override void UpdateContent(IPopupQueueElement popupQueueElement)
{
base.UpdateContent(popupQueueElement);
var gameOverCause = ((GameOverPopupDefinition)popupQueueElement).Cause;
OnGameOverReached(gameOverCause);
}
private void OnGameOverReached(GameOverCause cause)
{
var tableEntry = cause switch
{
GameOverCause.NoFuel => LocalizationKeys.NoFuel,
GameOverCause.FreeFall => LocalizationKeys.FreeFall,
GameOverCause.HeightTooHigh => LocalizationKeys.HeightHigh,
GameOverCause.HeightTooLow => LocalizationKeys.HeightLow,
_ => ""
};
LocalizationUtils.LoadLocalizedString(_localizedCause, LocalizationTables.UiTable, tableEntry, this, result =>
{
_causeText.text = result;
});
}
private void OpenMenu()
{
_sceneLoadHandler.LoadScene(GameScene.Menu, null);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment