public void Nullify()
    {
        LastSpawnedSegment = null;
        spawnSegment       = null;

        normalSpawned = 0;
        bufferSpawned = 0;
    }
    public void Initialize()
    {
        //instantiating the object pools into your scene.
        //You can 'load' these pools in during gameplay to change the availability of different tile sets.

        /*
         * TEST BIOME
         */
        for (int i = 0; i < testNormalPieces.Count; i++)
        {
            trackPiece newSegment = Instantiate(testNormalPieces[i]);
            newSegment.gameObject.name = "Test Normal Segment (" + i + ")";
            i_testNormalPool.Add(newSegment);
            newSegment.gameObject.SetActive(false);
        }

        for (int i = 0; i < testBossPieces.Count; i++)
        {
            trackPiece newSegment = Instantiate(testBossPieces[i]);
            newSegment.gameObject.name = "Test Boss Segment (" + i + ")";
            i_testBossPool.Add(newSegment);
            newSegment.gameObject.SetActive(false);
        }

        {
            trackPiece newSegment = Instantiate(testBossStart);
            newSegment.gameObject.name = "Test Boss Segment (Start)";
            i_testBossStart            = newSegment;
            newSegment.gameObject.SetActive(false);
        }

        /*
         * GRASS BIOME
         */
        for (int i = 0; i < grassNormalPieces.Count; i++)
        {
            trackPiece newSegment = Instantiate(grassNormalPieces[i]);
            newSegment.gameObject.name = "Grass Normal Segment (" + i + ")";
            i_grassNormalPool.Add(newSegment);
            newSegment.gameObject.SetActive(false);
        }
        for (int i = 0; i < grassBossPieces.Count; i++)
        {
            trackPiece newSegment = Instantiate(grassBossPieces[i]);
            newSegment.gameObject.name = "Grass Boss Segment (" + i + ")";
            i_grassBossPool.Add(newSegment);
            newSegment.gameObject.SetActive(false);
        }

        {
            trackPiece newSegment = Instantiate(grassBossStart);
            newSegment.gameObject.name = "Grass Boss Segment (Start)";
            i_grassBossStart           = newSegment;
            newSegment.gameObject.SetActive(false);
        }
    }
    /// <summary>
    /// Will return the object to the current pool if it is considered an 'active' segment.
    /// </summary>
    /// <param name="segment"></param>
    public void ReturnToPool(trackPiece segment)
    {
        if (activeSegments.Contains(segment))
        {
            activePool.Add(segment);
        }

        activeSegments.Remove(segment);

        segment.gameObject.SetActive(false);
        segment.transform.position = spawnPosition;
        segment.spawnedNextSegment = false;
    }
    public void SpawnRandomSegment()
    {
        //Check for Empty Pool
        if (activePool.Count <= 0)
        {
            Debug.LogWarning("Tried to spawn from an empty pool! [" + activePool.ToString() + "]");

            Debug.LogWarning("Pulling New Piece to Spawn");

            switch (biome.GetCurrentBiome())
            {
            case BIOME.TEST:
                if (spawnEnemies.instance.GetBossSpawned())
                {
                    trackPiece newPiece = Instantiate(testBossPieces[0]);
                    newPiece.gameObject.SetActive(false);
                    newPiece.name = "Test Boss Piece (Backup)";
                    activePool.Add(newPiece);
                    i_testBossPool.Add(newPiece);
                }
                else
                {
                    trackPiece newPiece = Instantiate(testNormalPieces[0]);
                    newPiece.gameObject.SetActive(false);
                    newPiece.name = "Test Normal Piece (Backup)";
                    activePool.Add(newPiece);
                    i_testNormalPool.Add(newPiece);
                }
                break;

            case BIOME.GRASS:
                if (spawnEnemies.instance.GetBossSpawned())
                {
                    trackPiece newPiece = Instantiate(grassBossPieces[0]);
                    newPiece.gameObject.SetActive(false);
                    newPiece.name = "Grass Boss Piece (Backup)";
                    activePool.Add(newPiece);
                    i_grassBossPool.Add(newPiece);
                }
                else
                {
                    trackPiece newPiece = Instantiate(grassNormalPieces[Random.Range(0, grassNormalPieces.Count - 1)]);
                    newPiece.gameObject.SetActive(false);
                    newPiece.name = "Grass Normal Piece (Backup)";
                    activePool.Add(newPiece);
                    i_grassNormalPool.Add(newPiece);
                }
                break;
            }

            //return;
        }

        //Various Checks for Tracking if Biome Length
        //Has Been Reached, If Buffer Length has Been
        //Reached and if Boss Start Segment Needs to
        //Spawn
        if (buffer && bufferSpawned < bufferLength)
        {
            bufferSpawned++;
        }
        else if (buffer && bufferSpawned >= bufferLength)
        {
            buffer        = false;
            bufferSpawned = 0;

            ChangeBiome();
            spawnEnemies.instance.ChangeBiome();
        }
        else
        {
            if (!spawnEnemies.instance.GetBossSpawned())
            {
                if (!BIOMELENGTH_OVERRIDE)
                {
                    normalSpawned++;
                }

                if (normalSpawned > biomeLength)
                {
                    switch (biome.GetCurrentBiome())
                    {
                    case BIOME.TEST:
                        activePool = LoadPool(i_testBossPool);
                        spawnEnemies.instance.SetBossSpawned(false);
                        break;

                    case BIOME.GRASS:
                        activePool = LoadPool(i_grassBossPool);
                        //spawnEnemies.instance.SetBossSpawned(false);
                        break;
                    }

                    normalSpawned = -1;
                }
            }
        }

        if (normalSpawned == -1)
        {
            switch (biome.GetCurrentBiome())
            {
            case BIOME.TEST:
                newSegment = i_testBossStart;
                break;

            case BIOME.GRASS:
                newSegment = i_grassBossStart;
                break;
            }

            normalSpawned = 0;
        }
        else
        {
            newSegment = activePool[Random.Range(0, activePool.Count)];
            activeSegments.Add(newSegment);
            activePool.Remove(newSegment);
        }

        /*
         * for (int i = 0; i < newSegment.spawnPoints.Count; i++)
         * {
         *
         *  spawnEnemies.instance.AddPoint(newSegment.spawnPoints[i]);
         *
         * }
         */

        if (LastSpawnedSegment != null)
        {
            newSegment.transform.position = LastSpawnedSegment.snapLocation.position;
        }
        else
        {
            newSegment.transform.position = initialSpawnPosition;
        }

        newSegment.gameObject.SetActive(true);
        spawnSegment       = LastSpawnedSegment;
        LastSpawnedSegment = newSegment;
    }