From 32e28f156e4f269128369c7712e4368d8bedc3ee Mon Sep 17 00:00:00 2001 From: BOTAlex Date: Sat, 3 Feb 2024 04:05:06 +0100 Subject: [PATCH] Added wave spawner --- Assets/Scripts/Controller/EnemySpawner.meta | 8 +++ .../Controller/EnemySpawner/.EnemyList.cs.un~ | Bin 0 -> 5343 bytes .../Controller/EnemySpawner/EnemyList.cs | 17 ++++++ .../Controller/EnemySpawner/EnemyList.cs.meta | 11 ++++ .../Controller/EnemySpawner/EnemyList.cs~ | 19 +++++++ .../Controller/EnemySpawner/EnemySpawner.cs | 52 ++++++++++++++++++ .../EnemySpawner/EnemySpawner.cs.meta | 11 ++++ 7 files changed, 118 insertions(+) create mode 100644 Assets/Scripts/Controller/EnemySpawner.meta create mode 100644 Assets/Scripts/Controller/EnemySpawner/.EnemyList.cs.un~ create mode 100644 Assets/Scripts/Controller/EnemySpawner/EnemyList.cs create mode 100644 Assets/Scripts/Controller/EnemySpawner/EnemyList.cs.meta create mode 100644 Assets/Scripts/Controller/EnemySpawner/EnemyList.cs~ create mode 100644 Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs create mode 100644 Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs.meta 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 0000000000000000000000000000000000000000..04a5e661e14fc4a9846e32b192c80f9715be78e5 GIT binary patch literal 5343 zcmeI0&npE{6vyxLn~fr&EGF_RN)~UUD8CkpXCV|xgDaEw=DlX-k+Put5A4`jAUl@+ z2Nw29B71Aj_r7;(dg?U~ccXjiHuucCGw;m#eD6JXX2D6F&bt%o7g6@O*!*_?P~Uvi zH~xNbaea06c6`2l(z91teY=18^gJbmXr$Ja$*v`xb!$Co`@S{l%GBPp;|JD|HIsJJ zV{*&hanf0jMpjXSl~Joxz1$If<;%OX+lm-@F|m4|A5gB`oP!JbCgPKf1{%|r0m9Lw za0v0yLjO`ht(qFB14Uwa+>>@7M}1!gGt$lWY&uDquv5|+w%RxBz;5riQgohAEp176 zU@l|ty3&J2=;v8)LwYoPuy=*-*cnMmDws+d&cQ$h5oH)ZRLVm5cpNsU%qWYqq5Vk8 zYWt_kf|8(3HmD4K0w>Ixg)HbaQdUQyvM{mrty!flJiLZ-4j>I956*`6Bgtc=P#&lv z4b)IYg1;?k(Y8kUngkitP~$p;xVUdt4oZezBWX;Ar2!m2*kGv539#|CB99k-ZRimg zHMSxKZzwT(x`a1T3~zU)q{#|;{0@VFK^D}z;FvOxEa)_%c~FdIX+=3aEfF=q0%j{5 z0~1-$X$12|!HnhJGYePV&PX#eR7E*huApG4%&_E4=sFV1(P9%b+8chJWjIKbN$k)J g%Wzh-_T}B_^Y2-H`*Z|~{@?DiBYifCAHH6G0Xeb6djJ3c literal 0 HcmV?d00001 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: