96 lines
3.3 KiB
C#
96 lines
3.3 KiB
C#
using Code.Example.Platformer.Entity;
|
|
using Code.Example.Platformer.Level;
|
|
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, IPlatformerEnemyLoadedHandle
|
|
{
|
|
public PlatformerState(AppStateMachineContext context, EventBus eventBus) : base(context, eventBus)
|
|
{
|
|
}
|
|
|
|
public override AppStates myState => AppStates.Platformer;
|
|
protected override void OnEnterState()
|
|
{
|
|
EventBus.Subscribe(this);
|
|
|
|
// Scene
|
|
// Camera
|
|
// Enemy snail
|
|
// Enemy bee
|
|
// Enemy boar
|
|
_loading = new(5, 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);
|
|
|
|
_enemyFactory.SpawnEnemy(PlatformerEntityType.Snail, _firstLevelData.enemySpawnPoints[0].position);
|
|
}
|
|
|
|
|
|
protected override void OnExitState()
|
|
{
|
|
_enemyFactory.ReleaseEnemy(PlatformerEntityType.Bee);
|
|
_enemyFactory.ReleaseEnemy(PlatformerEntityType.Snail);
|
|
_enemyFactory.ReleaseEnemy(PlatformerEntityType.Boar);
|
|
|
|
Context.CameraFactory.ReleaseCinemachineCamera(CameraMode.Platformer);
|
|
EventBus.Unsubscribe(this);
|
|
Context.InputService.DisableMap(ActionMappings.Platformer);
|
|
}
|
|
|
|
public void OnPlatformerSceneLoaded()
|
|
{
|
|
|
|
}
|
|
|
|
private IPlatformerEnemyFactory _enemyFactory;
|
|
private PlatformerFirstLevelData _firstLevelData;
|
|
public void OnPlatformerSceneInitialized(Container container)
|
|
{
|
|
_firstLevelData = container.Resolve<PlatformerFirstLevelData>();
|
|
_enemyFactory = container.Resolve<IPlatformerEnemyFactory>();
|
|
|
|
_enemyFactory.LoadEnemy(PlatformerEntityType.Bee);
|
|
_enemyFactory.LoadEnemy(PlatformerEntityType.Boar);
|
|
_enemyFactory.LoadEnemy(PlatformerEntityType.Snail);
|
|
|
|
_loading.DoProgress();
|
|
}
|
|
|
|
|
|
|
|
public void CinemachineLoaded(CinemachineCamera cinemachineCamera)
|
|
{
|
|
_loading.DoProgress();
|
|
}
|
|
|
|
public void PlatformerEnemyLoaded(PlatformerEntityType type, Entity.Entity entity)
|
|
{
|
|
if(entity) _loading.DoProgress();
|
|
}
|
|
}
|
|
} |