示例#1
0
        /// <summary>
        /// Initializes
        /// </summary>
        /// <param name="referenceManager"> The reference manager </param>
        public void Initialize(ReferenceManager referenceManager)
        {
            if (!IsInitialized)
            {
                reference = referenceManager;

                if (bossPrefab != null)
                {
                    IsInitialized = true;
                    ObjectPoolManager opm = reference.objectPoolManager;

                    bossObject = opm.Spawn(gameObject, opm.GetTypeIdentifier(bossPrefab),
                                           bossSpawn.position, bossSpawn.rotation, transform);

                    bossScript = bossObject.GetComponent <NewBoss>();
                    TransitionState(BossStates.Intro);
                }
                else
                {
                    Debug.LogError(GetType().Name + " - bossPrefab is not set.");
                }
            }
        }
示例#2
0
        /// <summary>
        /// Runs the spawning logic for the wave.
        /// </summary>
        private IEnumerator Spawn()
        {
            for (int i = 0; i < setupSpawnGroups.Length; i++)
            {
                //if (WaveNumber == 3 && i < 2)
                //{
                //    Debug.LogWarning(GetType().Name + " - Skipping Wave " + (WaveNumber + 1) + " Spawn Group Index = " + i);
                //    continue;
                //}

                SetupNormalSpawnGroup @group = setupSpawnGroups[i];
                yield return(new WaitForSeconds(Mathf.Abs(@group.delay)));

                while (enemiesRemaining > 0)
                {
                    yield return(new WaitForSeconds(0.1f));
                }

                foreach (SetupNormalSpawnZone zone in @group.setupSpawnZones)
                {
                    Vector3 position;

                    if (zone.zone == SpawnZone.Center ||
                        zone.zone == SpawnZone.FrontLeft ||
                        zone.zone == SpawnZone.FrontRight)
                    {
                        position = waveManager.enemySpawnPoints[0].position;
                    }
                    else
                    {
                        position = waveManager.enemySpawnPoints[1].position;
                    }

                    Quaternion rotation;

                    if (reference.playerShip != null)
                    {
                        // spawn the enemy looking at the player
                        rotation =
                            Quaternion.LookRotation(
                                reference.playerShip.transform.position - position);
                    }
                    else
                    {
                        // no player in the scene, spawn looking about where they should be
                        rotation =
                            Quaternion.LookRotation(new Vector3(0.0f, 2.0f, 0.0f) - position);
                    }

                    foreach (SetupNormalSpawnPath thisPath in zone.setupSpawnPaths)
                    {
                        string pathName =
                            waveManager.PathNames[(int)zone.zone] + (int)thisPath.path;

                        GameObject spawned =
                            objectPoolManager.Spawn(
                                gameObject, (short)waveManager.EnemyIDs[(int)thisPath.enemy],
                                position,
                                rotation);

                        Enemy spawnedEnemyScript = spawned.GetComponent <Enemy>();
                        spawnedEnemyScript.SetPath(pathName);
                        spawnedEnemyScript.SetWave(WaveNumber);
                        spawnedEnemyScript.SetAttackPattern(thisPath.attackPattern);

                        Hashtable moveHash = new Hashtable
                        {
                            { "easetype", iTween.EaseType.easeInOutSine },
                            { "time", 3.0f },
                            { "looktarget", reference.shipLookTarget.transform },
                            { "onComplete", "OnPathingComplete" },
                            { "onCompleteTarget", spawned },
                            { "path", iTweenPath.GetPath(pathName) }
                        };

                        iTween.MoveTo(spawned, moveHash);
                        ++enemiesRemaining;

                        if (spawned.name.Contains("Enemy_Splitter"))
                        {
                            // accounting for splitter children that the splitter spawns
                            enemiesRemaining += 4;
                        }
                    }
                }

                if (@group.powerupSpawn.powerupSpawn != PowerupSpawnPoint.NoPowerup)
                {
                    Vector3 spawnPoint = waveManager
                                         .powerupSpawnPoints[(int)@group.powerupSpawn.powerupSpawn - 1].position;

                    Instantiate(waveManager.powerupPrefabs[(int)@group.powerupSpawn.powerup],
                                spawnPoint, Quaternion.identity);

                    if (!waveManager.spawnedPowerupOnce)
                    {
                        waveManager.spawnedPowerupOnce = true;
                        reference.tooltips.SpawnGrabPowerup(
                            (int)@group.powerupSpawn.powerupSpawn - 1);
                    }
                }
            }

            StartCoroutine(WaitForWaveEnd());
        }
示例#3
0
        /// <summary>
        /// Runs the spawning logic for the subwave.
        /// </summary>
        private IEnumerator SpawnSubwave()
        {
            for (int group = 0; group < spawnGroups.Count; ++group)
            {
                if (spawnGroups[group].powerupSpawns.Count > 0)
                {
                    // stop the powerup coroutine if the previous ran over.
                    if (powerupCoroutine != null)
                    {
                        StopCoroutine(powerupCoroutine);
                    }

                    powerupCoroutine =
                        StartCoroutine(PowerupSpawn(spawnGroups[group].powerupSpawns));
                }

                if (Math.Abs(spawnGroups[group].spawnGroupDelay) > 0.001f)
                {
                    // wait the group delay time
                    yield return(new WaitForSeconds(spawnGroups[group].spawnGroupDelay));
                }

                // spawn all enemies in the spawn group
                for (int i = 0; i < spawnGroups[group].enemySpawns.Count; ++i)
                {
                    respawnDelay = spawnGroups[group].spawnDelay;

                    // wait until we can spawn a new enemy
                    while (!canSpawn)
                    {
                        yield return(new WaitForSeconds(0.1f));
                    }

                    if (Math.Abs(spawnGroups[group].spawnDelay) > 0.001f)
                    {
                        // wait the delay time
                        yield return(new WaitForSeconds(spawnGroups[group].spawnDelay));
                    }
                    else
                    {
                        // wait until the next frame
                        yield return(null);
                    }

                    Vector3   position;
                    SpawnZone zone = spawnGroups[group].enemySpawns[i].spawnZone;
                    //if (zone != SpawnZone.Introduction)
                    //{
                    //    // spawn position is random point in its zone
                    //    Vector3 lower = spawnZones[(int) zone].lowerBound.transform.position;
                    //    Vector3 upper = spawnZones[(int) zone].upperBound.transform.position;

                    //    float radius;
                    //    bool isColliding;

                    //    // set the collision radius for the enemy we're about to spawn
                    //    switch (spawnGroups[group].enemySpawns[i].typeIdentifier)
                    //    {
                    //        case 0:
                    //            radius = 0.4f;
                    //            break;
                    //        case 1:
                    //            radius = 0.4f;
                    //            break;
                    //        case 2:
                    //            radius = 0.24f;
                    //            break;
                    //        case 3:
                    //            radius = 0.9f;
                    //            break;
                    //        default:
                    //            radius = 0.4f;
                    //            break;
                    //    }

                    //    do
                    //    {
                    //        // find a position that isn't colliding with any enemies
                    //        position = new Vector3(UnityEngine.Random.Range(lower.x, upper.x),
                    //                               UnityEngine.Random.Range(lower.y, upper.y),
                    //                               UnityEngine.Random.Range(lower.z, upper.z));

                    //        Collider[] colliders =
                    //            Physics.OverlapSphere(position, radius, Utility.enemyMask);

                    //        isColliding = colliders.Length > 0;

                    //        // wait one frame to throttle this do-while
                    //        yield return null;
                    //    }
                    //    while (isColliding);
                    //}
                    //else
                    //{
                    // spawn position is the introduction point
                    position = spawnZones[0].lowerBound.transform.position;
                    //}

                    int typeIdentifier = spawnGroups[group].enemySpawns[i].typeIdentifier;

                    // wait until we can spawn a new enemy
                    while (!canSpawn)
                    {
                        yield return(new WaitForSeconds(0.1f));
                    }

                    Quaternion rotation;

                    if (reference.playerShip)
                    {
                        // spawn the enemy looking at the player
                        rotation =
                            Quaternion.LookRotation(
                                reference.playerShip.transform.position - position);
                    }
                    else
                    {
                        // no player in the scene, spawn looking about where they should be
                        rotation =
                            Quaternion.LookRotation(new Vector3(0.0f, 2.0f, 0.0f) - position);
                    }

                    GameObject spawned =
                        objectPoolManager.Spawn(gameObject, (short)typeIdentifier, position, rotation);

                    // initialize enemy subwave reference, EnemySpawn
                    // for respawning, and attack pattern.
                    Enemy spawnedEnemyScript = spawned.GetComponent <Enemy>();
                    //spawnedEnemyScript.SetSubwave(this);
                    //spawnedEnemyScript.SetEnemySpawn(spawnGroups[group].enemySpawns[i]);
                    spawnedEnemyScript.SetAttackPattern(
                        spawnGroups[group].enemySpawns[i].attackPattern);

                    --enemyCapCount;

                    if (enemyCapCount <= 0)
                    {
                        canSpawn = false;
                    }

                    ++enemiesRemaining;

                    if (spawned.name.Contains("Enemy_Splitter"))
                    {
                        // accounting for splitter children that the splitter spawns
                        enemiesRemaining += 4;
                    }

                    --enemiesToSpawn;
                }
            }

            if (enemiesToSpawn > 0)
            {
                Debug.LogWarning(GetType().Name + " #" + SubwaveNumber +
                                 " - enemiesToSpawn = " + enemiesToSpawn);
            }

            StartCoroutine(WaitForSubwaveEnd());
        }