Ader Alisma 01 749d2c5643 Finished group spawn
Created Serializable class GroupList in WaveConfig.cs to contain multiple enemy types per group
2023-10-18 20:31:57 -04:00

78 lines
1.9 KiB
C#

using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class GroupList
{
public List<EnemyType> groupSpawn;
public float triggerTime;
}
[CreateAssetMenu(menuName = "Gather And Defend/Levels/WaveConfig")]
public class WaveConfig : ScriptableObject
{
[SerializeField]
private List<EnemyType> _constantSpawn = new List<EnemyType>();
[SerializeField]
private List<GroupList> _nestedGroupSpawn = new List<GroupList>();
[SerializeField]
private float _gameDuration = 1;
private float _enemySpawndOnStart = 0;
private int _enemySum = 0;
public List<EnemyType> ConstantSpawn
{
get
{
return _constantSpawn;
}
}
/**
* Contains every list of enemy groups
*/
public List<GroupList> NestedGroupSpawn
{
get
{
return _nestedGroupSpawn;
}
}
public float GetInterval()
{
float interval = _gameDuration * 60.0f / (_enemySum > 0 ? _enemySum.ToFloat() : SumCount());
return interval;
}
/**
* Returns the updated game interval after adjusting to enemies spawned at the start
*/
public float GetUpdatedInterval()
{
_enemySpawndOnStart++;
float interval = Mathf.Max(_gameDuration * 60.0f / (_enemySum - _enemySpawndOnStart).ToFloat(), 0);
return interval;
}
/**
* Returns a random enemy among the constantSpawn list
*/
public EnemyType GetRandomSpawn()
{
if (_constantSpawn.Count == 1)
{
return _constantSpawn[0];
}
return _constantSpawn[Random.Range(0, _constantSpawn.Count - 1)];
}
/**
* Returns the count of enemies to spawn
*/
private float SumCount()
{
foreach (EnemyType enemy in _constantSpawn)
{
_enemySum += enemy.Count;
}
return _enemySum.ToFloat();
}
}