Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.InputSystem;
- public class CameraMovement : MonoBehaviour {
- public float movementSensitivity = 20f;
- public float rotationSensitivity = 20f;
- public float panSensitivity = 20f;
- private Vector2 m_inputMouseMoveDelta;
- private Vector2 m_inputMove;
- private float m_verticalMove;
- private bool m_CameraMoveFlag = false;
- private bool m_CameraPanFlag = false;
- public void SetCameraMoveFlag( InputAction.CallbackContext context ) {
- switch ( context.phase ) {
- case InputActionPhase.Started:
- case InputActionPhase.Performed:
- m_CameraMoveFlag = true;
- break;
- default:
- m_CameraMoveFlag = false;
- break;
- }
- }
- public void SetCameraPanFlag( InputAction.CallbackContext context ) {
- switch ( context.phase ) {
- case InputActionPhase.Started:
- case InputActionPhase.Performed:
- m_CameraPanFlag = true;
- break;
- default:
- m_CameraPanFlag = false;
- break;
- }
- }
- public void SetCameraMove( InputAction.CallbackContext context ) => m_inputMove = context.canceled ? Vector2.zero : context.ReadValue<Vector2> ();
- public void SetMouseMoveDelta( InputAction.CallbackContext context ) => m_inputMouseMoveDelta = context.canceled ? Vector2.zero : context.ReadValue<Vector2> ();
- public void SetVerticalMove( InputAction.CallbackContext context ) => m_verticalMove = context.canceled ? 0f : context.ReadValue<float> ();
- void Update() {
- Rotation ();
- Move ();
- Pan ();
- }
- private void Rotation() {
- if ( m_CameraMoveFlag ) {
- transform.Rotate ( Vector3.up * m_inputMouseMoveDelta.x * rotationSensitivity * Time.deltaTime, Space.World );
- transform.Rotate ( Vector3.left * m_inputMouseMoveDelta.y * rotationSensitivity * Time.deltaTime, Space.Self );
- }
- }
- private void Move () {
- if ( m_CameraMoveFlag ) {
- transform.position += ( transform.right * m_inputMove.x + transform.forward * m_inputMove.y ) * Time.deltaTime * movementSensitivity;
- transform.position += transform.up * Time.deltaTime * movementSensitivity * m_verticalMove;
- }
- }
- private void Pan() {
- if ( m_CameraPanFlag ) {
- transform.position -= ( transform.right * m_inputMouseMoveDelta.x + transform.up * m_inputMouseMoveDelta.y ) * Time.deltaTime * panSensitivity;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement