added temp scene and wave based enemy
This commit is contained in:
@@ -15,12 +15,13 @@ namespace Darkmatter.App
|
||||
[SerializeField] private PlayerMotor playerMotor;
|
||||
[SerializeField] private PlayerAnimController playerAnim;
|
||||
[SerializeField] private PlayerConfigSO playerConfig;
|
||||
[SerializeField] private EnemyConfigSO enemyConfig;
|
||||
[SerializeField] private CameraConfigSO cameraConfig;
|
||||
[SerializeField] private CameraService camService;
|
||||
[SerializeField] private GunWeapon gunWeapon;
|
||||
[SerializeField] private PlayerAimTargetProvider TargetProvider;
|
||||
|
||||
[SerializeField] private AudioService audioService;
|
||||
|
||||
|
||||
[Header("Factory parameters")]
|
||||
[SerializeField] private Transform playerTransform;
|
||||
@@ -29,8 +30,6 @@ namespace Darkmatter.App
|
||||
[SerializeField] private List<Transform> patrolPoints;
|
||||
|
||||
[SerializeField] private EnemiesSpawnner spawnner;
|
||||
|
||||
private readonly IObjectResolver resolver;
|
||||
protected override void Configure(IContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterEntryPoint<PlayerController>(Lifetime.Scoped);
|
||||
@@ -42,25 +41,24 @@ namespace Darkmatter.App
|
||||
|
||||
builder.RegisterComponent(playerConfig);
|
||||
builder.RegisterComponent(cameraConfig);
|
||||
builder.RegisterComponent(enemyConfig);
|
||||
|
||||
builder.RegisterComponent<ICameraService>(camService);
|
||||
builder.RegisterComponent<IReloadableWeapon>(gunWeapon);
|
||||
builder.RegisterComponent(spawnner);
|
||||
|
||||
builder.RegisterComponent<IAudioService>(audioService);
|
||||
|
||||
builder.Register<PlayerStateMachine>(Lifetime.Scoped);
|
||||
builder.Register<EnemyStateMachine>(Lifetime.Scoped);
|
||||
|
||||
|
||||
builder.Register<IEnemyFactory>(c =>
|
||||
new EnemyFactory(
|
||||
playerTransform,
|
||||
patrolPoints,
|
||||
fatZombie,
|
||||
SlimZombie,
|
||||
c.Resolve<IObjectResolver>(),
|
||||
enemyConfig), // <-- inject resolver properly
|
||||
Lifetime.Scoped);
|
||||
new EnemyFactory(
|
||||
playerTransform,
|
||||
patrolPoints,
|
||||
fatZombie,
|
||||
SlimZombie,
|
||||
c.Resolve<IObjectResolver>()), // <-- inject resolver properly
|
||||
Lifetime.Scoped);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
8
Assets/Darkmatter/Code/Core/Audio.meta
Normal file
8
Assets/Darkmatter/Code/Core/Audio.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75b5cdb2a0393e9468f0df134cd18157
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -10,11 +10,12 @@ namespace Darkmatter.Core
|
||||
|
||||
GameObject GameObject { get; }
|
||||
void InitializeFromFactory(Transform player,List<Transform> patrolPoints);
|
||||
bool isDead { get; }
|
||||
bool isDead { get; set; }
|
||||
NavMeshAgent EnemyAI { get; }
|
||||
List<Transform> PatrolPoints { get; }
|
||||
void SetDestination(Vector3 destination);
|
||||
Vector3 ReturnMyPos();
|
||||
Transform PlayerTarget { get; }
|
||||
void Reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Core
|
||||
{
|
||||
public interface IAudioService
|
||||
{
|
||||
void PlayMusic(AudioId id);
|
||||
void StopMusic();
|
||||
|
||||
void PlaySFX(AudioId id,float volume);
|
||||
void PlaySFXAt(AudioId id, UnityEngine.Vector3 position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad5ce615be52e274db215ee4a11cf0e4
|
||||
@@ -14,5 +14,5 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier: CoreAssembly::Darkmatter.Core.EnemyConfigSO
|
||||
walkSpeed: 1
|
||||
chaseSpeed: 2
|
||||
visionRange: 15
|
||||
visionRange: 50
|
||||
attackRange: 2
|
||||
|
||||
@@ -7,4 +7,18 @@ namespace Darkmatter.Core
|
||||
Fat,
|
||||
slim
|
||||
}
|
||||
|
||||
public enum AudioId
|
||||
{
|
||||
Music_Gameplay,
|
||||
Music_Menu,
|
||||
|
||||
Gun_Fire,
|
||||
Gun_Reload,
|
||||
|
||||
Zombie_Growl,
|
||||
Zombie_Death,
|
||||
|
||||
UI_Click
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@ namespace Darkmatter.Domain
|
||||
public override void Enter()
|
||||
{
|
||||
base.Enter();
|
||||
Debug.Log("Entered Attack State");
|
||||
Debug.Log("Attacking Player");
|
||||
enemyAnimController.PlayAttackAnim(true);
|
||||
enemyPawn.OnHealthDecreased += HandleHealth;
|
||||
}
|
||||
@@ -52,7 +50,6 @@ namespace Darkmatter.Domain
|
||||
public override void Exit()
|
||||
{
|
||||
base.Exit();
|
||||
Debug.Log("Exiting Attack State");
|
||||
enemyAnimController.PlayAttackAnim(false);
|
||||
enemyPawn.OnHealthDecreased -= HandleHealth;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace Darkmatter.Domain
|
||||
public override void Enter()
|
||||
{
|
||||
base.Enter();
|
||||
Debug.Log("Entered Chase State");
|
||||
runner.SetSpeed(enemyConfig.chaseSpeed);
|
||||
enemyAnimController.PlayeChaseAnim(true);
|
||||
enemyPawn.OnHealthDecreased += HandleHealth;
|
||||
runner.audioService.PlaySFXAt(AudioId.Zombie_Growl, enemyPawn.ReturnMyPos());
|
||||
}
|
||||
|
||||
private void HandleHealth(float health)
|
||||
@@ -34,7 +34,6 @@ namespace Darkmatter.Domain
|
||||
base.Update();
|
||||
HandleChase();
|
||||
CheckForStateBreak();
|
||||
Debug.Log("Updated Chase State");
|
||||
}
|
||||
|
||||
private void CheckForStateBreak()
|
||||
@@ -57,7 +56,6 @@ namespace Darkmatter.Domain
|
||||
public override void Exit()
|
||||
{
|
||||
base.Exit();
|
||||
Debug.Log("Exiting Chase State");
|
||||
enemyAnimController.PlayeChaseAnim(false);
|
||||
enemyPawn.OnHealthDecreased -= HandleHealth;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Darkmatter.Core;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
using VContainer.Unity;
|
||||
@@ -6,15 +7,20 @@ namespace Darkmatter.Domain
|
||||
{
|
||||
public class EnemyController : MonoBehaviour
|
||||
{
|
||||
EnemyStateMachine esm;
|
||||
EnemyStateMachine esm;
|
||||
IEnemyAnimController animController;
|
||||
IEnemyPawn enemy;
|
||||
[SerializeField] public EnemyConfigSO enemyConfig;
|
||||
[Inject] IAudioService audioService;
|
||||
|
||||
public void Initialize(EnemyStateMachine esm)
|
||||
private void Awake()
|
||||
{
|
||||
this.esm = esm;
|
||||
animController = this.GetComponent<IEnemyAnimController>();
|
||||
enemy = this.GetComponent<IEnemyPawn>();
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
esm = new EnemyStateMachine(enemy,animController,audioService, enemyConfig);
|
||||
esm.ChangeState(new PatrolState(esm));
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,13 @@ namespace Darkmatter.Domain
|
||||
public readonly IEnemyPawn enemyPawn;
|
||||
public readonly IEnemyAnimController enemyAnimController;
|
||||
public readonly EnemyConfigSO enemyConfig;
|
||||
public readonly IAudioService audioService;
|
||||
|
||||
public EnemyStateMachine(IEnemyPawn pawn, IEnemyAnimController animController,EnemyConfigSO enemyConfig)
|
||||
public EnemyStateMachine(IEnemyPawn pawn, IEnemyAnimController animController, IAudioService audioService, EnemyConfigSO enemyConfig)
|
||||
{
|
||||
enemyPawn = pawn;
|
||||
enemyAnimController = animController;
|
||||
this.audioService = audioService;
|
||||
this.enemyConfig = enemyConfig;
|
||||
}
|
||||
|
||||
@@ -44,6 +46,7 @@ namespace Darkmatter.Domain
|
||||
public void Die()
|
||||
{
|
||||
enemyAnimController.PlayDeadAnim();
|
||||
audioService.PlaySFXAt(AudioId.Zombie_Death,enemyPawn.ReturnMyPos());
|
||||
enemyPawn.Die();
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ namespace Darkmatter.Domain
|
||||
{
|
||||
if (enemyPawn.isDead) return;
|
||||
base.Update();
|
||||
Debug.Log("Update in Patrol State");
|
||||
HandlePatrol();
|
||||
CheckForStateBreak();
|
||||
}
|
||||
@@ -56,7 +55,6 @@ namespace Darkmatter.Domain
|
||||
|
||||
if(Vector3.Distance(target.position,enemyPawn.ReturnMyPos()) < 0.5f) //close enought to targetPatrolPoint
|
||||
{
|
||||
Debug.Log("Reached Point");
|
||||
currentPatrolPointIndex = (currentPatrolPointIndex+1)%enemyPawn.PatrolPoints.Count;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +63,6 @@ namespace Darkmatter.Domain
|
||||
{
|
||||
base.Exit();
|
||||
enemyAnimController.PlayWalkAnim(false);
|
||||
Debug.Log("Exiting Patrol State");
|
||||
enemyPawn.OnHealthDecreased -= HandleHealth;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,15 +14,14 @@ namespace Darkmatter.Domain
|
||||
private readonly GameObject fatZombiePrefab;
|
||||
private readonly GameObject slimZombiePrefab;
|
||||
private readonly IObjectResolver objectResolver;
|
||||
private readonly EnemyConfigSO enemyConfig;
|
||||
public EnemyFactory(Transform playerTransform, List<Transform> patrolPoints, GameObject fatZombiePrefab, GameObject slimZombiePrefab, IObjectResolver resolver , EnemyConfigSO enemyConfig)
|
||||
|
||||
public EnemyFactory(Transform playerTransform, List<Transform> patrolPoints, GameObject fatZombiePrefab, GameObject slimZombiePrefab,IObjectResolver resolver)
|
||||
{
|
||||
this.playerTransform = playerTransform;
|
||||
this.patrolPoints = patrolPoints;
|
||||
this.fatZombiePrefab = fatZombiePrefab;
|
||||
this.slimZombiePrefab = slimZombiePrefab;
|
||||
this.objectResolver = resolver;
|
||||
this.enemyConfig = enemyConfig;
|
||||
}
|
||||
public IEnemyPawn GetEnemy(ZombieType type)
|
||||
{
|
||||
@@ -44,16 +43,7 @@ namespace Darkmatter.Domain
|
||||
objectResolver.InjectGameObject(enemyObj);
|
||||
|
||||
IEnemyPawn enemyPawn = enemyObj.GetComponent<IEnemyPawn>();
|
||||
IEnemyAnimController animController = enemyObj.GetComponent<IEnemyAnimController>();
|
||||
|
||||
EnemyStateMachine esm = new EnemyStateMachine(enemyPawn, animController,enemyConfig);
|
||||
|
||||
EnemyController controller = enemyObj.GetComponent<EnemyController>();
|
||||
controller.Initialize(esm);
|
||||
|
||||
enemyPawn.InitializeFromFactory(playerTransform, GetRandomPatrolPoints(Random.Range(4, patrolPoints.Count)));
|
||||
|
||||
|
||||
return enemyPawn;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Darkmatter.Domain
|
||||
[Inject] public readonly IReloadableWeapon currentWeapon;
|
||||
[Inject] public readonly PlayerConfigSO playerConfig;
|
||||
[Inject] public readonly CameraConfigSO cameraConfig;
|
||||
[Inject] public readonly IAudioService audioService;
|
||||
|
||||
private Vector3 moveDir;
|
||||
private float Yaw;
|
||||
@@ -56,18 +57,21 @@ namespace Darkmatter.Domain
|
||||
if (!isShooting) return;
|
||||
if(currentWeapon.canAttack)
|
||||
{
|
||||
audioService.PlaySFX(AudioId.Gun_Fire,0.1f);
|
||||
currentWeapon.Attack();
|
||||
}
|
||||
if (currentWeapon.AmmoCount == 0)
|
||||
if (currentWeapon.AmmoCount == 0 && !currentWeapon.isReloading)
|
||||
{
|
||||
audioService.PlaySFX(AudioId.Gun_Reload, 0.1f);
|
||||
playerAnim.PlayReloadAnim(currentWeapon);
|
||||
}
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
if(currentWeapon.AmmoCount<currentWeapon.initialAmmoCount)
|
||||
if(currentWeapon.AmmoCount<currentWeapon.initialAmmoCount && !currentWeapon.isReloading)
|
||||
{
|
||||
audioService.PlaySFX(AudioId.Gun_Reload, 0.1f);
|
||||
playerAnim.PlayReloadAnim(currentWeapon);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,15 @@ namespace Darkmatter.Presentation
|
||||
|
||||
public void PlayDeadAnim()
|
||||
{
|
||||
resetValues();
|
||||
animator.SetTrigger(deadHash);
|
||||
}
|
||||
|
||||
public void resetValues()
|
||||
{
|
||||
animator.SetBool("walk", false);
|
||||
animator.SetBool("chase", false);
|
||||
animator.SetBool("attack", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
Assets/Darkmatter/Code/Presentation/Audio.meta
Normal file
8
Assets/Darkmatter/Code/Presentation/Audio.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34c3dab5409b0d74783cac7f227e35ad
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
65
Assets/Darkmatter/Code/Presentation/Audio/AudioService.cs
Normal file
65
Assets/Darkmatter/Code/Presentation/Audio/AudioService.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Darkmatter.Core;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
|
||||
[System.Serializable]
|
||||
public struct AudioEntry
|
||||
{
|
||||
public AudioId id;
|
||||
public AudioClip clip;
|
||||
}
|
||||
public class AudioService : MonoBehaviour, IAudioService
|
||||
{
|
||||
[Header("Audio Sources")]
|
||||
[SerializeField] private AudioSource musicSource;
|
||||
[SerializeField] private AudioSource sfxSource;
|
||||
|
||||
[Header("Audio Clips")]
|
||||
[SerializeField] private AudioEntry[] clips;
|
||||
|
||||
private Dictionary<AudioId, AudioClip> _clipMap;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_clipMap = new Dictionary<AudioId, AudioClip>();
|
||||
|
||||
foreach (var entry in clips)
|
||||
{
|
||||
if (!_clipMap.ContainsKey(entry.id))
|
||||
_clipMap.Add(entry.id, entry.clip);
|
||||
}
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
PlayMusic(AudioId.Music_Gameplay);
|
||||
}
|
||||
|
||||
public void PlayMusic(AudioId id)
|
||||
{
|
||||
if (!_clipMap.TryGetValue(id, out var clip)) return;
|
||||
|
||||
musicSource.clip = clip;
|
||||
musicSource.loop = true;
|
||||
musicSource.Play();
|
||||
}
|
||||
|
||||
public void StopMusic()
|
||||
{
|
||||
musicSource.Stop();
|
||||
}
|
||||
|
||||
public void PlaySFX(AudioId id,float volume)
|
||||
{
|
||||
if (!_clipMap.TryGetValue(id, out var clip)) return;
|
||||
sfxSource.PlayOneShot(clip,volume);
|
||||
}
|
||||
|
||||
public void PlaySFXAt(AudioId id, Vector3 position)
|
||||
{
|
||||
if (!_clipMap.TryGetValue(id, out var clip)) return;
|
||||
AudioSource.PlayClipAtPoint(clip, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1cf6936af3bcb942b8d98990ed4f7ae
|
||||
@@ -8,9 +8,12 @@ namespace Darkmatter.Presentation
|
||||
public class EnemiesSpawnner : MonoBehaviour
|
||||
{
|
||||
[Inject] IEnemyFactory _enemyFactory;
|
||||
public int enemiesPerWave = 5;
|
||||
public int baseEnemyCount =2;
|
||||
private ObjectPool<IEnemyPawn> _enemyPool;
|
||||
|
||||
private int killedEnemies = 0;
|
||||
private int enemiesMultiplier = 1;
|
||||
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
@@ -41,21 +44,30 @@ namespace Darkmatter.Presentation
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SpawnWave();
|
||||
SpawnWave(enemiesMultiplier);
|
||||
}
|
||||
|
||||
private void SpawnWave()
|
||||
private void SpawnWave(int multiplier)
|
||||
{
|
||||
for (int i = 0; i < enemiesPerWave; i++)
|
||||
for (int i = 0; i < baseEnemyCount*multiplier; i++)
|
||||
{
|
||||
IEnemyPawn enemy = _enemyPool.Get();
|
||||
enemy.GameObject.transform.position = enemy.PatrolPoints[Random.Range(0, enemy.PatrolPoints.Count)].position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ReturnEnemy(IEnemyPawn enemy)
|
||||
{
|
||||
enemy.Reset();
|
||||
_enemyPool.Release(enemy);
|
||||
killedEnemies++;
|
||||
if(killedEnemies == baseEnemyCount*enemiesMultiplier)
|
||||
{
|
||||
killedEnemies = 0;
|
||||
enemiesMultiplier++;
|
||||
SpawnWave(enemiesMultiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,5 +58,12 @@ namespace Darkmatter.Presentation
|
||||
this.PlayerTarget = player;
|
||||
this.PatrolPoints = patrolPoints;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Health = 100;
|
||||
enemyAI.enabled = true;
|
||||
isDead = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user