Handling of "VR <-> Desktop" switch, attempt one

This commit is contained in:
SDraw 2024-01-29 23:11:01 +03:00
parent c2a219dfa3
commit 66b448a2c3
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
20 changed files with 356 additions and 77 deletions

View file

@ -332,17 +332,7 @@ namespace ml_pam
internal void OnAvatarSetup()
{
// Recheck if user could switch to VR
if(m_inVR != Utils.IsInVR())
{
m_rootLeft.parent = PlayerSetup.Instance.GetActiveCamera().transform;
m_rootLeft.localPosition = Vector3.zero;
m_rootLeft.localRotation = Quaternion.identity;
m_rootRight.parent = PlayerSetup.Instance.GetActiveCamera().transform;
m_rootRight.localPosition = Vector3.zero;
m_rootRight.localRotation = Quaternion.identity;
}
m_inVR = Utils.IsInVR();
RecheckMode();
if(!m_inVR && PlayerSetup.Instance._animator.isHuman)
{
@ -409,8 +399,8 @@ namespace ml_pam
else
{
m_armLength = m_vrIK.solver.leftArm.mag * 1.25f;
m_vrIK.solver.OnPreUpdate += this.OnIKPreUpdate;
m_vrIK.solver.OnPostUpdate += this.OnIKPostUpdate;
m_vrIK.onPreSolverUpdate.AddListener(this.OnIKPreUpdate);
m_vrIK.onPostSolverUpdate.AddListener(this.OnIKPostUpdate);
}
l_tpHelper.Restore();
@ -420,6 +410,19 @@ namespace ml_pam
SetEnabled(m_enabled);
}
internal void OnAvatarReinitialize()
{
// Old VRIK is destroyed by game
RecheckMode();
m_vrIK = PlayerSetup.Instance._animator.GetComponent<VRIK>();
if(m_vrIK != null)
{
m_armLength = m_vrIK.solver.leftArm.mag * 1.25f;
m_vrIK.onPreSolverUpdate.AddListener(this.OnIKPreUpdate);
m_vrIK.onPostSolverUpdate.AddListener(this.OnIKPostUpdate);
}
}
internal void OnPickupGrab(CVRPickupObject p_pickup, ControllerRay p_ray, Vector3 p_hit)
{
if(p_ray == ViewManager.Instance.desktopControllerRay)
@ -509,5 +512,20 @@ namespace ml_pam
}
}
}
void RecheckMode()
{
if(m_inVR != Utils.IsInVR())
{
m_rootLeft.parent = PlayerSetup.Instance.GetActiveCamera().transform;
m_rootLeft.localPosition = Vector3.zero;
m_rootLeft.localRotation = Quaternion.identity;
m_rootRight.parent = PlayerSetup.Instance.GetActiveCamera().transform;
m_rootRight.localPosition = Vector3.zero;
m_rootRight.localRotation = Quaternion.identity;
}
m_inVR = Utils.IsInVR();
}
}
}