Files
butchers-games-test/Assets/Scripts/Game/UI/UIGameOver.cs
T
Boris Nikolaev 5f1e94b653 add project files
2026-08-14 01:58:31 +03:00

86 lines
1.7 KiB
C#

using UnityEngine;
using OHM.UnityToolkit;
using OHM.UnityToolkit.UI;
using UnityEngine.Serialization;
public class UIGameOver : UIMenu
{
[SerializeField]
private UIIncrementableCounter levelCounter;
[SerializeField]
[FormerlySerializedAs("distanceTxt")]
private TextWrapper _distanceTxt;
[SerializeField]
[FormerlySerializedAs("retryCont")]
private GameObject _retryCont;
[SerializeField]
[FormerlySerializedAs("respawnCont")]
private GameObject _respawnCont;
[SerializeField]
[FormerlySerializedAs("respawnGauge")]
private UIIncrementableGauge _respawnGauge;
[SerializeField]
private SFX sfx;
private float _showTime;
private float _duration;
public override void Show()
{
base.Show();
if (levelCounter != null)
{
levelCounter.Init(appController.GetPlayerLevel() + 1);
}
_respawnCont.gameObject.SetActive(value: false);
_retryCont.gameObject.SetActive(value: false);
sfx.Play(base.transform);
ShowRespawn();
}
private void ShowRespawn()
{
_showTime = Time.unscaledTime;
bool canRevive = false;
_respawnCont.gameObject.SetActive(canRevive);
_retryCont.gameObject.SetActive(!canRevive);
_respawnGauge.QuickResetToLevel(0, 1f, force: true);
}
public void Quit()
{
appController.Quit();
}
private void Update()
{
if (!_respawnCont.gameObject.activeSelf)
{
return;
}
float ratio = 1f - (Time.unscaledTime - _showTime) / _duration;
if (ratio > 0f)
{
_respawnGauge.SetTargetValue(ratio, 0);
}
else
{
_respawnCont.gameObject.SetActive(value: false);
_retryCont.gameObject.SetActive(value: true);
}
}
public void NoThanks()
{
_respawnCont.gameObject.SetActive(value: false);
_retryCont.gameObject.SetActive(value: true);
}
}