Files
Infratest/Assets/Code/Infrastructure/App/States/MainMenuState.cs
T

84 lines
2.7 KiB
C#

using Code.Debug;
using Code.Infrastructure.Audio;
using Code.Infrastructure.Generators;
using Code.Infrastructure.Loadings;
using Code.Infrastructure.SceneLoader;
using Code.Infrastructure.UI;
using Code.Infrastructure.UI.Panels;
using Reflex.Core;
using UnityEngine.SceneManagement;
namespace Code.Infrastructure.App.States
{
[State(typeof(AppStates),typeof(AppStateMachineContext))]
[StateRaisingEvent]
public partial class MainMenuState : IReadyToPlayHandle, IOnMainMenuSceneLoadedHandler, IMenuChoosePanelCreatedHandle
{
public MainMenuState(AppStateMachineContext context, EventBus.EventBus eventBus) : base(context,eventBus)
{
}
public override AppStates myState => AppStates.MainMenu;
private Loading _loading;
protected override void OnEnterState()
{
EventBus.Subscribe(this);
_loading = new Loading(2, LoadComplete);
Context.UIService.TryLoadCreatePanel(UIPanelType.DebugSceneChooser);
// Context.AudioFactory.LoadAudioClips(AudioNames.UISounds);
Context.SceneLoader.LoadSceneAsync(SceneId.MainMenu, LoadSceneMode.Single).Forget();
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0, AudioGroupType.Music);
Context.AudioService.ChangeGroupVolume(
AudioGroupType.Music,
1f,
0.5f);
}
protected override void OnExitState()
{
// Context.AudioFactory.ReleaseAudios(AudioNames.UISounds);
Context.UIService.TryRemovePanel(UIPanelType.DebugSceneChooser);
Context.AudioService.ChangeGroupVolume(
AudioGroupType.Music,
0,
0.5f,
() => Context.AudioService.CancelMusic(AudioNames.UISounds,0));
EventBus.Unsubscribe(this);
}
private void LoadComplete()
{
Context.UIService.OpenPanel(UIPanelType.DebugSceneChooser);
Context.UIService.ClosePanel(UIPanelType.Loading);
}
public void OnReadyToPlay(AudioNames groupName)
{
_loading.DoProgress();
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0, AudioGroupType.Music);
}
public void OnMainMenuSceneLoaded()
{
_loading.DoProgress();
}
public void OnMainMenuSceneInitialized(Container container)
{
}
public void MenuChoosePanelCreated(UIPanel panel)
{
panel.gameObject.SetActive(true);
panel.Open();
_loading.DoProgress();
}
}
}