78 lines
1.9 KiB
C#
78 lines
1.9 KiB
C#
using CharacterSystem;
|
||
using PrizeSystem;
|
||
using UnityEngine;
|
||
|
||
public class PrizesSelector : MonoBehaviour
|
||
{
|
||
[SerializeField] RectTransform _addedPrizesTable;
|
||
[SerializeField] PrizeView _prizeViewPrefab;
|
||
|
||
[SerializeField] AvailablePrizesTable _availablePrizesTable;
|
||
int index = 0;
|
||
|
||
|
||
private PrizeSet set;
|
||
|
||
public bool skipFrame = false;
|
||
|
||
[SerializeField] Transform pointer;
|
||
|
||
public void Open(Character character)
|
||
{
|
||
print($"открыто с персонажем {character.CharacterIndex}");
|
||
gameObject.SetActive(true);
|
||
|
||
set = PrizeSystemManager.PrizeContainer.Sets[character.CharacterIndex];
|
||
UpdateView();
|
||
}
|
||
|
||
private void UpdateView()
|
||
{
|
||
ClearTable();
|
||
DisplayPrizeSet(set);
|
||
|
||
_availablePrizesTable.Refresh(set);
|
||
}
|
||
|
||
|
||
private void Update()
|
||
{
|
||
if (skipFrame)
|
||
{
|
||
if(In.AnyButton() == false)
|
||
skipFrame = false;
|
||
return;
|
||
}
|
||
|
||
if (_availablePrizesTable.prizeButtons == null) return;
|
||
if (_availablePrizesTable.prizeButtons.Count == 0) return;
|
||
|
||
index = index - In.GetAxis(Axis.Vertical, JoystickSide.Both);
|
||
index = Mathf.Clamp(index, 0, _availablePrizesTable.prizeButtons.Count);
|
||
pointer.position = _availablePrizesTable.prizeButtons[index].transform.position;
|
||
|
||
|
||
if (In.GetButtonAnyPlayer(PlayerAction.action))
|
||
{
|
||
_availablePrizesTable.prizeButtons[index].ClickAnimation();
|
||
}
|
||
}
|
||
|
||
private void ClearTable()
|
||
{
|
||
for (int i = _addedPrizesTable.childCount - 1; i >= 0; i--)
|
||
{
|
||
var go = _addedPrizesTable.GetChild(i).gameObject;
|
||
Destroy(go);
|
||
}
|
||
}
|
||
|
||
private void DisplayPrizeSet(PrizeSet prizeSet)
|
||
{
|
||
foreach (var item in prizeSet.Prizes)
|
||
{
|
||
var view = Instantiate(_prizeViewPrefab, _addedPrizesTable);
|
||
view.SetPrize(item);
|
||
}
|
||
}
|
||
} |