Changé le nom de classe de LevelConfig vers WaveConfig afin d'éviter une confusion avec le LevelEditor
44 lines
983 B
C#
44 lines
983 B
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[CreateAssetMenu(menuName = "Gather And Defend/Levels/WaveConfig")]
|
|
public class WaveConfig : ScriptableObject
|
|
{
|
|
|
|
[SerializeField]
|
|
private List<EnemyType> _constantSpawn = new List<EnemyType>();
|
|
[SerializeField]
|
|
private float _gameDuration = 0;
|
|
public List<EnemyType> ConstantSpawn
|
|
{
|
|
get
|
|
{
|
|
return _constantSpawn;
|
|
}
|
|
}
|
|
public float GetInterval()
|
|
{
|
|
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;
|
|
}
|
|
|
|
}
|