private PianoKeyObjectSettings GetPianoKeyObjectSettings(PianoKeyColor pianoKeyColor) { if (pianoKeyColor == PianoKeyColor.WHITE) { return(whiteKeyObjectSettings); } else { return(blackKeyObjectSettings); } }
private void CreatePianoKey(Transform parent, PianoKeyColor pianoKeyColor, int midiNote, float distanceBetweenWhiteKeys) { PianoKeyObjectSettings pianoKeyObjectSettings = GetPianoKeyObjectSettings(pianoKeyColor); Vector3 position = GetPosition(pianoKeyColor, pianoKeyObjectSettings, distanceBetweenWhiteKeys); GameObject pianoKeyObject = PrefabUtility.InstantiatePrefab(pianoKeyObjectSettings.prefab) as GameObject; pianoKeyObject.transform.parent = parent; pianoKeyObject.transform.localPosition = position; pianoKeyObject.transform.localRotation = Quaternion.identity; //PianoKey pianoKey = pianoKeyObject.GetComponent<PianoKey>(); PianoKey pianoKey = pianoKeyObject.GetComponentInChildren <PianoKey>(); pianoKey.SetMidiPlayer(midiPlayer); pianoKey.SetMidiNote(midiNote); }
private Vector3 GetPosition(PianoKeyColor pianoKeyColor, PianoKeyObjectSettings pianoKeyObjectSettings, float distanceBetweenWhiteKeys) { Vector3 position = nextWhiteKeyPosition; Vector3 baseOffset = pianoKeyObjectSettings.baseOffset; if (pianoKeyColor == PianoKeyColor.WHITE) { nextWhiteKeyPosition += Vector3.right * (whiteKeyBounds.size.x + distanceBetweenWhiteKeys); } else if (pianoKeyColor == PianoKeyColor.BLACK) { position += Vector3.left * (whiteKeyBounds.size.x + distanceBetweenWhiteKeys) * 0.5f + blackKeyOffset; } return(position + baseOffset); }
public void BuildPiano(Transform parent, int octaves, int skippedOctaves, float distanceBetweenWhiteKeys) { parentScale = parent.localScale; parent.localScale = Vector3.one; int startNote = lowestC + skippedOctaves * wholeOctaveLength; int pianoKeyCount = octaves * wholeOctaveLength; for (int i = 0; i < pianoKeyCount; i++) { int midiNote = startNote + i; PianoKeyColor pianoKeyColor = GetPianoKeyColorForNote(midiNote); CreatePianoKey(parent, pianoKeyColor, midiNote, distanceBetweenWhiteKeys); } parent.localScale = parentScale; }