public MusicNode GetNode(float posX, float startY, float endY, float removeLineY, float posZ, float beat, int times, Color color, int id) { //check if there is an inactive instance foreach (MusicNode node in objList) { if (!node.gameObject.activeInHierarchy) { node.Initialize(posX, startY, endY, removeLineY, posZ, beat, times, color, id); node.gameObject.SetActive(true); return(node); } } //no inactive instances, instantiate a new GetComponent MusicNode musicNode = ((GameObject)Instantiate(nodePrefab)).GetComponent <MusicNode>(); musicNode.Initialize(posX, startY, endY, removeLineY, posZ, beat, times, color, id); objList.Add(musicNode); return(musicNode); }
public void OnUpdate() { if (paused) { return; } songPosition = (float)(AudioSettings.dspTime - dspTimeSong) * m_AudioService.GetAudioSource().pitch; float beatToShow = songPosition / crotchet + BeatsShownOnScreen; for (int i = 0; i < len; i++) { int nextIndex = trackNextIndices[i]; SongInfo.Track currTrack = tracks[i]; if (nextIndex < currTrack.Notes.Length && currTrack.Notes[nextIndex].note < beatToShow) { SongInfo.Note currNote = currTrack.Notes[nextIndex]; Vector3 parentPos = i == 0 ? LeftParent.position : RightParent.position; MusicNode musicNode = Instantiate(NodePrefab, new Vector3(parentPos.x, Screen.height + 200, 0), this.transform.rotation, i == 0 ? LeftParent : RightParent); musicNode.Initialize(parentPos.x, Screen.height + 200, finishLineY, 0, currNote.note); trackNextIndices[i]++; queueForTracks[i].Enqueue(musicNode); } } if (songPosition > songLength) { if (m_OnFinish != null) { m_OnFinish.Invoke(); paused = true; m_OnFinish = null; m_OnInput = null; } } }