fix: stabilize VR UI and song playback

This commit is contained in:
jongjae0305
2026-05-26 18:21:58 +09:00
parent 5e5e918c10
commit 182d2c90b9
5 changed files with 136 additions and 26 deletions
+30 -4
View File
@@ -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;
}
}
}
}