// Update is called once per frame void Update() { GameObject.Find("CurrentTime").GetComponent <Text>().text = "Current Time: " + MusicPlayer.time; if (EditorState == State.Editing) { SycnNoteLocation(); if ((Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.L))) { int minIndex = -1; float minRange = Mathf.Infinity; for (int i = 0; i < ConstructedNote.Count; i++) { if (Mathf.Abs(ConstructedNote[i].m_Timestamp - MusicPlayer.time) < minRange) { minRange = Mathf.Abs(ConstructedNote[i].m_Timestamp - MusicPlayer.time); minIndex = i; } } if (minRange <= 0.05) { ConstructedNote[minIndex].m_GameObject.GetComponent <EditableNoteController>().GetHit(); } } } if (EditorState == State.Recording) { if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.L) || Input.GetKeyDown(KeyCode.B)) { string noteType = ""; if (Input.GetKeyDown(KeyCode.A)) { noteType = "0"; } else if (Input.GetKeyDown(KeyCode.L)) { noteType = "1"; } else { noteType = "2"; } EditableNote newNote = new EditableNote(ConstructedNote.Count, MusicPlayer.time, noteType, 2f); ConstructedNote.Add(newNote); GameObject.Find("CurrentTotalNoteNum").GetComponent <Text>().text = "Total Note: " + ConstructedNote.Count; } if (MusicPlayer.time >= TheSong.length) { StopRecording(); } } }
public void ConstructNoteFromFile() { MusicPlayer.Stop(); foreach (Transform item in NoteContainer.transform) { Destroy(item.gameObject); } string FilePath = ""; #if UNITY_EDITOR FilePath = UnityEditor.EditorUtility.OpenFilePanel("Open Note Record File" , Application.streamingAssetsPath , "json"); #endif System.IO.StreamReader reader = new System.IO.StreamReader(FilePath); string rawJson = reader.ReadLine(); RawNoteRecord savedNotes = JsonUtility.FromJson <RawNoteRecord>(rawJson); int noteNum = savedNotes.TimestampList.Count; ConstructedNote.Clear(); for (int i = 0; i < noteNum; i++) { EditableNote newNote = new EditableNote(i, savedNotes.TimestampList[i], savedNotes.NoteTypeList[i], 2f); if (savedNotes.TimestampList[i] > 90) { newNote.m_Lifespan = 1.5f; } GameObject newNoteGameObject = Instantiate(NotePrefab, NoteContainer.transform); newNoteGameObject.GetComponent <EditableNoteController>().Init(newNote.m_NoteType, i); newNote.m_GameObject = newNoteGameObject; ConstructedNote.Add(newNote); } GameObject.Find("CurrentTotalNoteNum").GetComponent <Text>().text = "Total Note: " + ConstructedNote.Count; EditorState = State.Editing; GameObject.Find("CurrentEditorState").GetComponent <Text>().text = "Editor State: Editing"; }