ИИ гонщиков, запуск, перезапуск игры и пр

This commit is contained in:
ThomasCharester committed 2026-02-09 16:22:37 +03:00
1 parent f557c58c9d
commit efcfaae647
48 files changed
+1486 -212

No files matched your search

@@ -22,6 +22,7 @@ namespace Code.Infrastructure.App
[Inject] public IAudioFactory AudioFactory { get; set; }
[Inject] public IAudioService AudioService { get; set; }
[Inject] public IInputService InputService { get; set; }
public AppStateMachine StateMachine { get; set; }
}
[Generators.StateMachine(typeof(AppStateMachineContext),typeof(AppStates))]
@@ -110,6 +110,7 @@ namespace Code.Infrastructure.App
container.Resolve<EventBus.EventBus>().Unsubscribe(this);
container.Resolve<AppStateMachine>().SwitchState(AppStates.Bootstrap)
.AllowStateTransition(AppStates.Gameplay);
container.Resolve<AppStateMachineContext>().StateMachine = container.Resolve<AppStateMachine>();
}
public void SceneConfigsLoaded()
@@ -1,4 +1,3 @@
using Code.Debug;
using Code.Example.Race;
using Code.Example.Race.Racer;
using Code.Example.Race.Track;
@@ -6,21 +5,24 @@ using Code.Infrastructure.SceneLoader;
using Reflex.Core;
using Reflex.Enums;
using UnityEngine;
using UnityEngine.Serialization;
using Resolution = Reflex.Enums.Resolution;
namespace Code.Infrastructure.App.SceneInstallers
{
public class GameplaySceneInstaller : MonoBehaviour, IInstaller
{
[SerializeField] private RaceTrackData _raceTrackData;
[SerializeField] private RaceTrackData raceTrackData;
public void InstallBindings(ContainerBuilder containerBuilder)
{
containerBuilder.RegisterType(typeof(RacerFactory), new[] { typeof(IRacerFactory) }, Lifetime.Scoped,
Resolution.Lazy);
containerBuilder.RegisterType(typeof(RaceScores), Lifetime.Scoped,
Resolution.Eager);
containerBuilder.RegisterValue(raceTrackData);
containerBuilder.RegisterType(typeof(RaceGame), Lifetime.Scoped,
Resolution.Lazy);
containerBuilder.RegisterValue(_raceTrackData);
containerBuilder.OnContainerBuilt += PostInstall;
}
@@ -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)
{
}
}
}