void Update() { curTimer += Time.deltaTime; speakingNear.Clear(); foreach (var speaker in shutUpWhenOtherSpeaking) { if (speaker.currentNotePattern != null && Vector3.Distance(speaker.transform.position, transform.position) < shutUpWhenOtherSpeakingRadius) { speakingNear.Add(speaker); } } if (speakingNear.Count > 0) { curState = IdlePatternState.ShuttingUp; playNotes.StopPlaying(); curTimer = 0f; } switch (curState) { case IdlePatternState.PlayingNotes: if (playNotes.currentPattern == null) { curState = IdlePatternState.PausedBetween; curTimer = 0f; } break; case IdlePatternState.PausedBetween: if (curTimer > pauseBetweenRepeats) { if (playNotes.currentPattern == null) { playNotes.PlayPattern(pattern, volume); curState = IdlePatternState.PlayingNotes; } } break; case IdlePatternState.ShuttingUp: if (speakingNear.Count == 0 && curTimer > pauseBeforeResume) { if (playNotes.currentPattern == null) { playNotes.PlayPattern(pattern, volume); curState = IdlePatternState.PlayingNotes; } } break; default: break; } }
public void Execute(NotePattern p) { Renderer rend = GetComponent <Renderer>(); rend.material.SetColor("_Color", Color.green); PlayPatternIdle idlePattern = GetComponent <PlayPatternIdle>(); idlePattern.enabled = false; playNotes.PlayPattern(p); }
public void PlayBackLast() { if (lastRecorded == null) { Debug.Log("No last recorded file on record."); return; } string json = File.ReadAllText(dataPath + lastRecorded + ".json"); NotePattern nPattern = JsonUtility.FromJson <NotePattern>(json); PlayNotes playNotes = GetComponent <PlayNotes>(); playNotes.PlayPattern(nPattern); }
void Update() { if (recording) { Note inputNote = Note.NONOTE; if (Input.GetButtonDown("NoteA")) { inputNote = Note.NoteA; playNotes.PlayPattern(NotePattern.soloA); } else if (Input.GetButtonDown("NoteB")) { inputNote = Note.NoteB; playNotes.PlayPattern(NotePattern.soloB); } else if (Input.GetButtonDown("NoteC")) { inputNote = Note.NoteC; playNotes.PlayPattern(NotePattern.soloC); } else if (Input.GetButtonDown("NoteD")) { inputNote = Note.NoteD; playNotes.PlayPattern(NotePattern.soloD); } if (inputNote != Note.NONOTE) { if (currentNotePattern == null) { currentNotePattern = new NotePattern(new List <NoteStamp> { new NoteStamp { note = inputNote, time = 0f } }); firstNoteTime = Time.time; } else { currentNotePattern.Pattern.Add(new NoteStamp { note = inputNote, time = Time.time - firstNoteTime }); } } else { if (currentNotePattern != null) { // Check if a second has passed since last note, stop recording if so. float deadTimePassed = Time.time - (firstNoteTime + currentNotePattern.Pattern[currentNotePattern.Pattern.Count - 1].time); Debug.Log(deadTimePassed); Debug.Log(currentNotePattern.Pattern.Count); if (currentNotePattern != null && deadTimePassed > NotePattern.patternEndWindow) { recording = false; recordButtonText.text = "Record"; firstNoteTime = -1f; string json = JsonUtility.ToJson(currentNotePattern); currentNotePattern = null; // Save currentNotePattern. if (fileName.text != null || fileName.text != "") { try { File.WriteAllText(dataPath + fileName.text + ".json", json); lastRecorded = fileName.text; lastRecordedTextDisplay.text = lastRecorded; } catch (Exception e) { Debug.Log("Failed to save pattern " + NotePattern.patternFilePath + fileName.text + ", error: " + e.Message); } } } } } } }
void Update() { Note inputNote = Note.NONOTE; if (Input.GetButtonDown("NoteA")) { inputNote = Note.NoteA; playNotes.PlayPattern(NotePattern.soloA); } else if (Input.GetButtonDown("NoteB")) { inputNote = Note.NoteB; playNotes.PlayPattern(NotePattern.soloB); } else if (Input.GetButtonDown("NoteC")) { inputNote = Note.NoteC; playNotes.PlayPattern(NotePattern.soloC); } else if (Input.GetButtonDown("NoteD")) { inputNote = Note.NoteD; playNotes.PlayPattern(NotePattern.soloD); } if (inputNote != Note.NONOTE) { if (currentNotePattern == null) { currentNotePattern = new NotePattern(new List <NoteStamp> { new NoteStamp { note = inputNote, time = 0f } }); firstNoteTime = Time.time; } else { currentNotePattern.Pattern.Add(new NoteStamp { note = inputNote, time = Time.time - firstNoteTime }); } } else { if (currentNotePattern != null) { // Check if a second has passed since last note, stop recording if so. float deadTimePassed = Time.time - (firstNoteTime + currentNotePattern.Pattern[currentNotePattern.Pattern.Count - 1].time); if (currentNotePattern != null && deadTimePassed > NotePattern.patternEndWindow) { NotifyListenersOfPattern(currentNotePattern); firstNoteTime = -1f; currentNotePattern = null; } } } }