162 lines
5.1 KiB
C#
162 lines
5.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class TrophyRoomPlayer : MonoBehaviour
|
|
{
|
|
[HideInInspector]
|
|
public vp_FPInput ufpsInput;
|
|
|
|
[HideInInspector]
|
|
public vp_FPCamera ufpsCamera;
|
|
|
|
[HideInInspector]
|
|
public vp_FPController ufpsController;
|
|
|
|
[HideInInspector]
|
|
public OVRPlayerController ovrPlayerController;
|
|
|
|
public FishingPlayer fishingPlayer;
|
|
|
|
public Transform vrCameraParent;
|
|
|
|
public GameObject vrTeleport;
|
|
|
|
public GameObject vrPlayerController;
|
|
|
|
public GameObject vrPointer;
|
|
|
|
public float fadedOutTime = 0.5f;
|
|
|
|
private void Start()
|
|
{
|
|
ufpsInput = GetComponent<vp_FPInput>();
|
|
ufpsController = GetComponent<vp_FPController>();
|
|
ufpsCamera = GetComponentInChildren<vp_FPCamera>(true);
|
|
ovrPlayerController = GetComponentInChildren<OVRPlayerController>(true);
|
|
if ((bool)fishingPlayer)
|
|
{
|
|
fishingPlayer.ufpsInput = ufpsInput;
|
|
fishingPlayer.ufpsController = ufpsController;
|
|
fishingPlayer.ufpsCamera = ufpsCamera;
|
|
if (VRManager.IsVROn())
|
|
{
|
|
ufpsCamera.transform.parent.localPosition = new Vector3(0f, VRManager.Instance.cameraHeight, 0f);
|
|
ovrPlayerController.transform.localPosition = new Vector3(0f, VRManager.Instance.cameraHeight, 0f);
|
|
}
|
|
}
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
ufpsInput.MouseLookSensitivity *= GlobalSettings.Instance.playerSettings.mouseSensitivity;
|
|
ufpsInput.MouseLookInvert = GlobalSettings.Instance.playerSettings.invertYAxis < 0f;
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
UpdateMovement();
|
|
UpdateFOV();
|
|
UpdateRotation();
|
|
ufpsController.PhysicsSlopeSlidiness = 0f;
|
|
}
|
|
|
|
private void UpdateMovement()
|
|
{
|
|
if (!VRManager.IsVROn() || VRManager.Instance.playerWalkStyle == VRManager.PlayerWalkStyle.FREE)
|
|
{
|
|
ufpsInput.InputRun();
|
|
ufpsInput.MakeUpdate();
|
|
}
|
|
}
|
|
|
|
private void UpdateFOV()
|
|
{
|
|
if ((bool)GlobalSettings.Instance && !VRManager.IsVROn())
|
|
{
|
|
ufpsCamera.GetComponent<Camera>().fieldOfView = GlobalSettings.Instance.renderSettings.fov;
|
|
}
|
|
}
|
|
|
|
private void UpdateRotation()
|
|
{
|
|
if (!fishingPlayer || !VRManager.IsVROn())
|
|
{
|
|
return;
|
|
}
|
|
if (VRManager.Instance.playerRotateStyle == VRManager.PlayerRotateStyle.STEP)
|
|
{
|
|
if (UtilitiesInput.GetButtonDown("VR_TURN_LEFT") || OVRInput.GetDown(OVRInput.Button.SecondaryThumbstickLeft, OVRInput.Controller.Gamepad) || UtilitiesInput.isRThumbstickLeft)
|
|
{
|
|
Vector3 rotation = new Vector3(base.transform.eulerAngles.x, base.transform.eulerAngles.y - VRManager.Instance.turnAngle, base.transform.eulerAngles.z);
|
|
fishingPlayer.SetRotation(rotation);
|
|
}
|
|
else if (UtilitiesInput.GetButtonDown("VR_TURN_RIGHT") || OVRInput.GetDown(OVRInput.Button.SecondaryThumbstickRight, OVRInput.Controller.Gamepad) || UtilitiesInput.isRThumbstickRight)
|
|
{
|
|
Vector3 rotation2 = new Vector3(base.transform.eulerAngles.x, base.transform.eulerAngles.y + VRManager.Instance.turnAngle, base.transform.eulerAngles.z);
|
|
fishingPlayer.SetRotation(rotation2);
|
|
}
|
|
}
|
|
else if (VRManager.Instance.playerRotateStyle == VRManager.PlayerRotateStyle.FADE_STEP)
|
|
{
|
|
if (UtilitiesInput.GetButtonDown("VR_TURN_LEFT") || OVRInput.GetDown(OVRInput.Button.SecondaryThumbstickLeft, OVRInput.Controller.Gamepad) || UtilitiesInput.isRThumbstickLeft)
|
|
{
|
|
Vector3 eulerAngles = new Vector3(base.transform.eulerAngles.x, base.transform.eulerAngles.y - VRManager.Instance.turnAngle, base.transform.eulerAngles.z);
|
|
StartCoroutine(fishingPlayer.SetRotationFade(eulerAngles, VRManager.Instance.fadeDuration));
|
|
}
|
|
else if (UtilitiesInput.GetButtonDown("VR_TURN_RIGHT") || OVRInput.GetDown(OVRInput.Button.SecondaryThumbstickRight, OVRInput.Controller.Gamepad) || UtilitiesInput.isRThumbstickRight)
|
|
{
|
|
Vector3 eulerAngles2 = new Vector3(base.transform.eulerAngles.x, base.transform.eulerAngles.y + VRManager.Instance.turnAngle, base.transform.eulerAngles.z);
|
|
StartCoroutine(fishingPlayer.SetRotationFade(eulerAngles2, VRManager.Instance.fadeDuration));
|
|
}
|
|
}
|
|
else if (VRManager.Instance.playerRotateStyle == VRManager.PlayerRotateStyle.FREE && Mathf.Abs(UtilitiesInput.lookAxis.x) > 0.3f)
|
|
{
|
|
Vector3 rotation3 = new Vector3(base.transform.eulerAngles.x, base.transform.eulerAngles.y + VRManager.Instance.freeTurnSpeed * Time.deltaTime * UtilitiesInput.lookAxis.x, base.transform.eulerAngles.z);
|
|
fishingPlayer.SetRotation(rotation3);
|
|
}
|
|
}
|
|
|
|
public void Enable(MonoBehaviour context, bool enabled, Action onFadeOut, Action onFadingIn)
|
|
{
|
|
context.StopAllCoroutines();
|
|
context.StartCoroutine(EnableCoroutine(enabled, onFadeOut, onFadingIn));
|
|
}
|
|
|
|
private IEnumerator EnableCoroutine(bool enabled, Action onFadeOut, Action onFadingIn)
|
|
{
|
|
if (!enabled)
|
|
{
|
|
base.enabled = false;
|
|
vrPointer.SetActive(false);
|
|
vrTeleport.SetActive(false);
|
|
}
|
|
OVRScreenFade.instance.FadeOut();
|
|
yield return new WaitForSeconds(OVRScreenFade.instance.fadeTime);
|
|
if (enabled)
|
|
{
|
|
base.enabled = true;
|
|
vrPointer.SetActive(true);
|
|
vrTeleport.SetActive(true);
|
|
base.gameObject.SetActive(true);
|
|
}
|
|
if (onFadeOut != null)
|
|
{
|
|
onFadeOut();
|
|
}
|
|
yield return new WaitForSeconds(fadedOutTime);
|
|
if (!enabled)
|
|
{
|
|
base.gameObject.SetActive(enabled);
|
|
}
|
|
if (onFadingIn != null)
|
|
{
|
|
onFadingIn();
|
|
}
|
|
OVRScreenFade.instance.FadeIn();
|
|
}
|
|
}
|