125 lines
4.7 KiB
C#
125 lines
4.7 KiB
C#
using Code.Example.Race;
|
|
using Code.Example.Race.Racer;
|
|
using Code.Example.Race.Racer.AI;
|
|
using Code.Example.Race.Racer.Player;
|
|
using Code.Example.Race.Track;
|
|
using Code.Infrastructure.Audio;
|
|
using Code.Infrastructure.Camera;
|
|
using Code.Infrastructure.Camera.CameraStates;
|
|
using Code.Infrastructure.Generators;
|
|
using Code.Infrastructure.Input;
|
|
using Code.Infrastructure.Loadings;
|
|
using Code.Infrastructure.SceneLoader;
|
|
using Code.Infrastructure.UI;
|
|
using Reflex.Core;
|
|
using Reflex.Injectors;
|
|
using Unity.Cinemachine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace Code.Infrastructure.App.States
|
|
{
|
|
[State(typeof(AppStates), typeof(AppStateMachineContext))]
|
|
[StateRaisingEvent]
|
|
public partial class GameplayState :
|
|
IOnGameplaySceneLoadedHandler,
|
|
IRaceGameInitializedHandle,
|
|
IRacerFactoryInitializedHandle,
|
|
IUIPanelLoaded,
|
|
ICinematicMachineHandle
|
|
{
|
|
public GameplayState(AppStateMachineContext context, EventBus.EventBus eventBus) : base(context, eventBus)
|
|
{
|
|
}
|
|
|
|
public override AppStates myState => AppStates.Gameplay;
|
|
|
|
private Loading _gameplayLoading;
|
|
|
|
protected override void OnEnterState()
|
|
{
|
|
EventBus.Subscribe(this);
|
|
Context.UIService.OpenPanel(UIPanelType.Loading);
|
|
|
|
// Scene
|
|
// RaceGame
|
|
// Factory
|
|
// PlayerCounter
|
|
// CinemachineCamera
|
|
_gameplayLoading = new Loading(5, GameplayLoadingCompleted);
|
|
|
|
Context.UIService.TryLoadPanel(UIPanelType.PlayerScoreCounter);
|
|
Context.SceneLoader.LoadSceneAsync(SceneId.Gameplay, LoadSceneMode.Single).Forget();
|
|
Context.InputService.EnableMap(ActionMappings.Gameplay);
|
|
Context.CameraFactory.LoadCinemachineCamera(CameraMode.ThirdPerson).Forget();
|
|
}
|
|
|
|
private void GameplayLoadingCompleted()
|
|
{
|
|
Context.AudioService.CancelMusic(AudioNames.UISounds, 0);
|
|
|
|
_raceGame.PlaceRacers();
|
|
|
|
Context.Camera.SwitchState(CameraMode.ThirdPerson).AllowStateTransition(CameraMode.None);
|
|
// ((ThirdPersonState)Context.Camera.CurrentBaseState).SetFollowTarget(_raceGame.PlacedRacers[0].gameObject.transform, _raceGame.PlacedRacers[0].CarRigidbody);
|
|
Context.CameraFactory.GetCinematicCamera(CameraMode.ThirdPerson).transform.position = ((PlayerRacer)_raceGame.PlacedRacers[0]).CameraPosition.position;
|
|
Context.CameraFactory.GetCinematicCamera(CameraMode.ThirdPerson).transform.rotation = ((PlayerRacer)_raceGame.PlacedRacers[0]).CameraPosition.rotation;
|
|
|
|
Context.CameraFactory.GetCinematicCamera(CameraMode.ThirdPerson).Follow =
|
|
_raceGame.PlacedRacers[0].gameObject.transform;
|
|
|
|
Context.UIService.ClosePanel(UIPanelType.Loading);
|
|
_raceGame.StartRacers();
|
|
}
|
|
|
|
protected override void OnExitState()
|
|
{
|
|
Context.InputService.DisableMap(ActionMappings.Gameplay);
|
|
Context.UIService.TryRemovePanel(UIPanelType.PlayerScoreCounter);
|
|
Context.CameraFactory.ReleaseCinemachineCamera(CameraMode.ThirdPerson);
|
|
EventBus.Unsubscribe(this);
|
|
}
|
|
|
|
public void OnGameplaySceneLoaded()
|
|
{
|
|
}
|
|
|
|
private RaceTrackData _raceTrackData;
|
|
private RaceGame _raceGame;
|
|
private Container UNTILTHEYFIXCONTAINERS;
|
|
public void OnGameplaySceneInitialized(Container container)
|
|
{
|
|
UNTILTHEYFIXCONTAINERS = container;
|
|
|
|
_raceTrackData = container.Resolve<RaceTrackData>();
|
|
|
|
Context.CameraFactory.GetCinematicCamera(CameraMode.None).transform.position = _raceTrackData.CameraPosition.transform.position;
|
|
Context.CameraFactory.GetCinematicCamera(CameraMode.None).transform.rotation = _raceTrackData.CameraPosition.transform.rotation;
|
|
|
|
_gameplayLoading.DoProgress();
|
|
|
|
container.Resolve<IRacerFactory>();
|
|
}
|
|
|
|
public void RaceGameReady()
|
|
{
|
|
_gameplayLoading.DoProgress();
|
|
}
|
|
|
|
public void RacerFactoryInitialized()
|
|
{
|
|
_raceGame = (RaceGame)ConstructorInjector.Construct(typeof(RaceGame), UNTILTHEYFIXCONTAINERS);
|
|
|
|
_gameplayLoading.DoProgress();
|
|
}
|
|
|
|
public void UILoaded(UIPanelType uiPanelType)
|
|
{
|
|
if (uiPanelType != UIPanelType.PlayerScoreCounter) return;
|
|
|
|
Context.UIService.OpenPanel(UIPanelType.PlayerScoreCounter);
|
|
_gameplayLoading.DoProgress();
|
|
}
|
|
|
|
public void CinemachineLoaded(CinemachineCamera cinemachineCamera) => _gameplayLoading.DoProgress();
|
|
}
|
|
} |