Ejemplo n.º 1
0
    void SpawnBeat()
    {
        //What Beat to Spawn
        if (beats[0].IsNewCombo)
        {
            int prevColor = colorIndex;
            while (colorIndex == prevColor)
            {
                colorIndex = UnityEngine.Random.Range(0, 4);                                         //Randomise until you get a Different Color
            }
        }

        //Check if Beat is a Slider
        double beatLength = beats[0].EndTime - beats[0].StartTime;                              //Get Total Time Span of Beat

        if (beatLength / 1000 >= sliderThreshold && generateSliderBeats)                        //If it Qualifies as a Slider
        {
            int beatsToSpawn = Mathf.FloorToInt((float)(beatLength / (sliderInterval * 1000))); //Check how many beats to spawn
            //print(string.Format("Function Calculates such that it is to spawn {0} Additional Beats. Beat Length is {1}, Slider Threshold is {2}", beatsToSpawn, beatLength, sliderInterval * 1000));
            double beatInterval = beatsToSpawn == 0 ? 0 : beatLength / beatsToSpawn;
            //print("Beat Interval is " + beatInterval);

            for (int i = 0; i <= beatsToSpawn; i++)
            {
                //Make Last Beat the Directional Beat
                bool   isDirectional = (i == beatsToSpawn);
                string tag           = isDirectional ? "Directional" : "Slider";

                //Instantiate(beatPrefabs[1], beatSpawnPos.position, Quaternion.identity);
                Vector3 posOffset = isDirectional ? Vector3.zero : new Vector3(0, 0.15f, 0);
                Beat    beat      = objPooler.SpawnFromPool(tag, beatSpawnPos.position + posOffset, Quaternion.identity, beatSpawnPos).GetComponent <Beat>();
                beat.InitialiseBeat(this, beatSpawnPos.position + posOffset, spawnHitDist);

                //Set Slider Beats to their Correct Timing
                double additionalOffset = beatInterval * i;
                beat.SetBeatInstanceValues(GetBoxColorByIndex(colorIndex), GetTrackTime() + additionalOffset / 1000, beats[0].StartTime + additionalOffset, isDirectional ? RandomiseValidBeatDirection() : Direction.None);
                beat.MoveBeatPosition();
            }
        }
        else
        {
            //Beat beat = Instantiate(beatPrefabs[i], beatSpawnPos.position, Quaternion.identity);
            Beat beat = objPooler.SpawnFromPool("Normal", beatSpawnPos.position, Quaternion.identity, beatSpawnPos).GetComponent <Beat>();
            beat.InitialiseBeat(this, beatSpawnPos.position, spawnHitDist);

            beat.SetBeatInstanceValues(GetBoxColorByIndex(colorIndex), GetTrackTime(), beats[0].StartTime);
            beat.MoveBeatPosition();
        }

        beats.RemoveAt(0);

        if (spawnOnlyOneBeat)
        {
            beats.Clear();
        }
    }