added temp scene and wave based enemy
This commit is contained in:
@@ -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