160 lines
4.8 KiB
C#
160 lines
4.8 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using RR.Common.Controls;
|
||
using RR.Game2D.Core.Managers;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class SettingsCombination : MonoBehaviour
|
||
{
|
||
GameManager gm;
|
||
float resetStartsTimer = 0;
|
||
float resetGivenPrizesTimer = 0;
|
||
float setNumber = 0;
|
||
float telegram = 0;
|
||
|
||
float timeToReset = 5;
|
||
|
||
string PRIZE_BASE = "Счетчик призов ";
|
||
string STARTS_BASE = "Внесено монет ";
|
||
string NULLABLE = "(обнуляемый)";
|
||
string UNNULLABLE = "(глобальный)";
|
||
public TextMeshProUGUI starts, startsNul, prize, prizeNul;
|
||
public Image startsTimerImage, prizeTimerImage, numberImage, telegramImage;
|
||
|
||
|
||
private void OnEnable()
|
||
{
|
||
gm = GameManager.Instance;
|
||
RefreshUI();
|
||
}
|
||
void Update()
|
||
{
|
||
//сброс монет
|
||
bool condition = In.GetButton(ButtonPinMapping.left1) &&
|
||
In.GetButton(ButtonPinMapping.right1) &&
|
||
In.GetButton(ButtonPinMapping.left2) &&
|
||
In.GetButton(ButtonPinMapping.right2);
|
||
if (condition)
|
||
{
|
||
|
||
resetStartsTimer += Time.deltaTime;
|
||
startsTimerImage.fillAmount = resetStartsTimer / timeToReset;
|
||
|
||
if (resetStartsTimer >= timeToReset)
|
||
{
|
||
ResetStarts();
|
||
resetStartsTimer = 0;
|
||
}
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
resetStartsTimer -= Time.deltaTime;
|
||
resetStartsTimer = Mathf.Clamp(resetStartsTimer, 0, 5);
|
||
startsTimerImage.fillAmount = 0;
|
||
}
|
||
|
||
//телега
|
||
condition = In.GetButton(ButtonPinMapping.left1) &&
|
||
In.GetButton(ButtonPinMapping.right1) &&
|
||
/*In.GetButton(ButtonPinMapping.left2) &&*/
|
||
In.GetButton(ButtonPinMapping.right2);
|
||
if (condition)
|
||
{
|
||
telegram += Time.deltaTime;
|
||
telegramImage.fillAmount = telegram / timeToReset;
|
||
if (telegram >= timeToReset)
|
||
{
|
||
//Тут надо зайти в ввод номера
|
||
telegram = 0;
|
||
// gm.stateMachine.ChangeState(new EnterTelegramState());
|
||
//GetNumber();
|
||
}
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
telegram -= Time.deltaTime;
|
||
telegram = Mathf.Clamp(setNumber, 0, 5);
|
||
telegramImage.fillAmount = 0;
|
||
}
|
||
|
||
|
||
|
||
|
||
//выданные призы
|
||
condition = In.GetButton(ButtonPinMapping.left1) &&
|
||
In.GetButton(ButtonPinMapping.left2);
|
||
if (condition)
|
||
{
|
||
resetGivenPrizesTimer += Time.deltaTime;
|
||
prizeTimerImage.fillAmount = resetGivenPrizesTimer / timeToReset;
|
||
if (resetGivenPrizesTimer >= timeToReset)
|
||
{
|
||
ResetPrizes();
|
||
resetGivenPrizesTimer = 0;
|
||
}
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
resetGivenPrizesTimer -= Time.deltaTime;
|
||
resetGivenPrizesTimer = Mathf.Clamp(resetGivenPrizesTimer, 0, 5);
|
||
prizeTimerImage.fillAmount = 0;
|
||
}
|
||
|
||
|
||
//условие захода в ввод номера
|
||
condition = In.GetButton(ButtonPinMapping.right1) &&
|
||
In.GetButton(ButtonPinMapping.right2);
|
||
if (condition)
|
||
{
|
||
setNumber += Time.deltaTime;
|
||
numberImage.fillAmount = setNumber / timeToReset;
|
||
if (setNumber >= timeToReset)
|
||
{
|
||
//Тут надо зайти в ввод номера
|
||
setNumber = 0;
|
||
GetNumber();
|
||
}
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
setNumber -= Time.deltaTime;
|
||
setNumber = Mathf.Clamp(setNumber, 0, 5);
|
||
numberImage.fillAmount = 0;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
void ResetStarts()
|
||
{
|
||
PlayerPrefs.SetInt(PrizeSystem.key_startsNul, 0);
|
||
RefreshUI();
|
||
}
|
||
void ResetPrizes()
|
||
{
|
||
PlayerPrefs.SetInt(PrizeSystem.key_prizesgivenNul, 0);
|
||
RefreshUI();
|
||
}
|
||
|
||
void GetNumber()
|
||
{
|
||
// GameManager.instance.stateMachine.ChangeState(new GetNumberState());
|
||
}
|
||
|
||
|
||
void RefreshUI()
|
||
{
|
||
starts.text = STARTS_BASE + UNNULLABLE + ": " + PlayerPrefs.GetInt(PrizeSystem.key_starts);
|
||
startsNul.text = STARTS_BASE + NULLABLE + ": " + PlayerPrefs.GetInt(PrizeSystem.key_startsNul);
|
||
|
||
prize.text = PRIZE_BASE + UNNULLABLE + ": " + PlayerPrefs.GetInt(PrizeSystem.key_prizesgiven);
|
||
prizeNul.text = PRIZE_BASE + NULLABLE + ": " + PlayerPrefs.GetInt(PrizeSystem.key_prizesgivenNul);
|
||
}
|
||
}
|