chip-gameV3/Assets/Scripts/Menu/MenuLayoutController.cs

43 lines
1.0 KiB
C#

using System.Collections.Generic;
using UnityEngine;
public class MenuLayoutController : MonoBehaviour
{
[SerializeField] List<MenuPanel> panels;
int panelIndex = 0;
public void Initialize()
{
foreach (var panel in panels)
{
panel.Disable(0);
}
panels[panelIndex].Enable(0, 0);
}
private void Update()
{
int direction = GetDirection();
int newPanelIndex = Mathf.Clamp(panelIndex + direction, 0, 2);
bool indexChanged = newPanelIndex != panelIndex;
if (indexChanged)
{
var currentPanel = panels[panelIndex];
var nextPanel = panels[newPanelIndex];
currentPanel.Disable(0);
nextPanel.Enable(0, 0);
panelIndex = newPanelIndex;
}
}
private static int GetDirection()
{
int dir_h = 0;
dir_h += In.GetButtonDownAnyPlayer(PlayerAction.right) ? 1 : 0;
dir_h += In.GetButtonDownAnyPlayer(PlayerAction.left) ? -1 : 0;
return dir_h;
}
}