mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 10:29:22 +00:00
Handling of "VR <-> Desktop" switch, attempt one
This commit is contained in:
parent
c2a219dfa3
commit
66b448a2c3
20 changed files with 356 additions and 77 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using ABI.CCK.Components;
|
||||
using ABI_RC.Core.InteractionSystem;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.IK;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
@ -30,6 +31,11 @@ namespace ml_pam
|
|||
null,
|
||||
new HarmonyLib.HarmonyMethod(typeof(PickupArmMovement).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
HarmonyInstance.Patch(
|
||||
typeof(IKSystem).GetMethod(nameof(IKSystem.ReinitializeAvatar), BindingFlags.Instance | BindingFlags.Public),
|
||||
null,
|
||||
new HarmonyLib.HarmonyMethod(typeof(PickupArmMovement).GetMethod(nameof(OnAvatarReinitialize_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
HarmonyInstance.Patch(
|
||||
typeof(CVRPickupObject).GetMethod(nameof(CVRPickupObject.Grab)),
|
||||
null,
|
||||
|
@ -95,6 +101,20 @@ namespace ml_pam
|
|||
}
|
||||
}
|
||||
|
||||
static void OnAvatarReinitialize_Postfix() => ms_instance?.OnAvatarReinitialize();
|
||||
void OnAvatarReinitialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(m_localMover != null)
|
||||
m_localMover.OnAvatarReinitialize();
|
||||
}
|
||||
catch(System.Exception e)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
static void OnCVRPickupObjectGrab_Postfix(ref CVRPickupObject __instance, ControllerRay __1, Vector3 __2) => ms_instance?.OnCVRPickupObjectGrab(__instance, __1, __2);
|
||||
void OnCVRPickupObjectGrab(CVRPickupObject p_pickup, ControllerRay p_ray, Vector3 p_hit)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using ABI_RC.Core.UI;
|
||||
using ABI_RC.Core.Savior;
|
||||
using ABI_RC.Core.UI;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
|
@ -8,7 +9,7 @@ namespace ml_pam
|
|||
{
|
||||
static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
public static bool IsInVR() => ((ABI_RC.Core.Savior.CheckVR.Instance != null) && ABI_RC.Core.Savior.CheckVR.Instance.hasVrDeviceLoaded);
|
||||
public static bool IsInVR() => ((MetaPort.Instance != null) && MetaPort.Instance.isUsingVr);
|
||||
|
||||
static public void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => ((cohtml.Net.View)ms_view.GetValue(p_instance)).ExecuteScript(p_script);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue