88 lines
2.2 KiB
C#
88 lines
2.2 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace PrizeSystem
|
|
{
|
|
public class CountedPrizeInput : AbstractPrizeConfigurator
|
|
{
|
|
[SerializeField] private CountablePrizeType Type;
|
|
[SerializeField] private TextMeshProUGUI ValueLabel;
|
|
|
|
[SerializeField] private int Min;
|
|
[SerializeField] private int Max;
|
|
|
|
[SerializeField] private float MinDelay;
|
|
[SerializeField] private float MaxDelay;
|
|
[SerializeField] private float Acceleration;
|
|
|
|
[SerializeField] AudioClip SwitchClip;
|
|
|
|
|
|
private float Delay;//äëÿ òåñòà ñåðèàëèçîâàíî
|
|
private int Value;
|
|
private float LastSwipeTime = 0;
|
|
|
|
bool CanSwipe => Time.time - LastSwipeTime > Delay;
|
|
|
|
private void OnEnable()
|
|
{
|
|
Value = Min;
|
|
Display();
|
|
}
|
|
|
|
public override void Configure(Prize prize)
|
|
{
|
|
if (prize is CountablePrize countablePrize)
|
|
{
|
|
Value = countablePrize.Amount;
|
|
|
|
Display();
|
|
}
|
|
}
|
|
public void Display()
|
|
{
|
|
ValueLabel.text = Value.ToString();
|
|
}
|
|
|
|
public override void ChangeOption(int direction) { }
|
|
|
|
public override void Swipe(int direction)
|
|
{
|
|
|
|
if (CanSwipe)
|
|
{
|
|
if (Value + direction >= Min && Value + direction <= Max)
|
|
{
|
|
if (SwitchClip != null) SoundManager.instance.playClip(SwitchClip);
|
|
}
|
|
|
|
Value += direction;
|
|
Value = Mathf.Clamp(Value, Min, Max);
|
|
Display();
|
|
|
|
LastSwipeTime = Time.time;
|
|
}
|
|
}
|
|
|
|
|
|
public override void Tick()
|
|
{
|
|
bool left = In.GetButtonAnyPlayer(PlayerAction.left);
|
|
bool right = In.GetButtonAnyPlayer(PlayerAction.right);
|
|
|
|
if (!(left || right))
|
|
{
|
|
Delay = MaxDelay;
|
|
LastSwipeTime = 0;
|
|
}
|
|
else
|
|
{
|
|
Delay = Mathf.Clamp(Delay - Acceleration * Time.deltaTime, MinDelay, MaxDelay);
|
|
}
|
|
}
|
|
|
|
public override Prize GetPrize() => PrizeUtils.CreatePrize(Type, Value);
|
|
|
|
|
|
}
|
|
} |