Мобы на уровнях, анимации

This commit is contained in:
ThomasCharester committed 2025-12-01 12:59:15 +03:00
1 parent fb9510a6b2
commit 2f56a5758d
61 files changed
+2299 -596

No files matched your search

@@ -88,10 +88,13 @@ namespace Code.App.AppStates
{
Context.LoadingManager
.RegisterLoading(LoadingWork.LoadModelResource);
Context.LoadingManager.OnLoadingEnded -= AfterSceneLoaded;
Context.LoadingManager.OnLoadingEnded += AfterPlayerLoaded;
Context.PlayerProvider = SceneManager.GetActiveScene().GetSceneContainer().Resolve<IPlayerProvider>();
Context.PlayerFactory = SceneManager.GetActiveScene().GetSceneContainer().Resolve<IPlayerFactory>();
await UniTask.WhenAll(
WaitForPlayerArmsToInitialize(),
WaitForPlayerCharacterLoad()
@@ -33,11 +33,7 @@ namespace Code.App
containerBuilder.AddSingleton(typeof(LoadingManager), typeof(ILoadingManager));
containerBuilder.AddSingleton(typeof(InputService), typeof(IInputService));
// Перенести нахуй в контейнер геймплея
containerBuilder.AddSingleton(typeof(PlayerFactory), typeof(IPlayerFactory));
containerBuilder.AddSingleton(typeof(EnemyFactory), typeof(IEnemyFactory));
containerBuilder.AddSingleton(typeof(PlayerProvider), typeof(IPlayerProvider));
//
InitializeCamera(containerBuilder, staticDataService);
containerBuilder.AddSingleton(typeof(UIFactory), typeof(IUIFactory));
@@ -1,4 +1,5 @@
using Code.App.Loading;
using Code.Gameplay.Enemies;
using Code.Gameplay.Orders.Order;
using Code.Gameplay.Player;
using Code.Generator;
@@ -21,6 +22,9 @@ namespace Code.App.SceneInstallers
containerBuilder.AddScoped(typeof(PlayerScore), typeof(IPlayerScore));
containerBuilder.AddScoped(typeof(OrderService), typeof(IOrderService));
containerBuilder.AddScoped(typeof(RoomGeneratorFactory), typeof(IRoomGeneratorFactory));
containerBuilder.AddScoped(typeof(PlayerProvider), typeof(IPlayerProvider));
containerBuilder.AddScoped(typeof(PlayerFactory), typeof(IPlayerFactory));
containerBuilder.AddScoped(typeof(EnemyFactory), typeof(IEnemyFactory));
containerBuilder.AddScoped(typeof(RoomGenerator));
containerBuilder.OnContainerBuilt += Initialize;
@@ -37,7 +41,7 @@ namespace Code.App.SceneInstallers
loadingManager
.UnregisterLoading(LoadingWork.LoadScene);
LoadRooms(container,loadingManager);
LoadRooms(container,loadingManager).Forget();
}
private async UniTaskVoid LoadRooms(Container container, ILoadingManager loadingManager)
@@ -19,10 +19,10 @@ namespace Code.App.StateMachine
[Inject] public AppStateMachine StateMachine { get; private set; }
[Inject] public CameraStateMachine CameraStateMachine { get; private set; }
[Inject] public IUIService UIService { get; private set; }
[Inject] public IPlayerFactory PlayerFactory { get; private set; }
[Inject] public IPlayerProvider PlayerProvider { get; private set; }
[Inject] public IAudioFactory AudioFactory { get; private set; }
[Inject] public IAudioService AudioService { get; private set; }
[Inject] public IEnemyFactory EnemyFactory { get; private set; }
/*[Inject]*/public IPlayerFactory PlayerFactory { get; set; }
/*[Inject]*/public IPlayerProvider PlayerProvider { get; set; }
// [Inject] public IEnemyFactory EnemyFactory { get; private set; }
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f17ace0fa75741f2a730ff21181c6e8c
timeCreated: 1764575680
@@ -0,0 +1,23 @@
using UnityEngine;
using UnityEngine.AI;
namespace Code.Gameplay.Enemies.Animators
{
public class EnemyAnimator : MonoBehaviour
{
private static readonly int Velocity = Animator.StringToHash("Velocity");
[SerializeField] private Animator animator;
[SerializeField] private NavMeshAgent agent;
private void SetVelocity(float velocity)
{
animator.SetFloat(Velocity, velocity);
}
private void Update()
{
if(agent) SetVelocity(agent.velocity.magnitude);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 936125a7ed844674b0e0586a484253ce
timeCreated: 1764575708
@@ -3,6 +3,7 @@ using UnityEngine.AI;
using Code.Gameplay.Player;
using Code.Gameplay.Character.Controller;
using Code.Gameplay.Character.Core;
using Code.Gameplay.Enemies.Animators;
using Reflex.Attributes;
using Reflex.Core;
using Reflex.Injectors;
@@ -12,7 +13,7 @@ namespace Code.Gameplay.Enemies
public abstract class BaseEnemy : MonoBehaviour
{
[SerializeField] protected NavMeshAgent agent;
[SerializeField] protected Collider enemyCollider;
[SerializeField] protected Collider enemyCollider;
protected int Damage;
protected float AttackCooldown;
@@ -50,16 +51,17 @@ namespace Code.Gameplay.Enemies
protected virtual void Awake()
{
if (_playerProvider == null)
{
AttributeInjector.Inject(this, Container.ProjectContainer);
}
// // TODO Мешает
// if (_playerProvider == null)
// {
// AttributeInjector.Inject(this, Container.ProjectContainer);
// }
}
protected virtual void Update()
{
if (!Player) return;
HandleStun();
HandleAttackCooldown();
if (_isStunned) return;
@@ -1,4 +1,5 @@
using Code.Configs;
using Code.Gameplay.Enemies.Animators;
using Reflex.Attributes;
using UnityEngine;
using UnityEngine.AI;
@@ -38,15 +39,14 @@ namespace Code.Gameplay.Enemies
if (agent == null) return;
var walkableArea = NavMesh.GetAreaFromName("Walkable");
agent.areaMask = 1 << walkableArea;
agent.areaMask = 1 << walkableArea;
}
protected override void HandleAttack()
{
if (!Player) return;
var distance = Vector3.Distance(transform.position, Player.transform.position);
if (!(distance <= AttackRange)) return;
if (Player.CustomCharacterController.IsSliding)
@@ -27,6 +27,7 @@ namespace Code.Gameplay.Enemies
)
.ToUniTask();
// Работает, пока не трогаю
AttributeInjector.Inject(enemyObj, Container.ProjectContainer);
return enemyObj.GetComponent<BaseEnemy>();
@@ -1,8 +1,6 @@
using Code.Gameplay.Player;
using Cysharp.Threading.Tasks;
using Reflex.Attributes;
using Reflex.Core;
using Reflex.Injectors;
using Reflex.Attributes;
using UnityEngine;
namespace Code.Gameplay.Enemies
@@ -20,13 +18,14 @@ namespace Code.Gameplay.Enemies
private bool _isSpawning;
private bool _isPlayerInRange;
private void Awake()
{
if (_playerProvider == null || _enemyFactory == null)
{
AttributeInjector.Inject(this, Container.ProjectContainer);
}
}
// GameObjectSelfInjector существует
// private void Awake()
// {
// if (_playerProvider == null || _enemyFactory == null)
// {
// AttributeInjector.Inject(this, Container.ProjectContainer);
// }
// }
private void Update()
{
@@ -64,9 +63,14 @@ namespace Code.Gameplay.Enemies
_isSpawning = false;
}
private void OnDestroy()
{
Despawn();
}
private void Despawn()
{
if (_spawnedEnemy == null) return;
if (!_spawnedEnemy) return;
_enemyFactory.ReleaseEnemy(_spawnedEnemy);
_spawnedEnemy = null;