Skip to content

Commit

Permalink
0.3.3
Browse files Browse the repository at this point in the history
- Implement playerScale option
- Implement playerOffset option

With this you can customize your experience more by standing on the front deck of the ship or viewing the world from high up above.
  • Loading branch information
xen-42 authored Dec 21, 2023
2 parents e913b0b + b669d57 commit 77a4783
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 14 deletions.
14 changes: 13 additions & 1 deletion DredgeVR/Options/OptionsConfig.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Newtonsoft.Json;
using UnityEngine;

namespace DredgeVR.Options;

[JsonObject]
[JsonObject(MemberSerialization.OptIn)]
public class OptionsConfig
{
/// <summary>
Expand Down Expand Up @@ -94,4 +95,15 @@ public class OptionsConfig
/// </summary>
[JsonProperty]
public bool smoothRotation = false;

/// <summary>
/// Changes the size of the player in the game world
/// </summary>
[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]);
}
13 changes: 9 additions & 4 deletions DredgeVR/VRCamera/VRCameraManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -45,13 +43,15 @@ 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<EyeCamera>();
LeftEye.left = true;

var rightCamera = cameras[1];
rightCamera.transform.parent = transform;
rightCamera.transform.localPosition = Vector3.zero;
rightCamera.transform.localRotation = Quaternion.identity;
rightCamera.nearClipPlane *= OptionsManager.Options.playerScale;
RightEye = rightCamera.gameObject.AddComponent<EyeCamera>();
RightEye.left = false;

Expand Down Expand Up @@ -92,6 +92,9 @@ public void Awake()
var renderObject = new RenderObjects { name = "Flip" };
Delay.FireOnNextUpdate(() => renderObject.GetValue<RenderObjectsPass>("renderObjectsPass").renderPassEvent = RenderPassEvent.AfterRendering);
dataLists.First().rendererFeatures.Insert(0, renderObject);

// Rescale the character
_pivot.transform.localScale = Vector3.one * OptionsManager.Options.playerScale;
}

public void OnDestroy()
Expand Down Expand Up @@ -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);
}
}

Expand Down
20 changes: 16 additions & 4 deletions DredgeVR/VRInput/VRHand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using DredgeVR.Helpers;
using DredgeVR.Options;
using DredgeVR.VRCamera;
using DredgeVR.VRUI;
using System.Collections;
using UnityAsyncAwaitUtil;
using UnityEngine;
Expand Down Expand Up @@ -38,7 +41,7 @@ public void Start()
LaserPointerEnd = GameObject.CreatePrimitive(PrimitiveType.Sphere);
Component.DestroyImmediate(LaserPointerEnd.GetComponent<SphereCollider>());
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
Expand All @@ -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)
Expand Down Expand Up @@ -110,22 +120,24 @@ 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;

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
Expand Down
7 changes: 4 additions & 3 deletions DredgeVR/VRUI/GameCanvasFixer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DredgeVR.VRCamera;
using DredgeVR.Options;
using DredgeVR.VRCamera;
using UnityEngine;

namespace DredgeVR.VRUI;
Expand All @@ -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;
}
}
}
7 changes: 7 additions & 0 deletions DredgeVR/VRUI/Patches/DestinationButtonPatches.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Cinemachine.Utility;
using DredgeVR.Helpers;
using DredgeVR.Options;
using HarmonyLib;
using UnityEngine;

Expand Down Expand Up @@ -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;

Expand Down
9 changes: 8 additions & 1 deletion DredgeVR/VRUI/VRUIManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using DredgeVR.Helpers;
using DredgeVR.Items;
using DredgeVR.Options;
using DredgeVR.VRCamera;
using DredgeVR.VRInput;
using System;
using System.Linq;
Expand Down Expand Up @@ -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<TabbedPanelContainer>());
Expand Down
2 changes: 1 addition & 1 deletion DredgeVR/mod_meta.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 77a4783

Please sign in to comment.