инишиал спавнер мобов, нуждаюсь в консультации

This commit is contained in:
MrTorex committed 2025-11-26 18:23:27 +03:00
1 parent e654a0daf4
commit bd495a644f
12 files changed
+108 -1301

No files matched your search

@@ -1,8 +1,10 @@
using System.Collections.Generic;
using Code.App.StateMachine;
using Code.Audio;
using Code.Gameplay.Camera;
using Code.Gameplay.Camera.CameraStates;
using Code.Gameplay.Character.Core;
using Code.Gameplay.Enemies;
using Code.Gameplay.Player;
using Code.Input;
using Code.Scenes;
@@ -27,6 +29,7 @@ namespace Code.App.AppStates
private PlayerMoney _playerMoney;
private CharacterProvider _playerCharacter;
private List<BaseEnemy> _enemies;
public GameplayState(AppStateMachineContext context) : base(context)
{
@@ -59,6 +62,9 @@ namespace Code.App.AppStates
private async UniTask WaitForPlayerCharacterLoad() => _playerCharacter = await Context.PlayerFactory.CreatePlayer();
private async UniTask WaitForEnemyLoad(EnemyType type) =>
_enemies.Add(await Context.EnemyFactory.CreateEnemy(type));
private async UniTaskVoid WaitForSceneToLoad()
{
await UniTask.WhenAll(
@@ -1,5 +1,6 @@
using Code.Audio;
using Code.Gameplay.Camera;
using Code.Gameplay.Enemies;
using Code.Gameplay.Player;
using Code.Input;
using Code.Scenes;
@@ -19,5 +20,6 @@ namespace Code.App.StateMachine
[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; }
}
}
@@ -0,0 +1,44 @@
using System;
using Code.Configs;
using Code.Gameplay.Character.Core;
using Cysharp.Threading.Tasks;
using Reflex.Attributes;
using Reflex.Core;
using Reflex.Injectors;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace Code.Gameplay.Enemies
{
public class EnemyFactory : IEnemyFactory
{
[Inject] FogConfig _fogConfig;
[Inject] DrunkenGrandpaConfig _drunkenGrandpaConfig;
[Inject] CockroachConfig _cockroachConfig;
public async UniTask<BaseEnemy> CreateEnemy(EnemyType type)
{
var enemy = await Addressables.InstantiateAsync(GetEnemyPrefab(type)).ToUniTask();
AttributeInjector.Inject(enemy, Container.ProjectContainer);
return enemy.GetComponent<BaseEnemy>();
}
public void ReleaseEnemy(BaseEnemy enemy)
{
}
private AssetReference GetEnemyPrefab(EnemyType type)
{
return type switch
{
EnemyType.Fog => _fogConfig.fogPrefab,
EnemyType.DrunkenGrandpa => _drunkenGrandpaConfig.drunkenGrandpaPrefab,
EnemyType.Cockroach => _cockroachConfig.cockroachPrefab,
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2f9328c54d334b0c85ce44b0aa7add44
timeCreated: 1764168610
@@ -0,0 +1,9 @@
namespace Code.Gameplay.Enemies
{
public enum EnemyType
{
Fog,
DrunkenGrandpa,
Cockroach
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5430cad1a8c44516944259a428de641e
timeCreated: 1764168839
@@ -0,0 +1,10 @@
using Cysharp.Threading.Tasks;
namespace Code.Gameplay.Enemies
{
public interface IEnemyFactory
{
UniTask<BaseEnemy> CreateEnemy(EnemyType type);
void ReleaseEnemy(BaseEnemy enemy);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 68eb3027a07042b991aa1893ddd14368
timeCreated: 1764168497