From 9856c364c7cfc9090de4985daee7339fcfe36683 Mon Sep 17 00:00:00 2001 From: Aceship Date: Fri, 5 Jul 2024 12:45:38 +0700 Subject: [PATCH] Moved logic so it can be used on other than building --- ValheimVRMod/Patches/EyeRotationPatch.cs | 5 +++-- .../Patches/HandBasedInteractionPatches.cs | 3 ++- ValheimVRMod/Scripts/BuildingManager.cs | 17 ++++++----------- ValheimVRMod/Utilities/LayerUtils.cs | 5 ++++- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ValheimVRMod/Patches/EyeRotationPatch.cs b/ValheimVRMod/Patches/EyeRotationPatch.cs index 464f62248..52c05c2a1 100644 --- a/ValheimVRMod/Patches/EyeRotationPatch.cs +++ b/ValheimVRMod/Patches/EyeRotationPatch.cs @@ -4,6 +4,7 @@ using ValheimVRMod.Utilities; using System.Reflection; using System.Collections.Generic; +using ValheimVRMod.Scripts; namespace ValheimVRMod.Patches { @@ -289,14 +290,14 @@ static void Postfix(Player player) { var ship = player.GetStandingOnShip(); var movableBase = player.transform.parent; - if (ship || (movableBase && movableBase?.name == "MovableBase")) + if (ship || (movableBase && LayerUtils.IsModdedStructure(movableBase?.name))) { Transform referenceUp = null; if (ship) { referenceUp = ship.transform; } - else if (movableBase && movableBase?.name == "MovableBase") + else if (movableBase && LayerUtils.IsModdedStructure(movableBase?.name)) { referenceUp = movableBase.transform; } diff --git a/ValheimVRMod/Patches/HandBasedInteractionPatches.cs b/ValheimVRMod/Patches/HandBasedInteractionPatches.cs index 08cd2d6c4..324e18990 100644 --- a/ValheimVRMod/Patches/HandBasedInteractionPatches.cs +++ b/ValheimVRMod/Patches/HandBasedInteractionPatches.cs @@ -11,6 +11,7 @@ using static ValheimVRMod.Utilities.LogUtils; using TMPro; +using ValheimVRMod.Scripts; namespace ValheimVRMod.Patches { @@ -191,7 +192,7 @@ private static void UpdateHoverObject(Player instance, ref GameObject hoverRefer hitPosition = hit.point; if (hit.collider.GetComponent() != null || !hit.collider.attachedRigidbody || - hit.collider.attachedRigidbody.name == "MovableBase") // MovableBase is the gameobject name for Valheim Raft Mod object + LayerUtils.IsModdedStructure(hit.collider.attachedRigidbody.name)) // Added Compatibility to Valheim Raft Mod object { hoverReference = hit.collider.gameObject; } diff --git a/ValheimVRMod/Scripts/BuildingManager.cs b/ValheimVRMod/Scripts/BuildingManager.cs index 83d2b6ee1..cfef2026e 100644 --- a/ValheimVRMod/Scripts/BuildingManager.cs +++ b/ValheimVRMod/Scripts/BuildingManager.cs @@ -464,12 +464,12 @@ private void UpdateLine() originalRayTraceTransform = pieceRaycast.transform; if (modSupport) { - if (IsModdedStructure(pieceRaycast.transform.name)) + if (LayerUtils.IsModdedStructure(pieceRaycast.transform.name)) { originalRayTraceMod = pieceRaycast.transform; originalRayTraceTransform = pieceRaycast.collider.transform; } - else if (pieceRaycast.transform && (SteamVR_Actions.laserPointers_LeftClick.GetStateDown(SteamVR_Input_Sources.RightHand) || !(Player.m_localPlayer.transform.parent && IsModdedStructure(Player.m_localPlayer.transform.parent.name)))) + else if (pieceRaycast.transform && (SteamVR_Actions.laserPointers_LeftClick.GetStateDown(SteamVR_Input_Sources.RightHand) || !(Player.m_localPlayer.transform.parent && LayerUtils.IsModdedStructure(Player.m_localPlayer.transform.parent.name)))) { originalRayTraceMod = null; } @@ -483,7 +483,7 @@ private void UpdateLine() snapLine.enabled = true; snapLine.positionCount = 2; originalRayTraceTransform = null; - if (!(Player.m_localPlayer.transform.parent && IsModdedStructure(Player.m_localPlayer.transform.parent.name))) + if (!(Player.m_localPlayer.transform.parent && LayerUtils.IsModdedStructure(Player.m_localPlayer.transform.parent.name))) { originalRayTraceMod = null; } @@ -656,7 +656,7 @@ private void UpdateRefPosition(RaycastHit pieceRaycast, Vector3 direction) if (modSupport) { var raft = pieceRaycast.transform; - if (IsModdedStructure(raft.name)) + if (LayerUtils.IsModdedStructure(raft.name)) { buildRefBox.transform.SetParent(raft); } @@ -693,7 +693,7 @@ public int TranslateRotation() var forward = Vector3.forward; if (modSupport) { - if (rayTracedPiece && rayTracedPiece.transform.parent && IsModdedStructure(rayTracedPiece.transform.parent.name)) + if (rayTracedPiece && rayTracedPiece.transform.parent && LayerUtils.IsModdedStructure(rayTracedPiece.transform.parent.name)) { forward = rayTracedPiece.transform.parent.forward; } @@ -807,7 +807,7 @@ private void BuildSnapPoint() firstSnapTransform = pieceRaycast.transform; if (modSupport) { - if (IsModdedStructure(firstSnapTransform.transform.name)) + if (LayerUtils.IsModdedStructure(firstSnapTransform.transform.name)) { lastSnapMod = pieceRaycast.transform; firstSnapTransform = pieceRaycast.collider.transform; @@ -1803,10 +1803,5 @@ public void RelativeEulerModRotate(GameObject ghost) parentRotation = false; } } - - public bool IsModdedStructure(string name) - { - return name == "MS_CustomShip(Clone)" || name == "MovableBase"; - } } } diff --git a/ValheimVRMod/Utilities/LayerUtils.cs b/ValheimVRMod/Utilities/LayerUtils.cs index 5da7bb05a..eec53c8d5 100644 --- a/ValheimVRMod/Utilities/LayerUtils.cs +++ b/ValheimVRMod/Utilities/LayerUtils.cs @@ -87,6 +87,9 @@ private static void checkLayer(int layer) LogWarning("Layer " + layer + " is a named layer: " + layerString); } } - + public static bool IsModdedStructure(string name) + { + return name == "MS_CustomShip(Clone)" || name == "MovableBase" || name == "ValheimVehicles_WaterVehicleShip(Clone)"; + } } }