mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 22:39:22 +00:00
dancing around issues
This commit is contained in:
parent
7403b6c3e7
commit
a8b97607e1
2 changed files with 60 additions and 35 deletions
54
TrackedControllerFix/TrackedControllerFix.cs
Normal file
54
TrackedControllerFix/TrackedControllerFix.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using UnityEngine;
|
||||
using Valve.VR;
|
||||
|
||||
namespace NAK.Melons.TrackedControllerFix;
|
||||
|
||||
public class TrackedControllerFix : MonoBehaviour
|
||||
{
|
||||
public SteamVR_Input_Sources inputSource;
|
||||
public int deviceIndex;
|
||||
|
||||
private SteamVR_TrackedObject trackedObject;
|
||||
private SteamVR_Behaviour_Pose oldBehaviourPose;
|
||||
private SteamVR_Action_Pose actionPose = SteamVR_Input.GetAction<SteamVR_Action_Pose>("Pose", false);
|
||||
|
||||
private void Start()
|
||||
{
|
||||
trackedObject = gameObject.AddComponent<SteamVR_TrackedObject>();
|
||||
oldBehaviourPose = gameObject.GetComponent<SteamVR_Behaviour_Pose>();
|
||||
oldBehaviourPose.broadcastDeviceChanges = false; //this fucks us
|
||||
if (actionPose != null) CheckDeviceIndex();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (actionPose != null) actionPose[inputSource].onDeviceConnectedChanged += OnDeviceConnectedChanged;
|
||||
oldBehaviourPose.enabled = false;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (actionPose != null) actionPose[inputSource].onDeviceConnectedChanged -= OnDeviceConnectedChanged;
|
||||
oldBehaviourPose.enabled = true;
|
||||
}
|
||||
|
||||
private void OnDeviceConnectedChanged(SteamVR_Action_Pose changedAction, SteamVR_Input_Sources changedSource, bool connected)
|
||||
{
|
||||
if (actionPose != changedAction) actionPose = changedAction;
|
||||
if (changedSource != inputSource) return;
|
||||
CheckDeviceIndex();
|
||||
}
|
||||
|
||||
private void CheckDeviceIndex()
|
||||
{
|
||||
if (actionPose[inputSource].active && actionPose[inputSource].deviceIsConnected)
|
||||
{
|
||||
int trackedDeviceIndex = (int)actionPose[inputSource].trackedDeviceIndex;
|
||||
if (deviceIndex != trackedDeviceIndex)
|
||||
{
|
||||
deviceIndex = trackedDeviceIndex;
|
||||
trackedObject.SetDeviceIndex(deviceIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue