parent
e6ad4a32d7
commit
2dbd212481
|
@ -1,3 +1,5 @@
|
|||
using System;
|
||||
using Unity.VisualScripting.Dependencies.NCalc;
|
||||
using UnityEngine;
|
||||
#if ENABLE_INPUT_SYSTEM && STARTER_ASSETS_PACKAGES_CHECKED
|
||||
using UnityEngine.InputSystem;
|
||||
|
@ -14,12 +16,26 @@ namespace StarterAssets
|
|||
public bool _sprint;
|
||||
|
||||
[Header("Movement Settings")]
|
||||
[SerializeField] private float _mouseScale;
|
||||
public bool _analogMovement;
|
||||
|
||||
[Header("Mouse Cursor Settings")]
|
||||
public bool _cursorLocked = true;
|
||||
public bool _cursorInputForLook = true;
|
||||
|
||||
public float MouseScale
|
||||
{
|
||||
get => _mouseScale;
|
||||
set => _mouseScale = value;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_mouseScale = 1;
|
||||
_cursorLocked = true;
|
||||
SetCursorState();
|
||||
}
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM && STARTER_ASSETS_PACKAGES_CHECKED
|
||||
public void OnMove(InputValue value)
|
||||
{
|
||||
|
@ -32,7 +48,7 @@ namespace StarterAssets
|
|||
{
|
||||
if (Time.timeScale > 0)
|
||||
{
|
||||
LookInput(value.Get<Vector2>());
|
||||
LookInput(_mouseScale * value.Get<Vector2>());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -58,12 +74,6 @@ namespace StarterAssets
|
|||
}
|
||||
#endif
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_cursorLocked = true;
|
||||
SetCursorState();
|
||||
}
|
||||
|
||||
public void MoveInput(Vector2 newMoveDirection)
|
||||
{
|
||||
_move = newMoveDirection;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using Cinemachine;
|
||||
using StarterAssets;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
@ -9,13 +10,17 @@ public class WeaponZoom : MonoBehaviour
|
|||
{
|
||||
[Header("Configuration")]
|
||||
[SerializeField] private float _fovNormal;
|
||||
[SerializeField] private float _senseNormal;
|
||||
[SerializeField] private float _fovZoom;
|
||||
[SerializeField] private float _senseZoom;
|
||||
[SerializeField] private StarterAssetsInputs _input;
|
||||
[Header("State")]
|
||||
[SerializeField] private CinemachineVirtualCamera _camera;
|
||||
[SerializeField] private bool _zoomedIn;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_input = GetComponent<StarterAssetsInputs>();
|
||||
_camera = FindObjectOfType<CinemachineVirtualCamera>();
|
||||
Debug.Assert(_camera != null, nameof(_camera) + " != null");
|
||||
_fovNormal = _camera.m_Lens.FieldOfView;
|
||||
|
@ -23,18 +28,18 @@ public class WeaponZoom : MonoBehaviour
|
|||
|
||||
private void Update()
|
||||
{
|
||||
if (Mouse.current.rightButton.wasPressedThisFrame)
|
||||
{
|
||||
_zoomedIn = !_zoomedIn;
|
||||
}
|
||||
|
||||
if (!Mouse.current.rightButton.wasPressedThisFrame) return;
|
||||
_zoomedIn = !_zoomedIn;
|
||||
if (_zoomedIn)
|
||||
{
|
||||
_input.MouseScale = _senseZoom;
|
||||
_camera.m_Lens.FieldOfView = _fovZoom;
|
||||
}
|
||||
else
|
||||
{
|
||||
_input.MouseScale = _senseNormal;
|
||||
_camera.m_Lens.FieldOfView = _fovNormal;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue