Beispiel #1
0
    /// <summary>
    /// Conscruct a Song object that holds data regarding the timing of the rhythm,
    /// and properties like name and artist. Loads in the information from a JSON file
    /// for the song that is specified by the name and artist arguments.
    /// </summary>
    /// <param name="baseFilePath"></param>
    /// <param name="name"></param>
    /// <param name="artist"></param>
    public Song(string baseFilePath, string name, string artist)
    {
        filePath   = baseFilePath + "\\Assets\\Scripts\\Music\\" + name + " - " + artist;
        rhythmData = new List <int>();
        musicData  = new Dictionary <string, dynamic>();
        bool isViable = true;

        // check validity of RhythmData and MusicData, if both are valid then program will proceed.
        if (!MusicFileHandler.tryRhythmData(filePath, rhythmData))
        {
            Debug.Log("Error in RhythmData.csv, please check error log in " + filePath);
            isViable = false;
        }
        if (!MusicFileHandler.tryMusicData(filePath, musicData))
        {
            Debug.Log("Error in MusicData.csv, please check error log in " + filePath);
            isViable = false;
        }
        if (isViable)
        {
            // extract json data if values are viable
            Name       = musicData["Name"];
            Artist     = musicData["Artist"];
            Genre      = musicData["Genre"];
            Length     = musicData["Length"];
            NumOfBeats = musicData["Beats"];
            Highscore  = musicData["Highscore"];
            // convert formatted string "Length" to milliseconds
            string[] lengthArr = Length.Split(':');
            LengthMilli = Int32.Parse(lengthArr[0]) * 60000 + Int32.Parse(lengthArr[1]) * 1000;
        }
        else
        {
        }
    }
Beispiel #2
0
    // Start is called before the first frame update

    /// <summary>
    /// Before the first frame update, we create multiple variables and set their values
    /// including the specified cubes, a list of rhythm data to parse through, creating a time and count,
    /// getting the song from the file, and creating the audio source as well as creating a button manager
    /// </summary>
    void Start()
    {
        setCubes();
        // startTime = Time.time;
        filePath   = Directory.GetCurrentDirectory() + "\\Assets\\Scripts\\Music\\Alive - Mind Vortex";
        rhythmData = new List <int>();
        MusicFileHandler.tryRhythmData(filePath, rhythmData);
        time  = 0;
        count = 0;
        song  = new Song(Directory.GetCurrentDirectory(), "Alive", "Mind Vortex");
        audioSource.PlayDelayed(delay);
        lengthMilli = audioSource.clip.length * 1000;
        manager     = new ButtonSceneManager();
    }