Базовая инфраструктура
This commit is contained in:
1 parent
2e0dc15beb
commit
b5e28c7abb
117 files changed
+2068
-2031
No files matched your search
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b984d26778442e28274df043ee9a83c
|
||||
timeCreated: 1760423231
|
||||
@@ -0,0 +1,24 @@
|
||||
using Code.App.StateMachine;
|
||||
using Code.StateMachine;
|
||||
|
||||
namespace Code.App.AppStates
|
||||
{
|
||||
public class GameOverState : BaseState<AppStateMachineContext>
|
||||
{
|
||||
public GameOverState(AppStateMachineContext context) : base(context)
|
||||
{ }
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
base.EnterState();
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{ }
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
base.ExitState();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97314a9736904f47ab06a6744ca2692f
|
||||
timeCreated: 1758640549
|
||||
@@ -0,0 +1,38 @@
|
||||
using Code.App.StateMachine;
|
||||
using Code.Input;
|
||||
using Code.Scenes;
|
||||
using Code.StateMachine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.App.AppStates
|
||||
{
|
||||
public class GameplayState : BaseState<AppStateMachineContext>
|
||||
{
|
||||
public GameplayState(AppStateMachineContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
Context.SceneLoaderService.LoadScene((int)SceneIds.Gameplay, SceneLoaded);
|
||||
Context.InputService.EnableMap(ActionMappings.Gameplay);
|
||||
}
|
||||
|
||||
private void SceneLoaded()
|
||||
{
|
||||
|
||||
base.EnterState();
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
Context.InputService.DisableMap(ActionMappings.Gameplay);
|
||||
|
||||
base.ExitState();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b543b6d48f8b4c37bf3288f57d11dbc9
|
||||
timeCreated: 1758640462
|
||||
@@ -0,0 +1,35 @@
|
||||
using Code.App.StateMachine;
|
||||
using Code.Input;
|
||||
using Code.Scenes;
|
||||
using Code.StateMachine;
|
||||
|
||||
namespace Code.App.AppStates
|
||||
{
|
||||
public class MainMenuState : BaseState<AppStateMachineContext>
|
||||
{
|
||||
public MainMenuState(AppStateMachineContext context) : base(context)
|
||||
{ }
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
Context.SceneLoaderService.LoadScene((int)SceneIds.MainMenu, SceneLoaded);
|
||||
Context.InputService.EnableMap(ActionMappings.MainMenu);
|
||||
}
|
||||
|
||||
private void SceneLoaded()
|
||||
{
|
||||
|
||||
|
||||
base.EnterState();
|
||||
}
|
||||
public override void Tick()
|
||||
{ }
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
Context.InputService.DisableMap(ActionMappings.MainMenu);
|
||||
|
||||
base.ExitState();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74975b23ce5e4ba29add02c6406902f5
|
||||
timeCreated: 1758640536
|
||||
@@ -0,0 +1,60 @@
|
||||
using Code.App.StateMachine;
|
||||
using Code.Configs;
|
||||
using Code.Input;
|
||||
using Code.Scenes;
|
||||
using Code.StaticData;
|
||||
using Reflex.Core;
|
||||
using Reflex.Injectors;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Code.App
|
||||
{
|
||||
public class BootstrapInstaller : MonoBehaviour, IInstaller
|
||||
{
|
||||
|
||||
public void InstallBindings(ContainerBuilder containerBuilder)
|
||||
{
|
||||
InstallStaticData(containerBuilder, out IStaticDataService staticDataService);
|
||||
|
||||
InstallInfrastructureUnit(containerBuilder, staticDataService);
|
||||
|
||||
containerBuilder.AddSingleton(typeof(InputService), typeof(IInputService));
|
||||
containerBuilder.AddSingleton(typeof(SceneLoaderService), typeof(ISceneLoaderService));
|
||||
|
||||
containerBuilder.OnContainerBuilt += Bootstrap;
|
||||
}
|
||||
|
||||
private void InstallInfrastructureUnit(ContainerBuilder containerBuilder, IStaticDataService staticDataService)
|
||||
{
|
||||
GameObject infrastructureUnit = Instantiate(staticDataService.AppConfig.infrastructureUnitPrefab);
|
||||
DontDestroyOnLoad(infrastructureUnit);
|
||||
|
||||
containerBuilder.AddSingleton(infrastructureUnit);
|
||||
containerBuilder.AddSingleton(infrastructureUnit.GetComponent<ICoroutineRunner>(),
|
||||
typeof(ICoroutineRunner));
|
||||
containerBuilder.AddSingleton(infrastructureUnit.AddComponent<AppStateMachine>());
|
||||
}
|
||||
|
||||
private void InstallStaticData(ContainerBuilder containerBuilder, out IStaticDataService staticDataService)
|
||||
{
|
||||
staticDataService = new StaticDataService();
|
||||
staticDataService.Load();
|
||||
|
||||
containerBuilder.AddSingleton(staticDataService, typeof(IStaticDataService));
|
||||
containerBuilder.AddSingleton(staticDataService.InputConfig.inputActionAsset, typeof(InputActionAsset));
|
||||
}
|
||||
|
||||
private void Bootstrap(Container container)
|
||||
{
|
||||
AppStateMachine appStateMachine = container.Resolve<AppStateMachine>();
|
||||
appStateMachine.Initialize();
|
||||
|
||||
AttributeInjector.Inject(appStateMachine.StateMachineContext, container);
|
||||
|
||||
appStateMachine
|
||||
.SwitchState(AppState.MainMenu)
|
||||
.AllowStateTransition(AppState.Gameplay);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1efb7de496e44fed9b40cb92d99ef116
|
||||
timeCreated: 1760423402
|
||||
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.App
|
||||
{
|
||||
public class CoroutineRunner : MonoBehaviour, ICoroutineRunner
|
||||
{
|
||||
private void Awake() => DontDestroyOnLoad(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1c87e09de06474cb53bc7ebb77e90cd
|
||||
timeCreated: 1760423209
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8550610dc3df4f2ea40f05e33fc4a323
|
||||
timeCreated: 1760423877
|
||||
@@ -0,0 +1,18 @@
|
||||
using Code.App.StateMachine;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.App.Debug
|
||||
{
|
||||
public class GoToState : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private AppState gotoState;
|
||||
[SerializeField] private AppState allowedState;
|
||||
[Inject] private AppStateMachine _appStateMachine;
|
||||
private void Start()
|
||||
{
|
||||
_appStateMachine.SwitchState(gotoState)
|
||||
.AllowStateTransition(allowedState);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: affd42e82c2547a5af4604b574a24f59
|
||||
timeCreated: 1760083049
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.App
|
||||
{
|
||||
public interface ICoroutineRunner
|
||||
{
|
||||
Coroutine StartCoroutine(IEnumerator coroutine);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e7be46265584ecb9643632be0164f68
|
||||
timeCreated: 1760423209
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3240c88cce7490dadba30536b7c2189
|
||||
timeCreated: 1760423231
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace Code.App.StateMachine
|
||||
{
|
||||
[Flags]
|
||||
public enum AppState
|
||||
{
|
||||
Bootstrap = 1,
|
||||
MainMenu = 2,
|
||||
Gameplay = 4,
|
||||
GameOver = 8
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bda641d023e417083386b3e0bce89b1
|
||||
timeCreated: 1758561696
|
||||
@@ -0,0 +1,33 @@
|
||||
using Code.App.AppStates;
|
||||
using Code.StateMachine;
|
||||
|
||||
namespace Code.App.StateMachine
|
||||
{
|
||||
public class AppStateMachine : AbstractStateMachine<AppState, AppStateMachineContext>
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
States.Add(AppState.MainMenu, new MainMenuState(StateMachineContext));
|
||||
States.Add(AppState.Gameplay, new GameplayState(StateMachineContext));
|
||||
States.Add(AppState.GameOver, new GameOverState(StateMachineContext));
|
||||
|
||||
AllowedStates |= AppState.MainMenu;
|
||||
AllowedStates |= AppState.Gameplay;
|
||||
}
|
||||
|
||||
protected override bool CheckTransitionAllowed(AppState nextState) => AllowedStates.HasFlag(nextState);
|
||||
protected override void ResetAllowedTransitions() => AllowedStates = 0;
|
||||
}
|
||||
|
||||
public static class AppStateMachineExtensions
|
||||
{
|
||||
public static AbstractStateMachine<AppState, AppStateMachineContext> AllowStateTransition(
|
||||
this AbstractStateMachine<AppState, AppStateMachineContext> appStateMachine, AppState state)
|
||||
{
|
||||
if (appStateMachine == null) return null;
|
||||
|
||||
appStateMachine.AllowedStates |= state;
|
||||
return appStateMachine;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 818668cb48d54c90859d6486f38e307a
|
||||
timeCreated: 1758561251
|
||||
@@ -0,0 +1,12 @@
|
||||
using Code.Input;
|
||||
using Code.Scenes;
|
||||
using Reflex.Attributes;
|
||||
|
||||
namespace Code.App.StateMachine
|
||||
{
|
||||
public class AppStateMachineContext
|
||||
{
|
||||
[Inject] public ISceneLoaderService SceneLoaderService;
|
||||
[Inject] public IInputService InputService;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7ceb9ced4a3f47c3b0e56b7469164c38
|
||||
timeCreated: 1758654630
|
||||
Reference in new issue
Block a user