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

@ -1,5 +1,6 @@
using ABI_RC.Core.Player;
using ABI_RC.Systems.IK;
using ABI_RC.Systems.VRModeSwitch;
using RootMotion.FinalIK;
using System.Reflection;
using UnityEngine;
@ -121,7 +122,7 @@ namespace ml_lme
void LateUpdate()
{
if(m_enabled && !m_inVR && (m_poseHandler != null))
if(m_enabled && (m_vrIK == null) && (m_poseHandler != null))
{
LeapParser.LeapData l_data = LeapManager.Instance.GetLatestData();
@ -147,8 +148,7 @@ namespace ml_lme
m_leftTargetActive = false;
m_rightTargetActive = false;
if(!m_inVR)
m_poseHandler?.Dispose();
m_poseHandler?.Dispose();
m_poseHandler = null;
m_leftHandTarget.localPosition = Vector3.zero;
@ -169,7 +169,7 @@ namespace ml_lme
if(m_hips != null)
l_hipsPos = m_hips.localPosition;
if(m_vrIK == null)
if(!m_inVR)
{
// Force desktop avatar into T-Pose
m_poseHandler = new HumanPoseHandler(PlayerSetup.Instance._animator.avatar, PlayerSetup.Instance._avatar.transform);
@ -236,8 +236,8 @@ namespace ml_lme
}
else
{
m_vrIK.solver.OnPreUpdate += this.OnIKPreUpdate;
m_vrIK.solver.OnPostUpdate += this.OnIKPostUpdate;
m_vrIK.onPreSolverUpdate.AddListener(this.OnIKPreUpdate);
m_vrIK.onPostSolverUpdate.AddListener(this.OnIKPostUpdate);
}
if(m_hips != null)
@ -245,6 +245,18 @@ namespace ml_lme
}
}
internal void OnAvatarReinitialize()
{
// Old VRIK is destroyed by game
m_inVR = Utils.IsInVR();
m_vrIK = PlayerSetup.Instance._animator.GetComponent<VRIK>();
if(m_vrIK != null)
{
m_vrIK.onPreSolverUpdate.AddListener(this.OnIKPreUpdate);
m_vrIK.onPostSolverUpdate.AddListener(this.OnIKPostUpdate);
}
}
// VRIK updates
void OnIKPreUpdate()
{