Tanoda
RecordedAudio.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System;
10using System.Collections.Generic;
11using UnityEngine;
12
13namespace Leap.Unity.Recording {
14
15 public class RecordedAudio : MonoBehaviour {
16
17 public AudioSource target;
18 public List<ClipData> data = new List<ClipData>();
19
20 private bool _prevWasPlaying = false;
21 private float _prevTime = 0;
22 private AudioClip _prevClip = null;
23
24 private void LateUpdate() {
25 bool didStartNewClip = false;
26
27 if (target.isPlaying && !_prevWasPlaying) {
28 didStartNewClip = true;
29 }
30
31 if (target.time < _prevTime && target.isPlaying) {
32 didStartNewClip = true;
33 }
34
35 if (target.clip != null && target.clip != _prevClip && target.isPlaying) {
36 didStartNewClip = true;
37 }
38
39 if (didStartNewClip) {
40 data.Add(new ClipData() {
41 clip = target.clip,
42 startTime = HierarchyRecorder.instance.recordingTime,
43 pitch = target.pitch,
44 volume = target.volume
45 });
46 }
47
48 _prevWasPlaying = target.isPlaying;
49 _prevTime = target.time;
50 _prevClip = target.clip;
51 }
52
53 [Serializable]
54 public class ClipData {
55 public AudioClip clip;
56 public float startTime;
57 public float pitch;
58 public float volume;
59 }
60 }
61}