mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
VRTrackerManager controller swap fix & IKSystem tweak.
This commit is contained in:
parent
4ca30fe5cd
commit
81e734ec8f
9 changed files with 95 additions and 13 deletions
|
@ -1,9 +1,8 @@
|
|||
using ABI_RC.Systems.IK;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using ABI_RC.Systems.IK.TrackingModules;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.Melons.DesktopVRSwitch.Patches;
|
||||
|
||||
|
@ -44,6 +43,11 @@ public class IKSystemTracker : MonoBehaviour
|
|||
var steamVRTrackingModule = CreateSteamVRTrackingModule();
|
||||
ikSystem.AddTrackingModule(steamVRTrackingModule);
|
||||
}
|
||||
|
||||
//make it so you dont instantly end up in FBT from Desktop
|
||||
IKSystem.firstAvatarLoaded = false;
|
||||
//turn of finger tracking just in case user switched controllers
|
||||
ikSystem.FingerSystem.controlActive = false;
|
||||
}
|
||||
|
||||
//thanks for marking the constructor as internal
|
||||
|
|
|
@ -6,7 +6,6 @@ namespace NAK.Melons.DesktopVRSwitch.Patches;
|
|||
public class MovementSystemTracker : MonoBehaviour
|
||||
{
|
||||
public MovementSystem movementSystem;
|
||||
|
||||
public Vector3 preSwitchWorldPosition;
|
||||
public Quaternion preSwitchWorldRotation;
|
||||
|
||||
|
@ -25,8 +24,16 @@ public class MovementSystemTracker : MonoBehaviour
|
|||
|
||||
public void PreVRModeSwitch(bool enterVR, Camera activeCamera)
|
||||
{
|
||||
preSwitchWorldPosition = movementSystem.rotationPivot.transform.position;
|
||||
//correct rotationPivot y position, so we dont teleport up/down
|
||||
Vector3 position = movementSystem.rotationPivot.transform.position;
|
||||
position.y = movementSystem.transform.position.y;
|
||||
preSwitchWorldPosition = position;
|
||||
preSwitchWorldRotation = movementSystem.rotationPivot.transform.rotation;
|
||||
//ChilloutVR does not use VRIK root right, so avatar root is VR player root.
|
||||
//This causes desync between VR and Desktop positions & collision on switch.
|
||||
|
||||
//I correct for this in lazy way, but i use rotationPivot instead of avatar root,
|
||||
//so the user can still switch even if avatar is null (if it failed to load for example).
|
||||
}
|
||||
|
||||
public void PostVRModeSwitch(bool enterVR, Camera activeCamera)
|
||||
|
|
35
DesktopVRSwitch/Patches/VRTrackerManagerTracker.cs
Normal file
35
DesktopVRSwitch/Patches/VRTrackerManagerTracker.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.Melons.DesktopVRSwitch.Patches;
|
||||
|
||||
public class VRTrackerManagerTracker : MonoBehaviour
|
||||
{
|
||||
public VRTrackerManager vrTrackerManager;
|
||||
public Traverse _hasCheckedForKnucklesTraverse;
|
||||
public Traverse _posesTraverse;
|
||||
|
||||
void Start()
|
||||
{
|
||||
vrTrackerManager = GetComponent<VRTrackerManager>();
|
||||
_posesTraverse = Traverse.Create(vrTrackerManager).Field("poses");
|
||||
_hasCheckedForKnucklesTraverse = Traverse.Create(vrTrackerManager).Field("hasCheckedForKnuckles");
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
|
||||
}
|
||||
|
||||
public void PostVRModeSwitch(bool enterVR, Camera activeCamera)
|
||||
{
|
||||
//force the VRTrackerManager to reset anything its stored
|
||||
//this makes it get correct Left/Right hand if entering VR with different controllers
|
||||
//or if you restarted SteamVR and controllers are now in swapped index
|
||||
vrTrackerManager.leftHand = null;
|
||||
vrTrackerManager.rightHand = null;
|
||||
_posesTraverse.SetValue(null);
|
||||
_hasCheckedForKnucklesTraverse.SetValue(false);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue