Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/VRBoatWheel.cs
2026-02-21 16:45:37 +08:00

119 lines
3.8 KiB
C#

using BitStrap;
using UnityEngine;
public class VRBoatWheel : MonoBehaviour
{
public Transform holdTransform;
public Transform rotateParent;
public float holdDistanceStart = 0.5f;
public float holdDistanceStop = 0.8f;
public Renderer wheelModel;
[ReadOnly]
public float currentWheelRotation;
[ReadOnly]
public float prevWheelRotation;
public float maxWheelRotation = 90f;
public bool isHolding;
public OVRInput.Controller holdingController;
public Transform tempRotationPosition;
public float tempRotationAngle;
[ReadOnly]
public float startRotationAngle;
private void Start()
{
}
public float MakeUpdate()
{
if (!VRManager.Instance.IsVRDriveBoat())
{
return 0f;
}
float num = Vector3.Distance(holdTransform.position, VRControllersManager.Instance.GetVRController(OVRInput.Controller.LTouch).boatWheelTransform.position);
float num2 = Vector3.Distance(holdTransform.position, VRControllersManager.Instance.GetVRController(OVRInput.Controller.RTouch).boatWheelTransform.position);
bool flag = false;
if (isHolding)
{
if ((holdingController != OVRInput.Controller.LTouch || !(num < holdDistanceStop) || !OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.LTouch)) && (holdingController != OVRInput.Controller.RTouch || !(num2 < holdDistanceStop) || !OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.RTouch)))
{
UtilitiesInput.SetVibration(0, holdingController == VRControllersManager.Instance.GetPrimaryController(), 0.2f, 0.15f);
holdingController = OVRInput.Controller.None;
isHolding = false;
rotateParent.localEulerAngles = new Vector3(base.transform.localEulerAngles.x, base.transform.localEulerAngles.y, 0f);
startRotationAngle = (tempRotationAngle = (prevWheelRotation = 0f));
}
}
else if (num < holdDistanceStart && OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.LTouch))
{
holdingController = OVRInput.Controller.LTouch;
isHolding = true;
flag = true;
UtilitiesInput.SetVibration(0, VRControllersManager.Instance.IsLeftHanded(), 0.3f, 0.2f);
}
else if (num2 < holdDistanceStart && OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.RTouch))
{
holdingController = OVRInput.Controller.RTouch;
isHolding = true;
flag = true;
UtilitiesInput.SetVibration(0, !VRControllersManager.Instance.IsLeftHanded(), 0.3f, 0.2f);
}
if ((bool)wheelModel)
{
wheelModel.materials[(wheelModel.materials.Length > 1) ? 1 : 0].color = ((!isHolding) ? Color.white : Color.yellow);
}
if (isHolding)
{
Transform boatWheelTransform = VRControllersManager.Instance.GetVRController(holdingController).boatWheelTransform;
boatWheelTransform.parent = holdTransform;
Vector3 localPosition = boatWheelTransform.localPosition;
boatWheelTransform.parent = VRControllersManager.Instance.GetVRController(holdingController).gameplayTransformsParent.transform;
localPosition.z = 0f;
if ((bool)tempRotationPosition)
{
tempRotationPosition.localPosition = localPosition;
}
tempRotationAngle = Utilities.GetVectorAngle(localPosition);
}
if (flag)
{
startRotationAngle = tempRotationAngle;
}
if (isHolding)
{
currentWheelRotation = startRotationAngle - tempRotationAngle;
if (currentWheelRotation > 180f)
{
currentWheelRotation -= 360f;
}
else if (currentWheelRotation < -180f)
{
currentWheelRotation += 360f;
}
rotateParent.localEulerAngles = new Vector3(base.transform.localEulerAngles.x, base.transform.localEulerAngles.y, currentWheelRotation);
if ((currentWheelRotation > 90f && prevWheelRotation < -90f) || (currentWheelRotation < -90f && prevWheelRotation > 90f))
{
currentWheelRotation = prevWheelRotation;
}
else
{
prevWheelRotation = currentWheelRotation;
}
return currentWheelRotation / maxWheelRotation;
}
return 0f;
}
}