2026-01-12 09:36:17 +03:00

126 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using TMPro;
using UnityEngine;
public class PrizeState : IState
{
VictoryScale scale;
GameManager gameManager;
bool givePrize;
TextMeshProUGUI ToMenuLabel;
TextMeshProUGUI TimerLabel;
float TimeRest = 15;
IState nextState;
string timerTextCache;
public void enter()
{
LightUtility.Prize();
gameManager = GameManager.instance;
gameManager.timerManager.StopAllTimers();
ToMenuLabel = gameManager.ToMenuLabel;
timerTextCache = ToMenuLabel.text;
//ToMenuLabel.text = "До перехода";
TimerLabel = gameManager.TimerLabel;
ToMenuLabel.gameObject.SetActive(true);
//определяем с какой шкалой мы имеем дело
if (gameManager.gameMode == GameMode.pvp)
{
givePrize = false;
nextState = new ShowWinnerState(gameManager.lastResult);
if (gameManager.currentPlayer == CellState.Player1)
{
scale = gameManager.Player1Scale;
gameManager.winPanel.ShowWin(CellState.Player1);
}
else
{
scale = gameManager.Player2Scale;
gameManager.winPanel.ShowWin(CellState.Player2);
}
}
else
{
//победили ботов
givePrize = true;
scale = gameManager.botScale;
gameManager.winPanel.ShowWin(CellState.Empty);
//это в меню переход. Надо в показ видео и лидерборд
//nextState = new ClearFieldState(true, CellState.Player1);
//А вот это переход в показ видео и заполнение в таблицу лидеров
nextState = new VictoryVideoState(new EnterNameState());
}
//вкл анимацию приза
scale.SetWinState();
scale.winParticles.Play();
}
public void exit()
{
//выкл анимацию приза
scale.SetIdleState();
scale.winParticles.Stop();
//ToMenuLabel.text = timerTextCache; //не выводит \n почему то
gameManager.winPanel.CloseWin();
ToMenuLabel.gameObject.SetActive(false);
}
public void update()
{
//полинг инпутов
if (In.GetButtonDownAnyPlayer(PlayerAction.down))
{
/*if (gameManager.gameMode == GameMode.pve)
gameManager.stateMachine.ChangeState(new VictoryVideoState(new EnterNameState()));
else*/
gameManager.stateMachine.ChangeState(nextState);
}
TimerProcessing();
}
void GivePrizeAndGoMenu()
{
gameManager.stateMachine.ChangeState(nextState);
}
private void TimerProcessing()
{
TimeRest -= Time.deltaTime;
if (TimeRest < 0)
{
GivePrizeAndGoMenu();
}
TimerLabel.text = getTimeText();
}
string getTimeText()//в утилити бы это вынести
{
string minutes = ((int)(TimeRest / 60)).ToString();
string seconds = ((int)(TimeRest % 60)).ToString();
if (minutes.Length < 2) minutes = "0" + minutes;
if (seconds.Length < 2) seconds = "0" + seconds;
string result = minutes + ":" + seconds;
return result;
}
}