diff --git a/DredgeVR/Options/OptionsConfig.cs b/DredgeVR/Options/OptionsConfig.cs index 08ab78b..f449476 100644 --- a/DredgeVR/Options/OptionsConfig.cs +++ b/DredgeVR/Options/OptionsConfig.cs @@ -1,8 +1,9 @@ using Newtonsoft.Json; +using UnityEngine; namespace DredgeVR.Options; -[JsonObject] +[JsonObject(MemberSerialization.OptIn)] public class OptionsConfig { /// @@ -94,4 +95,15 @@ public class OptionsConfig /// [JsonProperty] public bool smoothRotation = false; + + /// + /// Changes the size of the player in the game world + /// + [JsonProperty] + public float playerScale = 1f; + + [JsonProperty] + public float[] playerPosition = new float[] { 0, 1.13f, -1.5f }; + + public Vector3 PlayerPosition => new(playerPosition[0], playerPosition[1], playerPosition[2]); } diff --git a/DredgeVR/VRCamera/VRCameraManager.cs b/DredgeVR/VRCamera/VRCameraManager.cs index 72ee98b..bb2d4ad 100644 --- a/DredgeVR/VRCamera/VRCameraManager.cs +++ b/DredgeVR/VRCamera/VRCameraManager.cs @@ -28,8 +28,6 @@ public class VRCameraManager : MonoBehaviour public static Transform AnchorTransform { get; private set; } private Transform _pivot, _rotationPivot, _root; - private float _gameAnchorYPosition = 0.8f; - public float minX = 0.5f; private bool _justTurned; @@ -45,6 +43,7 @@ public void Awake() leftCamera.transform.parent = transform; leftCamera.transform.localPosition = Vector3.zero; leftCamera.transform.localRotation = Quaternion.identity; + leftCamera.nearClipPlane *= OptionsManager.Options.playerScale; LeftEye = leftCamera.gameObject.AddComponent(); LeftEye.left = true; @@ -52,6 +51,7 @@ public void Awake() rightCamera.transform.parent = transform; rightCamera.transform.localPosition = Vector3.zero; rightCamera.transform.localRotation = Quaternion.identity; + rightCamera.nearClipPlane *= OptionsManager.Options.playerScale; RightEye = rightCamera.gameObject.AddComponent(); RightEye.left = false; @@ -92,6 +92,9 @@ public void Awake() var renderObject = new RenderObjects { name = "Flip" }; Delay.FireOnNextUpdate(() => renderObject.GetValue("renderObjectsPass").renderPassEvent = RenderPassEvent.AfterRendering); dataLists.First().rendererFeatures.Insert(0, renderObject); + + // Rescale the character + _pivot.transform.localScale = Vector3.one * OptionsManager.Options.playerScale; } public void OnDestroy() @@ -224,12 +227,14 @@ private void ResetAnchorToBoat() { if (_inFinaleCutscene) return; - AnchorTransform.localPosition = new Vector3(0, _gameAnchorYPosition + 0.33f, -1.5f); + AnchorTransform.localPosition = OptionsManager.Options.PlayerPosition; // Helps when you ram into stuff to not bounce around if (OptionsManager.Options.lockCameraYPosition) { - AnchorTransform.position = new Vector3(AnchorTransform.position.x, _gameAnchorYPosition, AnchorTransform.position.z); + // Subtract 0.33 from the local height to go from local to global + var lockedY = OptionsManager.Options.PlayerPosition.y - 0.33f; + AnchorTransform.position = new Vector3(AnchorTransform.position.x, lockedY, AnchorTransform.position.z); } } diff --git a/DredgeVR/VRInput/VRHand.cs b/DredgeVR/VRInput/VRHand.cs index 482b506..5e22d3d 100644 --- a/DredgeVR/VRInput/VRHand.cs +++ b/DredgeVR/VRInput/VRHand.cs @@ -1,4 +1,7 @@ using DredgeVR.Helpers; +using DredgeVR.Options; +using DredgeVR.VRCamera; +using DredgeVR.VRUI; using System.Collections; using UnityAsyncAwaitUtil; using UnityEngine; @@ -38,7 +41,7 @@ public void Start() LaserPointerEnd = GameObject.CreatePrimitive(PrimitiveType.Sphere); Component.DestroyImmediate(LaserPointerEnd.GetComponent()); LaserPointerEnd.transform.parent = RaycastCamera.transform; - LaserPointerEnd.transform.localScale = Vector3.one * 0.025f; + LaserPointerEnd.transform.localScale = Vector3.one * 0.025f * OptionsManager.Options.playerScale; LaserPointerEnd.name = "Dot"; // Tried using a line renderer for this but it did not behave in VR @@ -58,6 +61,13 @@ public void Start() VRInputModule.Instance.DominantHandChanged += OnDominantHandChanged; OnDominantHandChanged(VRInputModule.Instance.DominantHandInputSource); + + VRUIManager.HeldUIHidden += OnHeldUIHidden; + } + + private void OnHeldUIHidden(bool hidden) + { + } private void OnDominantHandChanged(SteamVR_Input_Sources dominantHand) @@ -110,7 +120,7 @@ public void Update() IsHoveringUI = inputRaycastDistance > 0; - var targetLength = IsHoveringUI ? inputRaycastDistance : defaultLength; + var targetLength = IsHoveringUI ? inputRaycastDistance : defaultLength * OptionsManager.Options.playerScale; // Only collide with UI var endPosition = RaycastCamera.transform.position + RaycastCamera.transform.forward * targetLength; @@ -118,14 +128,16 @@ public void Update() if (IsHoveringUI) { _line.transform.position = (transform.position + endPosition) / 2f; - _line.transform.localScale = new Vector3(0.005f, (transform.position - endPosition).magnitude / 2f, 0.005f); + var width = 0.005f * OptionsManager.Options.playerScale; + _line.transform.localScale = new Vector3(width, (transform.position - endPosition).magnitude / 2f, width); LaserPointerEnd.transform.position = endPosition; } else { _fadedLine.transform.position = (transform.position + endPosition) / 2f; - _fadedLine.transform.localScale = new Vector3(0.001f, (transform.position - endPosition).magnitude / 2f, 0.001f); + var width = 0.001f * OptionsManager.Options.playerScale; + _fadedLine.transform.localScale = new Vector3(width, (transform.position - endPosition).magnitude / 2f, width); } // Should show when colliding with UI diff --git a/DredgeVR/VRUI/GameCanvasFixer.cs b/DredgeVR/VRUI/GameCanvasFixer.cs index 6f5cc8b..3111184 100644 --- a/DredgeVR/VRUI/GameCanvasFixer.cs +++ b/DredgeVR/VRUI/GameCanvasFixer.cs @@ -1,4 +1,5 @@ -using DredgeVR.VRCamera; +using DredgeVR.Options; +using DredgeVR.VRCamera; using UnityEngine; namespace DredgeVR.VRUI; @@ -18,9 +19,9 @@ public void Update() if (uiParent != null) { - transform.position = uiParent.transform.TransformPoint(Offset); + transform.position = uiParent.transform.TransformPoint(Offset * OptionsManager.Options.playerScale); transform.rotation = Quaternion.Euler(0f, uiParent.rotation.eulerAngles.y, 0f); - transform.localScale = Vector3.one * scale; + transform.localScale = Vector3.one * scale * OptionsManager.Options.playerScale; } } } \ No newline at end of file diff --git a/DredgeVR/VRUI/Patches/DestinationButtonPatches.cs b/DredgeVR/VRUI/Patches/DestinationButtonPatches.cs index 8c6180c..9bff308 100644 --- a/DredgeVR/VRUI/Patches/DestinationButtonPatches.cs +++ b/DredgeVR/VRUI/Patches/DestinationButtonPatches.cs @@ -1,5 +1,6 @@ using Cinemachine.Utility; using DredgeVR.Helpers; +using DredgeVR.Options; using HarmonyLib; using UnityEngine; @@ -76,6 +77,12 @@ public static bool DestinationButton_LateUpdate(DestinationButton __instance) planeOffset *= 3f; } + if (OptionsManager.Options.playerScale > 1) + { + yOffset *= OptionsManager.Options.playerScale; + scaleModifier /= OptionsManager.Options.playerScale; + } + __instance.transform.position = __instance.destination.transform.position + yOffset + planeOffset; __instance.transform.localScale = Vector3.one * scaleModifier; diff --git a/DredgeVR/VRUI/VRUIManager.cs b/DredgeVR/VRUI/VRUIManager.cs index 253ec70..0aa61fe 100644 --- a/DredgeVR/VRUI/VRUIManager.cs +++ b/DredgeVR/VRUI/VRUIManager.cs @@ -1,5 +1,7 @@ using DredgeVR.Helpers; using DredgeVR.Items; +using DredgeVR.Options; +using DredgeVR.VRCamera; using DredgeVR.VRInput; using System; using System.Linq; @@ -137,7 +139,12 @@ private void OnTitleSceneStart() canvas.transform.rotation = Quaternion.Euler(0, 70, 0); } - canvas.transform.localScale = Vector3.one * 0.002f; + canvas.transform.localScale = Vector3.one * 0.002f * OptionsManager.Options.playerScale; + + // Tweak start canvas position based on player scale + var offset = (canvas.transform.position - VRCameraManager.AnchorTransform.position); + offset.y = 0; + canvas.transform.position += offset * (OptionsManager.Options.playerScale - 1f); // Remove controls tab for now since it doesnt work RemoveControlsTab(GameObject.Find("Canvases/SettingsDialog/TabbedPanelContainer").GetComponent()); diff --git a/DredgeVR/mod_meta.json b/DredgeVR/mod_meta.json index 02a2fab..b591749 100644 --- a/DredgeVR/mod_meta.json +++ b/DredgeVR/mod_meta.json @@ -1,7 +1,7 @@ { "Name": "DredgeVR", "ModGUID": "xen.DredgeVR", - "Version": "0.3.2", + "Version": "0.3.3", "ModAssembly": "DredgeVR.dll", "MinWinchVersion": "0.3.0", "Entrypoint": "DredgeVR.Loader/Initialize",