Теперь Addressables и UniTask в InstantiateAsync и прочих процессах

This commit is contained in:
ThomasCharester committed 2025-11-03 12:31:26 +03:00
1 parent 6b1f24b72e
commit f940cbffe0
45 files changed
+811 -189

No files matched your search

@@ -0,0 +1,12 @@
using Code.App.StateMachine;
using Code.StateMachine;
namespace Code.App.AppStates
{
public class BootstrapState : BaseState<AppStateMachineContext>
{
public BootstrapState(AppStateMachineContext context) : base(context)
{
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0183e73a08c64332babded3df3d06b95
timeCreated: 1762122962
@@ -22,17 +22,19 @@ namespace Code.App.AppStates
public override void EnterState()
{
_uiLoaded = _sceneLoaded = false;
Context.UIService.LoadingScreen.Show();
Context.SceneLoaderService.LoadSceneAsync((int)SceneIds.MovementDev, callBack: OnSceneLoaded); // TODO Фабрика говна Nada
_playerMoney = Context.PlayerFactory.CreatePlayerMoney();
_playerHealth = Context.PlayerFactory.CreatePlayerHealth();
_playerHealth.OnDeath += EndGame;
Context.SceneLoaderService.LoadSceneAsync((int)SceneIds.MovementDev, callBack: OnSceneLoaded); // TODO Фабрика игрока Nada
Context.UIService.SwitchPanelTo(UIPanel.Gameplay, callback: PostUILoaded);
_playerMoney = Context.PlayerFactory.CreatePlayerMoney();
_playerHealth = Context.PlayerFactory.CreatePlayerHealth();
_playerHealth.OnDeath += EndGame;
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.GiveHealth, GiveHealth);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.GiveMoney, GiveMoney);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.LooseHealth, LooseHealth);
@@ -47,8 +49,7 @@ namespace Code.App.AppStates
private void PostUILoaded()
{
((GameplayPanel)(Context.UIService.CurrentPanel)).Initialize(_playerMoney, _playerHealth);
Context.UIService.LoadingScreen.Hide();
((GameplayPanel)Context.UIService.CurrentPanel).Initialize(_playerMoney, _playerHealth);
_uiLoaded = true;
CheckIfLoaded();
}
@@ -21,8 +21,7 @@ namespace Code.App.AppStates
public override void EnterState()
{
_uiLoaded = false;
_sceneLoaded = false;
_uiLoaded = _sceneLoaded = false;
Context.UIService.LoadingScreen.Show();
@@ -1,20 +1,25 @@
using System.Threading.Tasks;
using Code.App.StateMachine;
using Code.Configs;
using Code.Constants;
using Code.Gameplay.Camera;
using Code.Gameplay.Player;
using Code.Input;
using Code.Scenes;
using Code.StaticData;
using Code.UI;
using Code.UI.Panels;
using Cysharp.Threading.Tasks;
using Reflex.Core;
using Reflex.Injectors;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.InputSystem;
namespace Code.App
{
public class BootstrapInstaller : MonoBehaviour, IInstaller
{
public void InstallBindings(ContainerBuilder containerBuilder)
{
InstallStaticData(containerBuilder, out IStaticDataService staticDataService);
@@ -37,8 +42,10 @@ namespace Code.App
// CameraService cameraService = Instantiate(staticDataService.CameraConfig.cameraPrefab);
// containerBuilder.AddSingleton(cameraService);
// DontDestroyOnLoad(cameraService);
Camera camera = Instantiate(staticDataService.CameraConfig.cameraPrefab);
// var task = staticDataService.InstantiateAsset<Camera>(staticDataService.CameraConfig.cameraAssetReference);
Camera camera = Instantiate(staticDataService.CameraConfig.cameraPrefab);
// Camera camera = task.Result;
DontDestroyOnLoad(camera);
containerBuilder.AddSingleton(camera);
}
@@ -50,7 +57,7 @@ namespace Code.App
containerBuilder.AddSingleton(infrastructureUnit);
containerBuilder.AddSingleton(infrastructureUnit.AddComponent<CoroutineRunner>(),
typeof(ICoroutineRunner));
typeof(ICoroutineRunner));
containerBuilder.AddSingleton(infrastructureUnit.AddComponent<AppStateMachine>());
containerBuilder.AddSingleton(infrastructureUnit.AddComponent<CameraStateMachine>());
}
@@ -61,29 +68,42 @@ namespace Code.App
staticDataService.Load();
containerBuilder.AddSingleton(staticDataService, typeof(IStaticDataService));
// containerBuilder.AddSingleton(staticDataService.InputConfig.inputActionAsset, typeof(InputActionAsset));
containerBuilder.AddSingleton(staticDataService.InputConfig.inputActionAsset, typeof(InputActionAsset));
containerBuilder.AddSingleton(staticDataService.InputConfig, typeof(InputConfig));
containerBuilder.AddSingleton(staticDataService.CameraConfig, typeof(CameraConfig));
containerBuilder.AddSingleton(staticDataService.PlayerConfig, typeof(PlayerConfig));
containerBuilder.AddSingleton(staticDataService.CharacterConfig, typeof(CharacterConfig));
containerBuilder.AddSingleton(staticDataService.UIConfig, typeof(UIConfig));
// containerBuilder.AddSingleton(staticDataService.UIConfig.canvasPrefab, typeof(Canvas));
// containerBuilder.AddSingleton(staticDataService.UIConfig.uiElementsPrefabs, typeof(UIElement[]));
}
private bool _onUiLoaded;
private AppStateMachine _appStateMachine;
private void Bootstrap(Container container)
{
AppStateMachine appStateMachine = container.Resolve<AppStateMachine>();
appStateMachine.Initialize();
AttributeInjector.Inject(appStateMachine.StateMachineContext, container);
_appStateMachine = container.Resolve<AppStateMachine>();
_appStateMachine.Initialize();
AttributeInjector.Inject(_appStateMachine.StateMachineContext, container);
CameraStateMachine cameraStateMachine = container.Resolve<CameraStateMachine>();
AttributeInjector.Inject(cameraStateMachine.StateMachineContext, container);
cameraStateMachine.Initialize();
var loadingScreen = GameObject.FindWithTag(Tags.LoadingScreen);
DontDestroyOnLoad(loadingScreen);
IUIService uiService = container.Resolve<IUIService>();
uiService.Initialize(loadingScreen.GetComponent<LoadingScreen>());
TryStartGame();
}
private void TryStartGame()
{
// TODO: поменяно для теста
appStateMachine
_appStateMachine
.SwitchState(AppState.MainMenu)
.AllowStateTransition(AppState.Gameplay);
}
@@ -7,6 +7,7 @@ namespace Code.App.StateMachine
{
public override void Initialize()
{
States.Add(AppState.Bootstrap, new BootstrapState(StateMachineContext));
States.Add(AppState.MainMenu, new MainMenuState(StateMachineContext));
States.Add(AppState.Gameplay, new GameplayState(StateMachineContext));
States.Add(AppState.GameOver, new GameOverState(StateMachineContext));
@@ -16,6 +17,8 @@ namespace Code.App.StateMachine
AllowedStates |= AppState.MainMenu;
AllowedStates |= AppState.Gameplay;
AllowedStates |= AppState.MovementDev;
CurrentBaseState = States[AppState.Bootstrap];
}
protected override bool CheckTransitionAllowed(AppState nextState) => AllowedStates.HasFlag(nextState);