Esempio n. 1
0
        /// <summary>
        /// Inform the enemy manager that an enemy has died.
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="destroyObject"></param>
        public override void spawnableDestroyed(GameObject instance, bool destroyObject)
        {
            // Make sure the server is handling the destroyed event
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Make sure we are destroying an enemy
            if (enemyList.Contains(instance) == true)
            {
                // Do we have authority to destroy the instance
                if (destroyObject == true)
                {
#if ULTIMATE_SPAWNER_NETWORKED == true
                    // Destroy on remote clients
                    NetworkServer.Destroy(instance);
#endif

                    // Destroy on local client
#if ULTIMATE_SPAWNER_POOLED == true
                    // Return the instance to the pool for reuse
                    UltimatePool.despawn(instance);
#else
                    // Destroy the instance
                    Destroy(instance);
#endif
                }

                // Remove from list
                enemyList.Remove(instance);
            }
        }
Esempio n. 2
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);
        }