49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class MenuLayoutController : MonoBehaviour, IControlable
|
|
{
|
|
[SerializeField] List<MenuPanel> panels;
|
|
int panelIndex = 0;
|
|
|
|
public bool ControlsEnabled { get; set; }
|
|
|
|
public void Initialize()
|
|
{
|
|
foreach (var panel in panels)
|
|
{
|
|
panel.Disable(0);
|
|
}
|
|
panels[panelIndex].Enable(0, 0);
|
|
ControlsEnabled = true;
|
|
}
|
|
|
|
public void UpdateControls()
|
|
{
|
|
int direction = GetDirection();
|
|
|
|
int newPanelIndex = Mathf.Clamp(panelIndex + direction, 0, 2);
|
|
bool indexChanged = newPanelIndex != panelIndex;
|
|
var currentPanel = panels[panelIndex];
|
|
|
|
if (indexChanged)
|
|
{
|
|
var nextPanel = panels[newPanelIndex];
|
|
currentPanel.Disable(0);
|
|
nextPanel.Enable(0, 0);
|
|
|
|
panelIndex = newPanelIndex;
|
|
}
|
|
|
|
if (In.GetButtonDownAnyPlayer(PlayerAction.action))
|
|
currentPanel.Interact();
|
|
}
|
|
|
|
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;
|
|
}
|
|
} |