private void Start()
        {
            if (!WaveCreated)
            {
                Debug.Log("Waves have not been created", this);
                return;
            }
            foreach (Wave wave in EnemyWaves)
            {
                var    settings      = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);
                var    entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
                Entity entity        = entityManager.CreateEntity();
                var    setup         = new WaveComponent()
                {
                    Level          = EnemyWaves.IndexOf(wave),
                    RewardEXP      = wave.RewardEXP,
                    RewardGold     = wave.RewardGold,
                    RewardSpawnID  = wave.RewardSpawnID,
                    MaxEnemyAtOnce = wave.MaxEnemyAtOnce
                };
                entityManager.AddComponentData(entity, setup);

                DynamicBuffer <WaveBufferComponent> buffer = entityManager.AddBuffer <WaveBufferComponent>(entity);
                foreach (EnemyWaveSpec Enemy in wave.EnemiesForWave)
                {
                    buffer.Add(new WaveBufferComponent()
                    {
                        EnemySpecForWave = Enemy
                    });
                }
            }
        }
        protected override void OnUpdate()
        {
            Entities.ForEach((Entity entity, ref WaveComponent wave) =>
            {
                if (!CurWave(wave))
                {
                    return;
                }
                if (Control == null)
                {
                    Control = SpawnController.Instance;
                }
                if (Control.MaxCountInScene != wave.MaxEnemyAtOnce)
                {
                    Control.MaxCountInScene = wave.MaxEnemyAtOnce;
                }

                if (!wave.AllEnemiesDispatched)
                {
                    DynamicBuffer <WaveBufferComponent> WaveBuffer = EntityManager.GetBuffer <WaveBufferComponent>(entity);
                    foreach (WaveBufferComponent waveEnemy in WaveBuffer)
                    {
                        int count = waveEnemy.EnemySpecForWave.SpawnCount;
                        while (count != 0)
                        {
                            NativeArray <int> dispatched = new NativeArray <int>(1, Allocator.TempJob);


                            var testing = new DispatchSpawnsToSpawnPointsEnemy()
                            {
                                SpawnCount       = count,
                                SpawnID          = waveEnemy.EnemySpecForWave.spawnID,
                                count            = dispatched,
                                chunkEnemyBuffer = GetArchetypeChunkBufferType <EnemySpawnData>(),
                                C1 = GetArchetypeChunkComponentType <EnemySpawnTag>()
                            };

                            JobHandle handle = testing.Schedule(m_Group);
                            handle.Complete();

                            count -= testing.count[0];
                            wave.EnemiesDispatched += dispatched[0];
                            dispatched.Dispose();
                        }
                    }
                    wave.AllEnemiesDispatched = true;
                }
                WaveComponent currentwave = wave;
                Entities.ForEach((ref Destroytag tag, ref EnemyTag Enemy) => {
                    currentwave.EnemiesDefeated++;
                });
                wave = currentwave;
                if (WaveDefeat(wave))
                {
                    PostUpdateCommands.DestroyEntity(entity);
                    wavecnt++;
                }
            });
        }
 bool WaveDefeat(WaveComponent wave)
 {
     if (wave.EnemiesDispatched > 0)
     {
         return(wave.EnemiesDefeated == wave.EnemiesDispatched);
     }
     else
     {
         return(false);
     }
 }
 bool CurWave(WaveComponent wave)
 {
     return(wave.Level == wavecnt);
 }