fix: stabilize VR UI and song playback
This commit is contained in:
@@ -11,6 +11,8 @@ namespace VRBeats
|
||||
[SerializeField] private float fadeOutTime = 4.0f;
|
||||
|
||||
private AudioSource audioSource = null;
|
||||
private double scheduledDspStartTime = -1.0;
|
||||
private bool hasScheduledClip = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -43,13 +45,37 @@ namespace VRBeats
|
||||
|
||||
public void PlayClip(AudioClip clip)
|
||||
{
|
||||
audioSource.clip = clip;
|
||||
audioSource.Play();
|
||||
PlayClipScheduled(clip);
|
||||
}
|
||||
|
||||
public float CurrentTime => audioSource != null ? audioSource.time : 0f;
|
||||
public double PlayClipScheduled(AudioClip clip, double delaySeconds = 0.1)
|
||||
{
|
||||
ResetThisComponent();
|
||||
audioSource.Stop();
|
||||
audioSource.clip = clip;
|
||||
audioSource.time = 0.0f;
|
||||
|
||||
scheduledDspStartTime = AudioSettings.dspTime + delaySeconds;
|
||||
hasScheduledClip = true;
|
||||
audioSource.PlayScheduled(scheduledDspStartTime);
|
||||
|
||||
return scheduledDspStartTime;
|
||||
}
|
||||
|
||||
public float CurrentTime
|
||||
{
|
||||
get
|
||||
{
|
||||
if (audioSource == null)
|
||||
return 0.0f;
|
||||
|
||||
if (hasScheduledClip)
|
||||
return (float)(AudioSettings.dspTime - scheduledDspStartTime);
|
||||
|
||||
return audioSource.time;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user