public float CalculateNoteSpeed(ChartNote note) { var page = Root.page_list[note.page_index]; var previousPage = Root.page_list[note.page_index - 1]; var pageRatio = (float)( 1.0f * (note.tick - page.actual_start_tick) / (page.end_tick - page.actual_start_tick)); var tempo = (page.end_time - page.actual_start_time) * pageRatio + (previousPage.end_time - previousPage.actual_start_time) * (1.367f - pageRatio); return(tempo >= 1.367f ? 1.0f : 1.367f / tempo); }
protected override void LateUpdate() { base.LateUpdate(); if (!View.IsRendered()) { View.OnRender(); } var time = Game.Time; IsMoving = time >= Note.start_time; if (IsMoving) { if (time >= ToNote.start_time) { gameObject.transform.eulerAngles = new Vector3(0, 0, 45 - ToNote.rotation); if (ToNote.next_id <= 0) { IsMoving = false; gameObject.transform.position = ToNote.position; } else { FromNote = ToNote; ToNote = Chart.note_list[FromNote.next_id]; } } if (IsMoving) { gameObject.transform.position = Vector3.Lerp(FromNote.position, ToNote.position, (time - FromNote.start_time) / (ToNote.start_time - FromNote.start_time)); } } else { gameObject.transform.position = Note.position; FromNote = Note; ToNote = Chart.note_list[Note.next_id]; } }
public ChartRoot FromCytus1Chart(string text) { // Parse var pageDuration = 0f; var pageShift = 0f; var tmpNotes = new Dictionary <int, C1Note>(); foreach (var line in text.Split('\n')) { var data = line.Split((char[])null, StringSplitOptions.RemoveEmptyEntries); if (data.Length == 0) { continue; } var type = data[0]; switch (type) { case "PAGE_SIZE": pageDuration = float.Parse(data[1]); checksumSource += data[1]; break; case "PAGE_SHIFT": pageShift = float.Parse(data[1]); checksumSource += data[1]; break; case "NOTE": checksumSource += data[1] + data[2] + data[3] + data[4]; var note = new C1Note(int.Parse(data[1]), float.Parse(data[2]), float.Parse(data[3]), float.Parse(data[4]), false); tmpNotes.Add(int.Parse(data[1]), note); if (note.Duration > 0) { note.Type = C1NoteType.Hold; } break; case "LINK": var notesInChain = new List <C1Note>(); for (var i = 1; i < data.Length; i++) { if (data[i] != "LINK") { checksumSource += data[i]; } int id; if (!int.TryParse(data[i], out id)) { continue; } note = tmpNotes[id]; note.Type = C1NoteType.Chain; if (!notesInChain.Contains(note)) { notesInChain.Add(note); } } for (var i = 0; i < notesInChain.Count - 1; i++) { notesInChain[i].ConnectedNote = notesInChain[i + 1]; } notesInChain[0].IsChainHead = true; break; } } pageShift += pageDuration; // Calculate chronological note ids var sortedNotes = tmpNotes.Values.ToList(); sortedNotes.Sort((a, b) => a.Time.CompareTo(b.Time)); var chronologicalIds = sortedNotes.Select(note => note.OriginalId).ToList(); var notes = new Dictionary <int, C1Note>(); // Recalculate note ids from original ids var newId = 0; foreach (var noteId in chronologicalIds) { tmpNotes[noteId].Id = newId; notes[newId] = tmpNotes[noteId]; newId++; } // Reset chronological ids chronologicalIds.Clear(); for (var i = 0; i < tmpNotes.Count; i++) { chronologicalIds.Add(i); } // Convert const int timeBase = 480; var root = new ChartRoot(); root.format_version = 0; root.time_base = 480; root.start_offset_time = 0; var tempo = new ChartTempo(); tempo.tick = 0; var tempoValue = (long)(pageDuration * 1000000f); tempo.value = tempoValue; root.tempo_list = new List <ChartTempo> { tempo }; if (pageShift < 0) { pageShift = pageShift + 2 * pageDuration; } var pageShiftTickOffset = pageShift / pageDuration * timeBase; var noteList = new List <ChartNote>(); var page = 0; foreach (var note in notes.Values) { var obj = new ChartNote(); obj.id = note.Id; switch (note.Type) { case C1NoteType.Single: obj.type = NoteType.Click; break; case C1NoteType.Chain: obj.type = note.IsChainHead ? NoteType.DragHead : NoteType.DragChild; break; case C1NoteType.Hold: obj.type = NoteType.Hold; break; } obj.x = note.X; var ti = note.Time * timeBase * 1000000 / tempoValue + pageShiftTickOffset; obj.tick = ti; obj.hold_tick = note.Duration * timeBase * 1000000 / tempoValue; page = Mathf.FloorToInt(ti / timeBase); obj.page_index = page; if (note.Type == C1NoteType.Chain) { obj.next_id = note.ConnectedNote != null ? note.ConnectedNote.Id : -1; } else { obj.next_id = 0; } if (obj.ring_color != null) { obj.ParsedRingColor = Convert.HexToColor(obj.ring_color); } if (obj.fill_color != null) { obj.ParsedFillColor = Convert.HexToColor(obj.fill_color); } noteList.Add(obj); } root.note_list = noteList; var pageList = new List <ChartPage>(); var direction = false; var t = 0; for (var i = 0; i <= page; i++) { var obj = new ChartPage(); obj.scan_line_direction = direction ? 1 : -1; direction = !direction; obj.start_tick = t; t += timeBase; obj.end_tick = t; pageList.Add(obj); } root.page_list = pageList; root.music_offset = pageShiftTickOffset / timeBase / 1000000 * tempoValue; return(root); }
private void Start() { FromNote = Note; ToNote = Chart.note_list[Note.next_id]; }