예제 #1
0
        /// <summary>
        /// Stop spawning enemies immediatley (The current wave will be abandoned and the next call to startWave will advance to the next wave)
        /// </summary>
        public override void stopSpawning()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Stop spawning
            StopCoroutine(waveRountine());
        }
예제 #2
0
        /// <summary>
        /// Begin spawning enemies using the wave settings (Called automatically if playOnStart is true)
        /// </summary>
        public override void startSpawning()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Run the coroutine
            StartCoroutine(waveRountine());
        }
예제 #3
0
        // Methods
        /// <summary>
        /// Called by unity on startup.
        /// </summary>
        protected override void Start()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Find all spawn points
            findSpawns();

            base.Start();
        }
예제 #4
0
        // Methods
        private void Start()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Launch spawn routine immediatley
            if (playOnStart == true)
            {
                startSpawning();
            }
        }
예제 #5
0
        public void spawnableDestroyed(GameObject instance)
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Make sure we are destroying an enemy
            if (enemyList.Contains(instance) == true)
            {
                // Remove from the list
                enemyList.Remove(instance);
            }
        }
예제 #6
0
        /// <summary>
        /// Selects an appropraite enemyinfo from the collection based on the current settings.
        /// </summary>
        /// <returns>An appropriate enemyinfo</returns>
        public virtual SpawnableInfo selectEnemy()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Check for empty enemies
            if (enemies.Length == 0)
            {
                Debug.LogError("Failed to spawn an enemy because the enemy manager does not contain any enemies");
                return(null);
            }

            float accumulator = 0;

            // FInd the total spawn chance value
            foreach (SpawnableInfo info in enemies)
            {
                accumulator += info.spawnChance;
            }

            // Select a random value
            float value = Random.Range(0, accumulator);

            // Reset the accumulator
            accumulator = 0;

            // Find the selected enemy
            foreach (SpawnableInfo info in enemies)
            {
                // Add to the accumulator
                accumulator += info.spawnChance;

                // Check if we have found the best match
                if (value < accumulator)
                {
                    return(info);
                }
            }

            // Default index
            return(enemies[0]);
        }
예제 #7
0
        /// <summary>
        /// Resets the wave manager to the first round without starting spwning.
        /// </summary>
        public void reset(bool keepState = false)
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Reset values
            activeWave   = null;
            currentIndex = 0;

            // Should we keep the wave state
            if (keepState == false)
            {
                currentWave  = 0;
                spawnedCount = 0;
            }
        }
예제 #8
0
        /// <summary>
        /// Returns an instance of the spawn info class representing a free spawn point at the time of calling this method.
        /// This can be used to access the location and rotation of the spawn point for manual spawning.
        /// </summary>
        /// <returns>An instance of the spawn info class representing a specific spawn location</returns>
        public override SpawnInfo getSpawnInfo()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Select a spawn using the spawn mode
            ISpawn spawn = this.selectSpawn(spawnMode);

            // Check for null
            if (spawn == null)
            {
                return(null);
            }

            // Get the spawn info
            return(spawn.getSpawnInfo());
        }
예제 #9
0
        /// <summary>
        /// Get the spawn info for this spawn point.
        /// </summary>
        /// <returns>An instance of the spawn info class representing this spawn points location and orientation</returns>
        public override SpawnInfo getSpawnInfo()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Check for cached info
            if (cachedInfo != null)
            {
                return(cachedInfo);
            }

            // Create a new spawn info
            cachedInfo = new SpawnInfo(this, transform);

            // Get the info
            return(cachedInfo);
        }
예제 #10
0
        // Methods
        /// <summary>
        /// Attempt to spawn an item using the current settings.
        /// </summary>
        /// <returns>The transform of the spawned item</returns>
        public override Transform spawn()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Make sure we can spawn
            if (IsSpawnFree == false)
            {
                // Spawn failed
                invokeSpawnFailedEvent();
                return(null);
            }

            // Create the spawner object
            Transform instance = this.createSpawnableInstance();

            // Check for error
            if (instance == null)
            {
                // Spawn failed
                invokeSpawnFailedEvent();
                return(null);
            }

            // Get the spawn info
            SpawnInfo info = getSpawnInfo();

            // Spawn the item
            info.spawnObjectAt(instance);

            // Success
            invokeSpawnedEvent(instance);

            return(instance);
        }
예제 #11
0
        // Methods
        private void Start()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            if (spawnManager == null)
            {
                Debug.LogError("Wave manager has not been setup correctly. Make sure that the spawn manager field is assigned");
                enabled = false;
                return;
            }

            // Launch wave immediatley
            if (playOnStart == true)
            {
                startSpawning();
            }
        }
예제 #12
0
        // Methods
        /// <summary>
        /// Attempts to create an instance of a spawnable object.
        /// </summary>
        /// <returns></returns>
        public override GameObject createSpawnable()
        {
            // Only allow the server to spawn
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Select the enemy type for spawning
            SpawnableInfo info = selectEnemy();

            // Check for error
            if (info == null)
            {
                return(null);
            }

            // Spawn the enemy
#if ULTIMATE_SPAWNER_POOLED == true
            // Reuse a pooled instance from the pool
            GameObject instance = UltimatePool.spawn(info.prefab);
#else
            // Create the instance
            GameObject instance = Instantiate(info.prefab);
#endif

            // Spawn the instance on remote clients
#if ULTIMATE_SPAWNER_NETWORKED == true
            // Spawn on server
            NetworkServer.Spawn(instance);
#endif

            // Store the enemy in a list
            enemyList.Add(instance);

            return(instance);
        }
예제 #13
0
        /// <summary>
        /// Iterates through all spawn points associated with this area and returns true if one or more of the spawn points are un-occupied and can spawn.
        /// </summary>
        /// <returns>True is there is atleast one spawn point that can spawn an object</returns>
        public override bool canSpawn()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Make sure our spawn is correctly setup
            if (this.isValidConfiguration() == false)
            {
                return(false);
            }

            // Check if the area is active
            if (collidingObjects.Count == 0 && collidingObjects2D.Count == 0)
            {
                if (alwaysActive == false)
                {
                    return(false);
                }
            }

            // Make sure there is atleat 1 free spawn
            foreach (ISpawn spawnPoint in this)
            {
                // Check if we can spawn an object at this location
                if (spawnPoint.canSpawn() == true)
                {
                    // There is a free spawn point in this area
                    return(true);
                }
            }

            // Failed to find a spawn
            return(false);
        }
예제 #14
0
        /// <summary>
        /// Returns true if the spawn manager is able to spawn an item at any location otherwise false.
        /// </summary>
        /// <returns>True if there is a spawn available</returns>
        public override bool canSpawn()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Make sure there is atleat 1 free spawn
            foreach (ISpawn spawnPoint in this)
            {
                // Check if we can spawn an object at this location
                if (spawnPoint.canSpawn() == true)
                {
                    // There is a free spawn point in this area
                    return(true);
                }
            }

            // Failed to find a spawn
            return(false);
        }
예제 #15
0
        /// <summary>
        /// Is the spawn point able to spawn an item.
        /// </summary>
        /// <returns>True if the spawn point can spawn an item</returns>
        public override bool canSpawn()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Make sure our spawn is correctly setup
            if (this.isValidConfiguration() == false)
            {
                return(false);
            }

            // Check for trival case
            if (performOccupiedCheck == false)
            {
                return(true);
            }

            // Allow the user to specify how occupied spawns are detected
            switch (occupiedCheckMode)
            {
            // Use physics overlap sphere to validate the spawn
            default:
            case OccupiedCheckMode.OverlapSphere:
            {
                // Get the spawn info
                SpawnInfo info = getSpawnInfo();

                // Find the center point
                Vector3 center = info.SpawnLocation + new Vector3(0, spawnRadius, 0);

                // Perform the sphere overlap
                Collider[] colliders = Physics.OverlapSphere(center, spawnRadius, 1);

                // Iteratre through each collider
                foreach (Collider collider in colliders)
                {
                    // The spawn is occupied
                    if (collider.isTrigger == false)
                    {
                        return(false);
                    }
                }
            }
            break;

            case OccupiedCheckMode.OverlapSphere2D:
            {
                // Get the spawn info
                SpawnInfo info = getSpawnInfo();

                // Find the center point
                Vector3 center = info.SpawnLocation + new Vector3(0, spawnRadius, 0);

                // Perform the overlap sphere
                Collider2D[] colliders = Physics2D.OverlapCircleAll(center, spawnRadius, 1);

                // Iterate though each collider
                foreach (Collider2D collider in colliders)
                {
                    // The spawn is occupied
                    if (collider.isTrigger == false)
                    {
                        return(false);
                    }
                }
            }
            break;

            case OccupiedCheckMode.TriggerEnterExit:
            {
                // Check if the collision list contains any items
                if (collidingObjects.Count > 0 || collidingObjects2D.Count > 0)
                {
                    // This spawn point is occupied
                    return(false);
                }
            }
            break;
            }

            // The spawn point is not occupied and we can spawn at this location
            return(true);
        }