84 lines
2.0 KiB
C#
84 lines
2.0 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class Menu : MonoBehaviour, IControlable
|
|
{
|
|
public MenuAnimator menuAnimator;
|
|
public MenuPanelManager menuPanelManager;
|
|
|
|
[SerializeField] private float _timeToPromo = 180f;
|
|
[SerializeField] private float _timeToSettings = 1f;
|
|
[SerializeField] private MenuPromoTransit _menuPromoTransit;
|
|
[SerializeField] private MenuSettingsTransit _menuSettingsTransit;
|
|
private HoldTimer _promoTimer;
|
|
private HoldTimer _settingsTimer;
|
|
|
|
public bool ControlsEnabled { get; set; }
|
|
|
|
private void Update()
|
|
{
|
|
if (ControlsEnabled == false)
|
|
return;
|
|
|
|
//переход настройки
|
|
if (_settingsTimer.Update(In.GetService()))
|
|
{
|
|
_menuSettingsTransit.GotoSettings();
|
|
return;
|
|
}
|
|
|
|
//переход промо
|
|
if (_promoTimer.Update(!In.AnyButton()))
|
|
{
|
|
_menuPromoTransit.GotoPromo();
|
|
return;
|
|
}
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
menuAnimator.Initialize();
|
|
menuPanelManager.Initialize();
|
|
|
|
_promoTimer = new HoldTimer(_timeToPromo);
|
|
_settingsTimer = new HoldTimer(_timeToSettings);
|
|
|
|
ControlsEnabled = true;
|
|
}
|
|
|
|
public void UpdateControls()
|
|
{
|
|
int direction_horizontal = In.GetAxis(JoystickSide.Both, InteractMode.Discrete).x;
|
|
menuPanelManager.SwitchPanel(direction_horizontal);
|
|
|
|
bool action = In.GetAction(JoystickSide.Both, InteractMode.Discrete);
|
|
if (action)
|
|
menuPanelManager.InteractCurrent();
|
|
}
|
|
|
|
public void Open(Action callback)
|
|
{
|
|
Enable();
|
|
menuAnimator.Open(callback);
|
|
}
|
|
|
|
public void Close(Action callback)
|
|
{
|
|
Disable();
|
|
menuAnimator.Close(callback);
|
|
}
|
|
|
|
private void Enable()
|
|
{
|
|
ControlsEnabled = true;
|
|
LightSystem.Idle();
|
|
}
|
|
|
|
private void Disable()
|
|
{
|
|
ControlsEnabled = false;
|
|
_promoTimer.Reset();
|
|
_settingsTimer.Reset();
|
|
}
|
|
}
|