Skip to content

Commit 4ebbce2

Browse files
committed
misc unity cleanup
1 parent 8b490f1 commit 4ebbce2

File tree

4 files changed

+107
-90
lines changed

4 files changed

+107
-90
lines changed

platforms/unity/Assets/BarelyMusician/Scripts/Instrument.cs

+10-8
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,6 @@ public static void OnNoteOnEvent(Instrument instrument, double pitch, double int
256256

257257
private void Awake() {
258258
Source = GetComponent<AudioSource>();
259-
Source.clip = AudioClip.Create("[DO NOT EDIT]", 64, 1, AudioSettings.outputSampleRate, false);
260-
float[] ones = new float[64];
261-
for (int i = 0; i < ones.Length; ++i) {
262-
ones[i] = 1.0f;
263-
}
264-
Source.clip.SetData(ones, 0);
265259
Source.loop = true;
266260
}
267261

@@ -272,13 +266,21 @@ private void OnDestroy() {
272266
private void OnEnable() {
273267
Musician.Internal.Instrument_Create(this, ref _handle);
274268
OnInstrumentCreate?.Invoke();
275-
Source?.Play();
269+
Source.clip = AudioClip.Create("[DO NOT EDIT]", 64, 1, AudioSettings.outputSampleRate, false);
270+
float[] ones = new float[64];
271+
for (int i = 0; i < ones.Length; ++i) {
272+
ones[i] = 1.0f;
273+
}
274+
Source.clip.SetData(ones, 0);
275+
Source.Play();
276276
}
277277

278278
private void OnDisable() {
279-
Source?.Stop();
279+
Source.Stop();
280+
Source.clip = null;
280281
OnInstrumentDestroy?.Invoke();
281282
Musician.Internal.Instrument_Destroy(ref _handle);
283+
_sliceCount = 0;
282284
}
283285

284286
private void Update() {

0 commit comments

Comments
 (0)