WaveObserver donne aux spawners les unités à instancier ainsi que l'intervalle de création de ceux-ci LevelConfig passe de Level vers LevelManager puis il est utilisé dans l'instance de WaveObserver
47 lines
1.0 KiB
C#
47 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[CreateAssetMenu(menuName = "Gather And Defend/Levels/LevelConfig")]
|
|
public class LevelConfig : ScriptableObject
|
|
{
|
|
[SerializeField]
|
|
private List<EnemyType> _constantSpawn = new List<EnemyType>();
|
|
[SerializeField]
|
|
private float _gameDuration = 0;
|
|
public List<EnemyType> ConstantSpawn
|
|
{
|
|
get
|
|
{
|
|
return _constantSpawn;
|
|
}
|
|
}
|
|
public float GameDuration
|
|
{
|
|
get
|
|
{
|
|
float interval = SumCount().ToFloat() / _gameDuration * 0.01f;
|
|
return interval;
|
|
}
|
|
}
|
|
public EnemyType GetRandomSpawn()
|
|
{
|
|
if (_constantSpawn.Count == 1)
|
|
{
|
|
return _constantSpawn[0];
|
|
}
|
|
return _constantSpawn[Random.Range(0, _constantSpawn.Count - 1)];
|
|
}
|
|
|
|
private int SumCount()
|
|
{
|
|
int sum = 0;
|
|
foreach (EnemyType enemy in _constantSpawn)
|
|
{
|
|
sum += enemy.Count;
|
|
}
|
|
return sum;
|
|
}
|
|
|
|
}
|