Exemplo n.º 1
0
    // Save list by serialization
    public List <(float, float)> SaveRecordingToDat(string fileLoc, List <Transform> notesObjects)
    {
        fileLoc += ".dat";
        FileStream file;

        Directory.CreateDirectory(Application.dataPath + "/levels/");

        if (File.Exists(fileLoc))
        {
            file = File.OpenWrite(fileLoc);
        }
        else
        {
            file = File.Create(fileLoc);
        }

        BinaryFormatter bf = new BinaryFormatter();

        // Transform list from list of objects to list of tuples with only time attributes
        List <(float, float)> timelineNoteTuples = new List <(float, float)>();

        if (notesObjects.Count == 0)
        {
            Debug.Log("List is empty!");
            return(null);
        }

        // Add info about offset and bpm first
        LevelCreatorManager levelCreatorManager = FindObjectOfType <LevelCreatorManager>();

        timelineNoteTuples.Add((levelCreatorManager.BPMValue, levelCreatorManager.OffsetValue));

        // Pass notes data
        foreach (Transform noteObject in notesObjects)
        {
            NoteTimelineIndicator noteTimelineIndicator = noteObject.GetComponent <NoteTimelineIndicator>();
            timelineNoteTuples.Add((noteTimelineIndicator.Timestamp, noteTimelineIndicator.TimeHeld));
        }

        bf.Serialize(file, timelineNoteTuples);
        file.Close();

        for (int i = 0; i < timelineNoteTuples.Count; i++)
        {
            Debug.Log(timelineNoteTuples[i].Item1);
        }

        return(timelineNoteTuples);
    }
Exemplo n.º 2
0
    public void SaveRecordingToTxt(string fileLoc, List <Transform> notesObjects)
    {
        fileLoc += ".txt";
        using (TextWriter tw = new StreamWriter(fileLoc))
        {
            // Add info about offset and bpm first
            LevelCreatorManager levelCreatorManager = FindObjectOfType <LevelCreatorManager>();
            tw.WriteLine(levelCreatorManager.BPMValue.ToString() + " /  " + levelCreatorManager.OffsetValue.ToString());

            foreach (Transform noteObject in notesObjects)
            {
                NoteTimelineIndicator noteTimelineIndicator = noteObject.GetComponent <NoteTimelineIndicator>();
                tw.WriteLine(noteTimelineIndicator.Timestamp.ToString() + " /  " + noteTimelineIndicator.TimeHeld.ToString());

                Debug.Log((noteTimelineIndicator.Timestamp, noteTimelineIndicator.TimeHeld));
            }
        }
    }