43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
public class MenuPanelManager
|
|
{
|
|
[SerializeField] List<MenuPanel> _panels;
|
|
int _currentIndex = 0;
|
|
|
|
private MenuPanel CurrentPanel => _panels[_currentIndex];
|
|
|
|
public void Initialize()
|
|
{
|
|
foreach (var panel in _panels)
|
|
{
|
|
panel.Initialize();
|
|
panel.Disable(0);
|
|
}
|
|
|
|
_panels[_currentIndex].Enable(0, 0);
|
|
}
|
|
|
|
public void SwitchPanel(int direction)
|
|
{
|
|
//Считаем новый индекс панели
|
|
int newIndex = Mathf.Clamp(_currentIndex + direction, 0, _panels.Count - 1);
|
|
|
|
//Если индекс не поменялся, выход
|
|
bool indexChanged = newIndex != _currentIndex;
|
|
if (indexChanged == false)
|
|
return;
|
|
|
|
//Выкл старую, Вкл новую
|
|
CurrentPanel.Disable(0);
|
|
_currentIndex = newIndex;
|
|
CurrentPanel.Enable(0, 0);
|
|
}
|
|
|
|
public void InteractCurrent()
|
|
=> CurrentPanel.Interact();
|
|
}
|