diff --git a/TrackedControllerFix/HarmonyPatches.cs b/TrackedControllerFix/HarmonyPatches.cs index be5d728..f312b0f 100644 --- a/TrackedControllerFix/HarmonyPatches.cs +++ b/TrackedControllerFix/HarmonyPatches.cs @@ -4,16 +4,18 @@ using Valve.VR; namespace NAK.TrackedControllerFix.HarmonyPatches; -internal class PlayerSetupPatches +class PlayerSetupPatches { [HarmonyPostfix] - [HarmonyPatch(typeof(PlayerSetup), "Start")] - private static void Post_PlayerSetup_Start(ref PlayerSetup __instance) + [HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.Start))] + static void Post_PlayerSetup_Start(ref PlayerSetup __instance) { // Add TrackedControllerFix var vrLeftHandTracker = __instance.vrLeftHandTracker.AddComponent(); vrLeftHandTracker.inputSource = SteamVR_Input_Sources.LeftHand; var vrRightHandTracker = __instance.vrRightHandTracker.AddComponent(); vrRightHandTracker.inputSource = SteamVR_Input_Sources.RightHand; + vrLeftHandTracker.Initialize(); + vrRightHandTracker.Initialize(); } } \ No newline at end of file diff --git a/TrackedControllerFix/TrackedControllerFix.cs b/TrackedControllerFix/TrackedControllerFix.cs index 3097c56..0a0955c 100644 --- a/TrackedControllerFix/TrackedControllerFix.cs +++ b/TrackedControllerFix/TrackedControllerFix.cs @@ -8,11 +8,11 @@ public class TrackedControllerFixer : 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("Pose", false); + SteamVR_TrackedObject trackedObject; + SteamVR_Behaviour_Pose oldBehaviourPose; + SteamVR_Action_Pose actionPose = SteamVR_Input.GetAction("Pose", false); - private void Start() + public void Initialize() { trackedObject = gameObject.AddComponent(); oldBehaviourPose = gameObject.GetComponent(); @@ -20,26 +20,28 @@ public class TrackedControllerFixer : MonoBehaviour if (actionPose != null) CheckDeviceIndex(); } - private void OnEnable() + void OnEnable() { if (actionPose != null) actionPose[inputSource].onDeviceConnectedChanged += OnDeviceConnectedChanged; - oldBehaviourPose.enabled = false; + if (oldBehaviourPose != null) + oldBehaviourPose.enabled = false; } - private void OnDisable() + void OnDisable() { if (actionPose != null) actionPose[inputSource].onDeviceConnectedChanged -= OnDeviceConnectedChanged; - oldBehaviourPose.enabled = true; + if (oldBehaviourPose != null) + oldBehaviourPose.enabled = true; } - private void OnDeviceConnectedChanged(SteamVR_Action_Pose changedAction, SteamVR_Input_Sources changedSource, bool connected) + 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() + void CheckDeviceIndex() { if (actionPose[inputSource].active && actionPose[inputSource].deviceIsConnected) {