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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -23,23 +23,48 @@ namespace VRBeats
|
||||
|
||||
public void DisableXRRayInteractorComponents()
|
||||
{
|
||||
rayInteractor.enabled = false;
|
||||
interactorLineVisual.enabled = false;
|
||||
lineRender.enabled = false;
|
||||
if (rayInteractor != null)
|
||||
rayInteractor.enabled = false;
|
||||
if (interactorLineVisual != null)
|
||||
interactorLineVisual.enabled = false;
|
||||
if (lineRender != null)
|
||||
lineRender.enabled = false;
|
||||
|
||||
// VRPointerController는 부모("LeftHand/RightHand Controller")에 추가되므로 InParent로 탐색
|
||||
var pointer = GetComponentInParent<VRPointerController>();
|
||||
if (pointer != null) pointer.enabled = false;
|
||||
// VRPointerController 위치가 컨트롤러/레이 구조에 따라 달라질 수 있어서 계층 전체에서 찾는다.
|
||||
var pointer = FindPointerController();
|
||||
if (pointer != null)
|
||||
pointer.enabled = false;
|
||||
}
|
||||
|
||||
public void EnableXRRayInteractorComponents()
|
||||
{
|
||||
rayInteractor.enabled = true;
|
||||
interactorLineVisual.enabled = true;
|
||||
lineRender.enabled = true;
|
||||
if (rayInteractor != null)
|
||||
rayInteractor.enabled = true;
|
||||
if (interactorLineVisual != null)
|
||||
interactorLineVisual.enabled = true;
|
||||
if (lineRender != null)
|
||||
lineRender.enabled = true;
|
||||
|
||||
var pointer = GetComponentInParent<VRPointerController>();
|
||||
if (pointer != null) pointer.enabled = true;
|
||||
var pointer = FindPointerController();
|
||||
if (pointer != null)
|
||||
pointer.enabled = true;
|
||||
}
|
||||
|
||||
private VRPointerController FindPointerController()
|
||||
{
|
||||
var pointer = GetComponent<VRPointerController>();
|
||||
if (pointer != null)
|
||||
return pointer;
|
||||
|
||||
pointer = GetComponentInParent<VRPointerController>();
|
||||
if (pointer != null)
|
||||
return pointer;
|
||||
|
||||
pointer = GetComponentInChildren<VRPointerController>(true);
|
||||
if (pointer != null)
|
||||
return pointer;
|
||||
|
||||
return transform.root.GetComponentInChildren<VRPointerController>(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user