diff --git a/Assets/Scripts/Controller/EnemySpawner.meta b/Assets/Scripts/Controller/EnemySpawner.meta new file mode 100644 index 0000000..fbae12a --- /dev/null +++ b/Assets/Scripts/Controller/EnemySpawner.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 357d89feb38affe49b5f3813d110de48 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Controller/EnemySpawner/.EnemyList.cs.un~ b/Assets/Scripts/Controller/EnemySpawner/.EnemyList.cs.un~ new file mode 100644 index 0000000..04a5e66 Binary files /dev/null and b/Assets/Scripts/Controller/EnemySpawner/.EnemyList.cs.un~ differ diff --git a/Assets/Scripts/Controller/EnemySpawner/EnemyList.cs b/Assets/Scripts/Controller/EnemySpawner/EnemyList.cs new file mode 100644 index 0000000..2890200 --- /dev/null +++ b/Assets/Scripts/Controller/EnemySpawner/EnemyList.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[CreateAssetMenu(fileName = "data", menuName = "Zhen/SpawnerList")] +public class EnemyList : ScriptableObject +{ + public EnemyPrefabInfo[] List; +} + +[Serializable] +public struct EnemyPrefabInfo +{ + public GameObject prefab; + public float Difficulty; +} \ No newline at end of file diff --git a/Assets/Scripts/Controller/EnemySpawner/EnemyList.cs.meta b/Assets/Scripts/Controller/EnemySpawner/EnemyList.cs.meta new file mode 100644 index 0000000..4db2678 --- /dev/null +++ b/Assets/Scripts/Controller/EnemySpawner/EnemyList.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: af7974227ca2b6c4eb332e658d94fc34 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Controller/EnemySpawner/EnemyList.cs~ b/Assets/Scripts/Controller/EnemySpawner/EnemyList.cs~ new file mode 100644 index 0000000..4549050 --- /dev/null +++ b/Assets/Scripts/Controller/EnemySpawner/EnemyList.cs~ @@ -0,0 +1,19 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[CreateAssetMenu(fileName = "data", menuName = "Zhen/SpawnerList", Order = 1)] +public class EnemyList : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs b/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs new file mode 100644 index 0000000..d9ff855 --- /dev/null +++ b/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Unity.VisualScripting; +using UnityEngine; + +public class NewBehaviourScript : MonoBehaviour +{ + // Shared + public int Wave = 0; + public float difficulty = 0; + + // Inspector + [SerializeField] private float difficultyIncreasePerWave = 0.1f; + [SerializeField] private float WaveTime; + [SerializeField] private EnemyList enemyList; + + // Private + private bool nextWaveRequested = false; + private float timer = 0f; + + public void StartSpawning() => StartCoroutine(SpawnLoop()); + public void StartNextWave() => nextWaveRequested = true; + + private IEnumerator SpawnLoop() + { + while (true) + { + yield return new WaitUntil(() => timer > WaveTime || nextWaveRequested); + + SpawnWave(difficulty); + + Wave++; + difficulty *= difficultyIncreasePerWave + 1; + } + + } + + void SpawnWave(float difficulty) + { + var decendingList = enemyList.List.OrderByDescending(x => x.Difficulty).ToArray(); + for (int i = 0; i < decendingList.Length; i++) + { + while (difficulty > decendingList[i].Difficulty) + { + Instantiate(decendingList[i].prefab); + difficulty -= decendingList[i].Difficulty; + } + } + } +} diff --git a/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs.meta b/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs.meta new file mode 100644 index 0000000..735e58b --- /dev/null +++ b/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8a592fac78e06964b863b67047a446a1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: