47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using PrizeSystem;
|
|
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
using UnityEngine.UI;
|
|
|
|
public class CountablePrizeConfigurator : BasePrizeConfigurator, IControlable
|
|
{
|
|
[SerializeField, FormerlySerializedAs("icon")] private Image _icon;
|
|
[SerializeField, FormerlySerializedAs("numberInput")] private MNumberStepper _numberInput;
|
|
|
|
private PrizeType _prizeType;
|
|
|
|
public override void Configure(PrizeType prizeType)
|
|
{
|
|
_prizeType = prizeType;
|
|
_icon.sprite = PrizeSystemManager.GetPrizeIcon(prizeType);
|
|
|
|
int maxValue = prizeType switch
|
|
{
|
|
PrizeType.Hopper => 10,
|
|
PrizeType.Ticket => 100,
|
|
PrizeType.Marbles => 10,
|
|
_ => 1
|
|
};
|
|
|
|
_numberInput.Initialize(value: 1, min: 1, maxValue);
|
|
}
|
|
|
|
public override void UpdateControls()
|
|
{
|
|
_numberInput.SetDirection(In.GetAxis(JoystickSide.Both, InteractMode.Continious).x);
|
|
|
|
if (In.GetAction(JoystickSide.Both, InteractMode.Discrete))
|
|
{
|
|
CountablePrizeType countableType = _prizeType switch
|
|
{
|
|
PrizeType.Hopper => CountablePrizeType.Hopper,
|
|
PrizeType.Ticket => CountablePrizeType.Ticket,
|
|
PrizeType.Marbles => CountablePrizeType.Marbles,
|
|
_ => CountablePrizeType.Hopper
|
|
};
|
|
Prize prize = PrizeUtils.CreatePrize(countableType, _numberInput.Value);
|
|
Complete(prize);
|
|
}
|
|
}
|
|
}
|