sega db3a0fd0bb Добавить правила игры и титры с управляемой прокруткой
Сверстать страницы правил и подключить открытие из главного меню. Добавить управление обоими джойстиками, выход по бездействию через 60 секунд и автоматический расчёт высоты титров.
2026-09-18 14:42:41 +03:00

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.GetHorizontalAxis(JoystickSide.Both, InteractMode.Discrete);
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;
}
private void Disable()
{
menuPanelManager.CloseModal();
ControlsEnabled = false;
_promoTimer.Reset();
_settingsTimer.Reset();
}
}