63 lines
1.3 KiB
C#
63 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CombinatorManger : MonoBehaviour
|
|
{
|
|
[SerializeField] List<CombinatorPanel> CombinationPanels;
|
|
int currentPanelIndex;
|
|
|
|
private void OnEnable() => Initialize();
|
|
|
|
private void OnDisable() => CloseAllPanels();
|
|
|
|
private void Update()
|
|
{
|
|
int direction = GetDirection();
|
|
SwitchPanel(direction);
|
|
|
|
}
|
|
|
|
|
|
public void Initialize()
|
|
{
|
|
currentPanelIndex = 0;
|
|
|
|
CloseAllPanels();
|
|
OpenPanel(0);
|
|
}
|
|
|
|
public void SwitchPanel(int direction)
|
|
{
|
|
if (direction == 0) return;
|
|
|
|
CloseAllPanels();
|
|
|
|
currentPanelIndex = (currentPanelIndex + direction + CombinationPanels.Count) % CombinationPanels.Count;
|
|
OpenPanel(currentPanelIndex);
|
|
}
|
|
public void OpenPanel(int index)
|
|
{
|
|
CombinationPanels[index].Generate();
|
|
}
|
|
public void CloseAllPanels()
|
|
{
|
|
foreach (CombinatorPanel panel in CombinationPanels)
|
|
{
|
|
panel.Clear();
|
|
}
|
|
}
|
|
|
|
|
|
private int GetDirection()
|
|
{
|
|
int direction = 0;
|
|
if (In.GetButtonDown(ButtonPinMapping.startOnePlayer)) { direction -= 1; }
|
|
if (In.GetButtonDown(ButtonPinMapping.startTwoPlayers)) { direction += 1; }
|
|
|
|
return direction;
|
|
}
|
|
|
|
|
|
}
|