67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
using Code.Infrastructure.App;
|
|
using Code.Infrastructure.Audio;
|
|
using Code.Infrastructure.Camera;
|
|
using Code.Infrastructure.EventBus;
|
|
using Code.Infrastructure.Generators;
|
|
using Code.Infrastructure.Input;
|
|
using Code.Infrastructure.Loadings;
|
|
using Code.Infrastructure.SceneLoader;
|
|
using Code.Infrastructure.UI;
|
|
using Reflex.Core;
|
|
using Unity.Cinemachine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace Code.Example.Platformer
|
|
{
|
|
[State(typeof(AppStates),typeof(AppStateMachineContext))]
|
|
[StateRaisingEvent]
|
|
public partial class PlatformerState : IOnPlatformerSceneLoadedHandler, ICinematicMachineHandle
|
|
{
|
|
public PlatformerState(AppStateMachineContext context, EventBus eventBus) : base(context, eventBus)
|
|
{
|
|
}
|
|
|
|
public override AppStates myState => AppStates.Platformer;
|
|
protected override void OnEnterState()
|
|
{
|
|
EventBus.Subscribe(this);
|
|
|
|
_loading = new(2, LoadingCompleted);
|
|
|
|
Context.UIService.OpenPanel(UIPanelType.Loading);
|
|
Context.SceneLoader.LoadSceneAsync(SceneId.Platformer, LoadSceneMode.Single).Forget();
|
|
Context.InputService.EnableMap(ActionMappings.Platformer);
|
|
Context.CameraFactory.LoadCinemachineCamera(CameraMode.Platformer).Forget();
|
|
}
|
|
private Loading _loading;
|
|
|
|
private void LoadingCompleted()
|
|
{
|
|
Context.AudioService.CancelMusic(AudioNames.UISounds,0);
|
|
Context.UIService.ClosePanel(UIPanelType.Loading);
|
|
}
|
|
|
|
|
|
protected override void OnExitState()
|
|
{
|
|
Context.CameraFactory.ReleaseCinemachineCamera(CameraMode.Platformer);
|
|
Context.InputService.DisableMap(ActionMappings.Platformer);
|
|
EventBus.Unsubscribe(this);
|
|
}
|
|
|
|
public void OnPlatformerSceneLoaded()
|
|
{
|
|
|
|
}
|
|
|
|
public void OnPlatformerSceneInitialized(Container container)
|
|
{
|
|
_loading.DoProgress();
|
|
}
|
|
|
|
public void CinemachineLoaded(CinemachineCamera cinemachineCamera)
|
|
{
|
|
_loading.DoProgress();
|
|
}
|
|
}
|
|
} |