Platformer level management
This commit is contained in:
1 parent
72070901ec
commit
1aceea1b79
94 files changed
+3656
-197
No files matched your search
@@ -19,43 +19,58 @@ namespace Code.Example.Platformer
|
||||
[StateRaisingEvent]
|
||||
public partial class PlatformerState :
|
||||
IOnPlatformerSceneLoadedHandler,
|
||||
IOnPlatformer2SceneLoadedHandler,
|
||||
IOnPlatformer3SceneLoadedHandler,
|
||||
ICinematicMachineHandle,
|
||||
IPlatformerEnemyLoadedHandle,
|
||||
IPlatformerPlayerLoadedHandle,
|
||||
IPlatformerPlayerSpawnedHandle
|
||||
{
|
||||
IPlatformerPlayerSpawnedHandle,
|
||||
IReadyToPlayHandle,
|
||||
IPlayerReachedFinishHandle
|
||||
{
|
||||
private IPlatformerEnemyFactory _enemyFactory;
|
||||
private IPlatformerPlayerFactory _playerFactory;
|
||||
private PlatformerFirstLevelData _currentLevelData;
|
||||
private Entity.Entity _playerEntity;
|
||||
|
||||
private IAudioFactory _audioFactory;
|
||||
|
||||
private Container _fixdamncontainer;
|
||||
|
||||
private Loading _loading;
|
||||
|
||||
public PlatformerState(AppStateMachineContext context, EventBus eventBus) : base(context, eventBus)
|
||||
{
|
||||
}
|
||||
|
||||
public override AppStates myState => AppStates.Platformer;
|
||||
|
||||
protected override void OnEnterState()
|
||||
{
|
||||
EventBus.Subscribe(this);
|
||||
|
||||
// Scene
|
||||
// Dependency scene
|
||||
// Level scene
|
||||
// Camera
|
||||
// Enemy snail
|
||||
// Enemy bee
|
||||
// Enemy boar
|
||||
// Player
|
||||
_loading = new(6, LoadingCompleted);
|
||||
// Music
|
||||
_loading = new(8, InitialLoadingCompleted);
|
||||
|
||||
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()
|
||||
private void InitialLoadingCompleted()
|
||||
{
|
||||
Context.AudioService.CancelMusic(AudioNames.UISounds,0);
|
||||
Context.UIService.ClosePanel(UIPanelType.Loading);
|
||||
|
||||
_enemyFactory.SpawnEnemy(PlatformerEntityType.Snail, _firstLevelData.enemySpawnPoints[0].position);
|
||||
_enemyFactory.SpawnEnemy(PlatformerEntityType.Boar, _currentLevelData.enemySpawnPoints[0].position);
|
||||
|
||||
_playerFactory.SpawnPlayer(_firstLevelData.playerCheckPoints[0].position);
|
||||
_playerFactory.SpawnPlayer(_currentLevelData.playerCheckPoints[0].position);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,37 +85,10 @@ namespace Code.Example.Platformer
|
||||
Context.CameraFactory.ReleaseCinemachineCamera(CameraMode.Platformer);
|
||||
EventBus.Unsubscribe(this);
|
||||
Context.InputService.DisableMap(ActionMappings.Platformer);
|
||||
|
||||
_audioFactory.ReleaseAudios(AudioNames.Platformer);
|
||||
}
|
||||
|
||||
public void OnPlatformerSceneLoaded()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private IPlatformerEnemyFactory _enemyFactory;
|
||||
private IPlatformerPlayerFactory _playerFactory;
|
||||
private PlatformerFirstLevelData _firstLevelData;
|
||||
|
||||
private Container _fixdamncontainer;
|
||||
|
||||
public void OnPlatformerSceneInitialized(Container container)
|
||||
{
|
||||
_fixdamncontainer = container;
|
||||
_firstLevelData = container.Resolve<PlatformerFirstLevelData>();
|
||||
_enemyFactory = container.Resolve<IPlatformerEnemyFactory>();
|
||||
|
||||
_enemyFactory.WarmEnemy(PlatformerEntityType.Bee);
|
||||
_enemyFactory.WarmEnemy(PlatformerEntityType.Boar);
|
||||
_enemyFactory.WarmEnemy(PlatformerEntityType.Snail);
|
||||
|
||||
_playerFactory = container.Resolve<IPlatformerPlayerFactory>();
|
||||
|
||||
_playerFactory.LoadPlayer();
|
||||
|
||||
_loading.DoProgress();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void CinemachineLoaded(CinemachineCamera cinemachineCamera)
|
||||
{
|
||||
@@ -119,7 +107,90 @@ namespace Code.Example.Platformer
|
||||
|
||||
public void PlatformerPlayerSpawned(Entity.Entity entity)
|
||||
{
|
||||
_playerEntity = entity;
|
||||
|
||||
Context.CameraFactory.GetCinematicCamera(CameraMode.Platformer).Follow = entity.transform;
|
||||
}
|
||||
|
||||
public void OnReadyToPlay(AudioNames groupName)
|
||||
{
|
||||
if(groupName == AudioNames.Platformer) _loading.DoProgress();
|
||||
}
|
||||
|
||||
public void PlayerReachedFinish()
|
||||
{
|
||||
_loading = new(1, Level2LoadingCompleted);
|
||||
Context.UIService.OpenPanel(UIPanelType.Loading);
|
||||
|
||||
_playerEntity.Freeze();
|
||||
|
||||
SceneManager.MoveGameObjectToScene(_playerEntity.gameObject, Context.SceneLoader.GetScene(SceneId.Platformer));
|
||||
|
||||
Context.SceneLoader.UnloadSceneAsync(SceneId.Platformer2).Forget();
|
||||
Context.SceneLoader.LoadSceneAsync(SceneId.Platformer3, LoadSceneMode.Additive).Forget();
|
||||
}
|
||||
|
||||
private void Level2LoadingCompleted()
|
||||
{
|
||||
Context.UIService.ClosePanel(UIPanelType.Loading);
|
||||
|
||||
_enemyFactory.SpawnEnemy(PlatformerEntityType.Boar, _currentLevelData.enemySpawnPoints[0].position);
|
||||
|
||||
_playerEntity.transform.position = _currentLevelData.playerCheckPoints[0].position;
|
||||
_playerEntity.UnFreeze();
|
||||
}
|
||||
|
||||
public void OnPlatformerSceneLoaded()
|
||||
{
|
||||
Context.SceneLoader.LoadSceneAsync(SceneId.Platformer2, LoadSceneMode.Additive).Forget();
|
||||
}
|
||||
|
||||
|
||||
public void OnPlatformerSceneInitialized(Container container)
|
||||
{
|
||||
_fixdamncontainer = container;
|
||||
|
||||
_audioFactory = container.Resolve<IAudioFactory>();
|
||||
_audioFactory.LoadAudioClips(AudioNames.Platformer);
|
||||
|
||||
_enemyFactory = container.Resolve<IPlatformerEnemyFactory>();
|
||||
|
||||
_enemyFactory.WarmEnemy(PlatformerEntityType.Bee);
|
||||
_enemyFactory.WarmEnemy(PlatformerEntityType.Boar);
|
||||
_enemyFactory.WarmEnemy(PlatformerEntityType.Snail);
|
||||
|
||||
_playerFactory = container.Resolve<IPlatformerPlayerFactory>();
|
||||
|
||||
_playerFactory.WarmPlayer();
|
||||
|
||||
_loading.DoProgress();
|
||||
}
|
||||
|
||||
public void OnPlatformer2SceneLoaded()
|
||||
{
|
||||
SceneManager.SetActiveScene(Context.SceneLoader.GetScene(SceneId.Platformer2));
|
||||
}
|
||||
|
||||
public void OnPlatformer2SceneInitialized(Container container)
|
||||
{
|
||||
_currentLevelData = container.Resolve<PlatformerFirstLevelData>();
|
||||
_loading.DoProgress();
|
||||
}
|
||||
|
||||
public void OnPlatformer3SceneLoaded()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnPlatformer3SceneInitialized(Container container)
|
||||
{
|
||||
_currentLevelData = container.Resolve<PlatformerFirstLevelData>();
|
||||
|
||||
_loading.DoProgress();
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPlayerReachedFinishHandle : IGlobalSubscriber
|
||||
{
|
||||
void PlayerReachedFinish();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user