ИИ гонщиков, запуск, перезапуск игры и пр
This commit is contained in:
1 parent
f557c58c9d
commit
efcfaae647
48 files changed
+1486
-212
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System.Threading;
|
||||
using System.Threading;
|
||||
using Code.Debug;
|
||||
using Code.Infrastructure.Audio;
|
||||
using Code.Infrastructure.Generators;
|
||||
using Code.Infrastructure.UI;
|
||||
@@ -37,7 +38,7 @@ namespace Code.Infrastructure.App.States
|
||||
{
|
||||
if (uiPanelType != UIPanelType.DebugSceneChooser) return;
|
||||
|
||||
Context.UIService.OpenPanel(uiPanelType);
|
||||
Context.UIService.OpenPanel(uiPanelType);
|
||||
}
|
||||
public void OnReadyToPlay(AudioNames groupName)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Linq;
|
||||
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.Example.Race.UI;
|
||||
using Code.Infrastructure.Audio;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Camera.CameraStates;
|
||||
@@ -11,6 +13,7 @@ using Code.Infrastructure.Input;
|
||||
using Code.Infrastructure.Loadings;
|
||||
using Code.Infrastructure.SceneLoader;
|
||||
using Code.Infrastructure.UI;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Reflex.Core;
|
||||
using Reflex.Injectors;
|
||||
using Unity.Cinemachine;
|
||||
@@ -22,7 +25,7 @@ namespace Code.Infrastructure.App.States
|
||||
[StateRaisingEvent]
|
||||
public partial class GameplayState :
|
||||
IOnGameplaySceneLoadedHandler,
|
||||
IRaceGameInitializedHandle,
|
||||
IRaceGameHandle,
|
||||
IRacerFactoryInitializedHandle,
|
||||
IUIPanelLoaded,
|
||||
ICinematicMachineHandle
|
||||
@@ -44,10 +47,12 @@ namespace Code.Infrastructure.App.States
|
||||
// RaceGame
|
||||
// Factory
|
||||
// PlayerCounter
|
||||
// WinScreen
|
||||
// CinemachineCamera
|
||||
_gameplayLoading = new Loading(5, GameplayLoadingCompleted);
|
||||
_gameplayLoading = new Loading(6, GameplayLoadingCompleted);
|
||||
|
||||
Context.UIService.TryLoadPanel(UIPanelType.PlayerScoreCounter);
|
||||
Context.UIService.TryLoadPanel(UIPanelType.WinScreen);
|
||||
Context.SceneLoader.LoadSceneAsync(SceneId.Gameplay, LoadSceneMode.Single).Forget();
|
||||
Context.InputService.EnableMap(ActionMappings.Gameplay);
|
||||
Context.CameraFactory.LoadCinemachineCamera(CameraMode.ThirdPerson).Forget();
|
||||
@@ -75,7 +80,12 @@ namespace Code.Infrastructure.App.States
|
||||
{
|
||||
Context.InputService.DisableMap(ActionMappings.Gameplay);
|
||||
Context.UIService.TryRemovePanel(UIPanelType.PlayerScoreCounter);
|
||||
Context.UIService.TryRemovePanel(UIPanelType.WinScreen);
|
||||
Context.CameraFactory.ReleaseCinemachineCamera(CameraMode.ThirdPerson);
|
||||
Context.InputService.DisableMap(ActionMappings.Gameplay);
|
||||
|
||||
_raceGame = null;
|
||||
|
||||
EventBus.Unsubscribe(this);
|
||||
}
|
||||
|
||||
@@ -105,17 +115,50 @@ namespace Code.Infrastructure.App.States
|
||||
_gameplayLoading.DoProgress();
|
||||
}
|
||||
|
||||
public void RaceGameEnded(RaceScores scores)
|
||||
{
|
||||
var winScreen = (WinScreen)Context.UIService.TryGetPanel(UIPanelType.WinScreen);
|
||||
|
||||
var id = 0;
|
||||
var cachedScores = scores.GetScores();
|
||||
|
||||
for (var i = 0; i < cachedScores.Count; i++)
|
||||
if (cachedScores[i].Key.Data.type == RacerType.Player) id = i + 1;
|
||||
|
||||
var winText = $@"{id} МЕСТО\n";
|
||||
winScreen.SetText(winText);
|
||||
|
||||
Context.UIService.ClosePanel(UIPanelType.PlayerScoreCounter);
|
||||
Context.UIService.OpenPanel(UIPanelType.WinScreen);
|
||||
|
||||
EndTheGame().Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid EndTheGame()
|
||||
{
|
||||
await UniTask.WaitForSeconds(3f);
|
||||
|
||||
Context.UIService.OpenPanel(UIPanelType.Loading);
|
||||
Context.StateMachine.SwitchState(AppStates.MainMenu).AllowStateTransition(AppStates.Gameplay);
|
||||
}
|
||||
|
||||
public void RacerFactoryInitialized()
|
||||
{
|
||||
_raceGame = (RaceGame)ConstructorInjector.Construct(typeof(RaceGame), UNTILTHEYFIXCONTAINERS);
|
||||
_raceGame = UNTILTHEYFIXCONTAINERS.Resolve<RaceGame>();
|
||||
|
||||
_gameplayLoading.DoProgress();
|
||||
}
|
||||
|
||||
public void UILoaded(UIPanelType uiPanelType)
|
||||
{
|
||||
if(uiPanelType == UIPanelType.WinScreen)
|
||||
{
|
||||
_gameplayLoading.DoProgress();
|
||||
return;
|
||||
}
|
||||
|
||||
if (uiPanelType != UIPanelType.PlayerScoreCounter) return;
|
||||
|
||||
|
||||
Context.UIService.OpenPanel(UIPanelType.PlayerScoreCounter);
|
||||
_gameplayLoading.DoProgress();
|
||||
}
|
||||
|
||||
@@ -1,22 +1,74 @@
|
||||
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
|
||||
public partial class MainMenuState : IUIPanelLoaded, IReadyToPlayHandle, IOnMainMenuSceneLoadedHandler
|
||||
{
|
||||
private EventBus.EventBus _eventBus;
|
||||
public MainMenuState(AppStateMachineContext context, EventBus.EventBus eventBus) : base(context,eventBus)
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
}
|
||||
|
||||
public override AppStates myState => AppStates.MainMenu;
|
||||
private Loading _loading;
|
||||
protected override void OnEnterState()
|
||||
{
|
||||
_eventBus.Subscribe(this);
|
||||
|
||||
_loading = new Loading(2, LoadComplete);
|
||||
|
||||
Context.UIService.TryLoadPanel(UIPanelType.DebugSceneChooser);
|
||||
// Context.AudioFactory.LoadAudioClips(AudioNames.UISounds);
|
||||
Context.SceneLoader.LoadSceneAsync(SceneId.MainMenu, LoadSceneMode.Single).Forget();
|
||||
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0);
|
||||
}
|
||||
|
||||
|
||||
protected override void OnExitState()
|
||||
{
|
||||
// Context.AudioFactory.ReleaseAudios(AudioNames.UISounds);
|
||||
Context.UIService.TryRemovePanel(UIPanelType.DebugSceneChooser);
|
||||
_eventBus.Unsubscribe(this);
|
||||
}
|
||||
|
||||
public void UILoaded(UIPanelType uiPanelType)
|
||||
{
|
||||
if (uiPanelType != UIPanelType.DebugSceneChooser) return;
|
||||
|
||||
Context.UIService.OpenPanel(uiPanelType);
|
||||
_loading.DoProgress();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void OnMainMenuSceneLoaded()
|
||||
{
|
||||
_loading.DoProgress();
|
||||
}
|
||||
|
||||
public void OnMainMenuSceneInitialized(Container container)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user