60 lines
1.6 KiB
C#

using UnityEngine;
public class EnterNameState : IState
{
TextInput textInput;
GameManager gm;
PlayerStatsRecord record;
private string name;
public void enter()
{
gm = GameManager.instance;
textInput = gm.nameInput;
textInput.gameObject.SetActive(true);
textInput.Initialize();
}
public void exit()
{
textInput.gameObject.SetActive(false);
//вот тут получаем время и ходы.надо их считать
gm.StatsService.AddRecord(record);
//Тут же запись в бд будет
}
public void update()
{
int discreteDir = 0;
if (In.GetButtonDown(ButtonPinMapping.left1)) discreteDir -= 1;
if (In.GetButtonDown(ButtonPinMapping.right1)) discreteDir += 1;
int continiousDir = 0;
if (In.GetButton(ButtonPinMapping.left2)) continiousDir -= 1;
if (In.GetButton(ButtonPinMapping.right2)) continiousDir += 1;
textInput.SwitchSlot(discreteDir);
textInput.SwitchLetter(continiousDir);
if (In.GetButtonDownAnyPlayer(PlayerAction.down))
{
name = textInput.AcceptAndClose();
//формирование записи
int time = (int)gm.vsBotThinkTime;
int moves = gm.vsBotMoves;
Debug.Log($"Записываю {name} {time} {moves}");
record = new PlayerStatsRecord(name, time, moves);
gm.stateMachine.ChangeState(new LeaderboardState(record));
}
}
}