示例#1
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);
        }