private void CreateLabelForMidiNote(int midiNote) { Text uiText = Instantiate(labelPrefab, labelContainer); RectTransform label = uiText.GetComponent <RectTransform>(); float y = (float)noteArea.GetVerticalPositionForMidiNote(midiNote); float anchorHeight = noteArea.HeightForSingleNote; label.anchorMin = new Vector2(0, y - (anchorHeight / 2f)); label.anchorMax = new Vector2(1, y + (anchorHeight / 2f)); label.anchoredPosition = Vector2.zero; label.sizeDelta = new Vector2(0, 0); string midiNoteName = MidiUtils.GetAbsoluteName(midiNote); uiText.text = midiNoteName; }
private void PositionUiNote(RectTransform uiNoteRectTransform, int midiNote, int startBeat, int endBeat) { float y = (float)noteArea.GetVerticalPositionForMidiNote(midiNote); float xStart = (float)noteArea.GetHorizontalPositionForBeat(startBeat); float xEnd = (float)noteArea.GetHorizontalPositionForBeat(endBeat); float height = noteArea.HeightForSingleNote; uiNoteRectTransform.anchorMin = new Vector2(xStart, y - height / 2f); uiNoteRectTransform.anchorMax = new Vector2(xEnd, y + height / 2f); uiNoteRectTransform.anchoredPosition = Vector2.zero; uiNoteRectTransform.sizeDelta = Vector2.zero; }
private void CreatePianoKeyForMidiNote(int midiNote) { VirtualPianoKey key = Instantiate(pianoKeyPrefab, pianoKeyContainer); injector.Inject(key); key.MidiNote = midiNote; RectTransform keyRectTransform = key.GetComponent <RectTransform>(); float y = (float)noteArea.GetVerticalPositionForMidiNote(midiNote); float anchorHeight = noteArea.HeightForSingleNote * 0.8f; float xMax = MidiUtils.IsWhitePianoKey(midiNote) ? 0.9f : 0.7f; keyRectTransform.anchorMin = new Vector2(0, y - (anchorHeight / 2f)); keyRectTransform.anchorMax = new Vector2(xMax, y + (anchorHeight / 2f)); keyRectTransform.anchoredPosition = Vector2.zero; keyRectTransform.sizeDelta = new Vector2(0, 0); }