void InstantiateNotesData(MusicModel.NotesData notesData)
    {
        var editorModel = NotesEditorModel.Instance;

        editorModel.BPM.Value = notesData.BPM;
        editorModel.BeatOffsetSamples.Value = notesData.offset;

        foreach (var note in notesData.notes)
        {
            if (note.type == 1)
            {
                InstantiateNoteObject(notesData, note);
                continue;
            }

            var longNoteObjects = new MusicModel.Note[] { note }.Concat(note.notes)
            .Select(note_ => InstantiateNoteObject(notesData, note_))
            .ToList();

            for (int i = 1; i < longNoteObjects.Count; i++)
            {
                longNoteObjects[i].prev     = longNoteObjects[i - 1];
                longNoteObjects[i - 1].next = longNoteObjects[i];
            }
        }
    }
    NoteObject InstantiateNoteObject(MusicModel.NotesData notesData, MusicModel.Note note)
    {
        var noteObject = (Instantiate(noteObjectPrefab) as GameObject).GetComponent <NoteObject>();

        noteObject.notePosition   = new NotePosition(notesData.BPM, note.LPB, note.num, note.block);
        noteObject.noteType.Value = note.type == 2 ? NoteTypes.Long : NoteTypes.Normal;
        noteObject.transform.SetParent(notesRegion.transform);
        NotesEditorModel.Instance.NoteObjects.Add(noteObject.notePosition, noteObject);
        return(noteObject);
    }
Ejemplo n.º 3
0
    public string SerializeNotesData()
    {
        var data = new MusicModel.NotesData();

        data.BPM    = BPM.Value;
        data.offset = BeatOffsetSamples.Value;
        data.name   = Path.GetFileNameWithoutExtension(MusicName.Value);

        var sortedNoteObjects = NoteObjects.Values
                                .Where(note => !(note.noteType.Value == NoteTypes.Long && note.prev != null))
                                .OrderBy(note => note.notePosition.ToSamples(Audio.clip.frequency));

        data.notes = new List <MusicModel.Note>();

        foreach (var noteObject in sortedNoteObjects)
        {
            if (noteObject.noteType.Value == NoteTypes.Normal)
            {
                data.notes.Add(ConvertToNote(noteObject));
            }
            else if (noteObject.noteType.Value == NoteTypes.Long)
            {
                var current = noteObject;
                var note    = ConvertToNote(noteObject);

                while (current.next != null)
                {
                    note.notes.Add(ConvertToNote(current.next));
                    current = current.next;
                }

                data.notes.Add(note);
            }
        }

        var jsonWriter = new JsonWriter();

        jsonWriter.PrettyPrint = true;
        jsonWriter.IndentValue = 4;
        JsonMapper.ToJson(data, jsonWriter);
        return(jsonWriter.ToString());
    }