62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using PrizeSystem;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class VitrinaPrizeConfigurator : BasePrizeConfigurator, IControlable
|
|
{
|
|
public Image icon;
|
|
|
|
public Transform pointer;
|
|
public List<RectTransform> pivots;
|
|
public List<MToggle> toggles;
|
|
|
|
int index = 0;
|
|
|
|
public override void Configure(PrizeType prizeType)
|
|
{
|
|
icon.sprite = PrizeSystemManager.GetPrizeIcon(prizeType);
|
|
|
|
foreach (var t in toggles)
|
|
{
|
|
t.DisplayImmediate(false);
|
|
}
|
|
UpdPointerPos();
|
|
}
|
|
|
|
private void UpdPointerPos()
|
|
{
|
|
pointer.position = pivots[index].position;
|
|
}
|
|
|
|
public override void UpdateControls()
|
|
{
|
|
Vector2Int axes = In.GetAxis(JoystickSide.Both, InteractMode.Discrete);
|
|
index = Mathf.Clamp(index + axes.y, 0, toggles.Count - 1);
|
|
UpdPointerPos();
|
|
|
|
int toggleDir = axes.x;
|
|
if (toggleDir != 0)
|
|
{
|
|
toggles[index].SetValue(toggleDir > 0);
|
|
}
|
|
|
|
if (In.GetAction(JoystickSide.Both, InteractMode.Discrete))
|
|
{
|
|
List<int> boxes = new();
|
|
|
|
for (int i = 0; i < toggles.Count; i++)
|
|
{
|
|
MToggle toggle = toggles[i];
|
|
if (toggle.Value)
|
|
{
|
|
boxes.Add(i+1);
|
|
}
|
|
}
|
|
|
|
Prize prize = PrizeUtils.CreatePrize(boxes.ToArray());
|
|
Complete(prize);
|
|
}
|
|
}
|
|
}
|