mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 07:41:10 +00:00
feat: add state machine
This commit is contained in:
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Logic.Gameplay.Features;
|
||||
using _Project.Develop.Runtime.Logic.Gameplay.Features.AI;
|
||||
using _Project.Develop.Runtime.Utils.InputManagement;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -16,7 +17,7 @@ namespace Assets._Project.Develop.Runtime.Gameplay.Infrastructure
|
||||
|
||||
private DIContainer _container;
|
||||
private EntitiesLifeContext _entitiesLifeContext;
|
||||
private GameplayInputArgs _gameplayArgs;
|
||||
private AIBrainsContext _aiBrainsContext;
|
||||
|
||||
private IPlayerInput _playerInput;
|
||||
|
||||
@@ -28,12 +29,12 @@ namespace Assets._Project.Develop.Runtime.Gameplay.Infrastructure
|
||||
throw new ArgumentException($"{nameof(sceneArgs)} is not match with {typeof(GameplayInputArgs)} type");
|
||||
|
||||
GameplayContextRegistrations.Process(_container);
|
||||
_gameplayArgs = gameplayInputArgs;
|
||||
}
|
||||
|
||||
public override IEnumerator Initialize()
|
||||
{
|
||||
_entitiesLifeContext = _container.Resolve<EntitiesLifeContext>();
|
||||
_aiBrainsContext = _container.Resolve<AIBrainsContext>();
|
||||
|
||||
_testGameplay.Initialize(_container);
|
||||
yield break;
|
||||
@@ -46,6 +47,7 @@ namespace Assets._Project.Develop.Runtime.Gameplay.Infrastructure
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_aiBrainsContext?.Update(Time.deltaTime);
|
||||
_entitiesLifeContext?.Update(Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Logic.Gameplay.Features.AI;
|
||||
using _Project.Develop.Runtime.UI;
|
||||
using _Project.Develop.Runtime.UI.Core;
|
||||
using _Project.Develop.Runtime.UI.Screens.Gameplay;
|
||||
@@ -21,9 +22,13 @@ namespace Assets._Project.Develop.Runtime.Gameplay.Infrastructure
|
||||
container.RegisterAsSingle(CreateEntitiesFactory);
|
||||
container.RegisterAsSingle(CreateEntitiesLifeContext);
|
||||
container.RegisterAsSingle(CreateCollidersRegistryService);
|
||||
container.RegisterAsSingle(CreateAIBrainContext);
|
||||
container.RegisterAsSingle(CreateBrainsFactory);
|
||||
container.RegisterAsSingle(CreateMonoEntitiesFactory).NonLazy();
|
||||
}
|
||||
|
||||
private static AIBrainsContext CreateAIBrainContext(DIContainer c) => new();
|
||||
private static BrainsFactory CreateBrainsFactory(DIContainer c) => new(c);
|
||||
private static EntitiesLifeContext CreateEntitiesLifeContext(DIContainer c) => new();
|
||||
|
||||
private static EntitiesFactory CreateEntitiesFactory(DIContainer c) => new(c);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Logic.Gameplay.Features.AI;
|
||||
using _Project.Develop.Runtime.Utils.InputManagement;
|
||||
using Assets._Project.Develop.Runtime.Infrastructure.DI;
|
||||
using UnityEngine;
|
||||
@@ -10,8 +11,11 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features
|
||||
{
|
||||
private DIContainer _container;
|
||||
private EntitiesFactory _entitiesFactory;
|
||||
private BrainsFactory _brainsFactory;
|
||||
|
||||
private Entity _entity;
|
||||
private Entity _hero;
|
||||
private Entity _ghost;
|
||||
|
||||
private bool _isRunning;
|
||||
|
||||
public void Initialize(DIContainer container)
|
||||
@@ -20,15 +24,15 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features
|
||||
|
||||
_container.Resolve<IPlayerInput>().Enable();
|
||||
_entitiesFactory = _container.Resolve<EntitiesFactory>();
|
||||
_brainsFactory = _container.Resolve<BrainsFactory>();
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
_entity = _entitiesFactory.CreateTeleportWizard(Vector3.zero);
|
||||
|
||||
_entitiesFactory.CreateGhost(Vector3.zero + Vector3.forward * 5);
|
||||
_entitiesFactory.CreateGhost(Vector3.zero + Vector3.right * 5);
|
||||
_entitiesFactory.CreateGhost(Vector3.zero + Vector3.left * 5);
|
||||
_hero = _entitiesFactory.CreateTeleportWizard(Vector3.zero);
|
||||
_ghost = _entitiesFactory.CreateGhost(Vector3.zero + Vector3.forward * 5);
|
||||
|
||||
_brainsFactory.CreateGhostBrain(_ghost);
|
||||
|
||||
_isRunning = true;
|
||||
}
|
||||
@@ -41,11 +45,11 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (_entity == null)
|
||||
if (_hero == null)
|
||||
return;
|
||||
|
||||
GUI.Label(new Rect(10, 20, 200, 50), $"Health: {_entity.CurrentHealth.Value}/{_entity.MaxHealth.Value}");
|
||||
GUI.Label(new Rect(10, 40, 200, 50), $"Energy: {_entity.CurrentEnergy.Value}/{_entity.MaxEnergy.Value}");
|
||||
GUI.Label(new Rect(10, 20, 200, 50), $"Health: {_hero.CurrentHealth.Value}/{_hero.MaxHealth.Value}");
|
||||
GUI.Label(new Rect(10, 40, 200, 50), $"Energy: {_hero.CurrentEnergy.Value}/{_hero.MaxEnergy.Value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user