Esempio n. 1
0
        IEnumerator SpawnSubWave(SubWave subWave, Wave parentWave)
        {
            if (subWave.unit == null)
            {
                Debug.LogWarning("No creep prefab has been assigned to sub-wave", this);
                yield break;
            }

            yield return(new WaitForSeconds(subWave.delay));

            PathTD path = defaultPath;

            if (subWave.path != null)
            {
                path = subWave.path;
            }

            Vector3    pos = path.GetSpawnPoint();
            Quaternion rot = path.GetSpawnDirection();

            int spawnCount = 0;

            if (subWave.unitC == null)
            {
                subWave.unitC = subWave.unit.GetComponent <UnitCreep>();
            }

            while (spawnCount < subWave.count)
            {
                if (subWave.unit == null)
                {
                    Debug.LogWarning("no creep has been assigned to subwave", this);
                    break;
                }

                GameObject obj  = ObjectPoolManager.Spawn(subWave.unit, pos, rot);
                UnitCreep  unit = obj.GetComponent <UnitCreep>();

                if (subWave.overrideHP > 0)
                {
                    unit.defaultHP = subWave.overrideHP;
                }
                else
                {
                    unit.defaultHP = subWave.unitC.defaultHP;
                }

                if (subWave.overrideShield > 0)
                {
                    unit.defaultShield = subWave.overrideShield;
                }
                else
                {
                    unit.defaultShield = subWave.unitC.defaultShield;
                }

                if (subWave.overrideMoveSpd > 0)
                {
                    unit.moveSpeed = subWave.overrideMoveSpd;
                }
                else
                {
                    unit.moveSpeed = subWave.unitC.moveSpeed;
                }

                unit.Init(path, totalSpawnCount, parentWave.waveID);

                totalSpawnCount += 1;
                activeUnitCount += 1;

                parentWave.activeUnitCount += 1;

                spawnCount += 1;
                if (spawnCount == subWave.count)
                {
                    break;
                }

                yield return(new WaitForSeconds(subWave.interval));
            }

            parentWave.subWaveSpawnedCount += 1;
            if (parentWave.subWaveSpawnedCount == parentWave.subWaveList.Count)
            {
                parentWave.spawned = true;
                spawning           = false;
                Debug.Log("wave " + (parentWave.waveID + 1) + " has done spawning");

                yield return(new WaitForSeconds(0.5f));

                if (currentWaveID <= waveList.Count - 2 || spawnLimit == _SpawnLimit.Infinite)
                {
                    if ((spawnMode == _SpawnMode.WaveCleared || spawnMode == _SpawnMode.Continous) && allowSkip)
                    {
                        TDTK.OnEnableSpawn();
                    }
                }
            }
        }