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

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)
{
}
}
}
@@ -54,6 +54,8 @@ namespace Code.Infrastructure.Audio
public async UniTaskVoid LoadAudioClips(AudioNames groupName)
{
UnityEngine.Debug.LogWarning($"Audios loaded {groupName}");
foreach (var audioInfo in _audioInfos[groupName])
if (!_clipsHandles[groupName].ContainsKey(audioInfo.Key))
_clipsHandles[groupName].Add(audioInfo.Key, Addressables.LoadAssetAsync<AudioClip>(audioInfo.Value));
@@ -71,6 +73,7 @@ namespace Code.Infrastructure.Audio
public void ReleaseAudios(AudioNames groupName)
{
UnityEngine.Debug.LogWarning($"Audios unloaded {groupName}");
_eventBus.RaiseEvent<IAudioClipsEventHandle>(x=> x.AudioClipsUnLoaded(groupName));
foreach (var handle in _clipsHandles)
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Code.Infrastructure.Configs;
using Code.Infrastructure.EventBus;
using Code.Infrastructure.Generators;
@@ -36,7 +37,11 @@ namespace Code.Infrastructure.SceneLoader
// TODO типилище
public async UniTaskVoid LoadSceneAsync(SceneId id, LoadSceneMode loadMode)
{
{
if (loadMode == LoadSceneMode.Single)
for (var i = 0; i < _loadedScenes.Count; i++)
UnloadSceneAsync(_loadedScenes.Keys.ToList()[i]).Forget();
_loadedScenes.Add(id,Addressables.LoadSceneAsync(_sceneInfos[id].SceneAsset, loadMode));
await _loadedScenes[id];
@@ -6,12 +6,12 @@ namespace Code.Infrastructure.UI.Panels
{
public override void Open(Action callback = null)
{
callback?.Invoke();
}
public override void Close(Action callback = null)
{
callback?.Invoke();
}
}
}
@@ -1,18 +1,22 @@
using System;
using Code.Debug;
using Code.Infrastructure.Audio;
using Reflex.Attributes;
using UnityEngine;
namespace Code.Infrastructure.UI.Panels
{
public class MenuChoosePanel : UIPanel
{
[Inject] IAudioService _audioService;
[SerializeField] private SceneChooser sceneChooser;
public void PlaySelectSound() => _audioService.PlayOneShot(AudioNames.UISounds, 7);
public void PlayDeselectSound() => _audioService.PlayOneShot(AudioNames.UISounds, 8);
public void PlayClickSound() => _audioService.PlayOneShot(AudioNames.UISounds, 1);
public override void Open(Action callback = null)
{
sceneChooser.EnableButtons();
callback?.Invoke();
}
public override void Close(Action callback = null)
+4 -1
View File
@@ -43,13 +43,16 @@ namespace Code.Infrastructure.UI
public async UniTaskVoid LoadPanel(UIPanelType panelType)
{
var panel = (await Addressables.InstantiateAsync(_configs[panelType].Prefab, _canvas.transform).ToUniTask()).GetComponent<UIPanel>();
var panel = (await Addressables.InstantiateAsync(_configs[panelType].Prefab, _canvas.transform).ToUniTask())
.GetComponent<UIPanel>();
UnityEngine.Debug.LogWarning($"Panel loaded {panelType}");
_eventBus.RaiseEvent<IUIPanelLoadedHandle>(ui => ui.UIPanelLoaded(panel, panelType));
}
public void ReleasePanel(UIPanel panel)
{
UnityEngine.Debug.LogWarning($"Panel released {panel.gameObject.name}");
Addressables.ReleaseInstance(panel.gameObject);
}
@@ -6,6 +6,7 @@ namespace Code.Infrastructure.UI
Loading,
DebugSceneChooser,
PlayerScoreCounter,
WinScreen,
DebugMenu
}
}
@@ -15,6 +15,7 @@ namespace Code.Infrastructure.UI
void TryLoadPanel(UIPanelType uiPanelType);
void TryRemovePanel(UIPanelType uiPanelType);
void SetCanvasCamera(UnityEngine.Camera camera);
UIPanel TryGetPanel(UIPanelType panelType);
}
public class UIService : IUIPanelLoadedHandle, IUIService
@@ -34,6 +35,7 @@ namespace Code.Infrastructure.UI
public void SetCanvasCamera(UnityEngine.Camera camera)
{
_factory.Canvas.worldCamera = camera;
_factory.Canvas.planeDistance = 0.3f;
}
public void OpenPanel(UIPanelType uiPanelType)
@@ -75,6 +77,8 @@ namespace Code.Infrastructure.UI
_factory.ReleasePanel(_loadedPanels[panelType]);
_loadedPanels.Remove(panelType);
}
public UIPanel TryGetPanel(UIPanelType panelType) => _loadedPanels.GetValueOrDefault(panelType);
}
public interface IUIPanelLoaded : IGlobalSubscriber