Debug camera for neighborhood view

This commit is contained in:
Nahuel Rocchetti 2023-06-24 03:26:27 -03:00
parent 942c19536d
commit d558950971
3 changed files with 110 additions and 1 deletions

View file

@ -575,6 +575,7 @@ GameObject:
- component: {fileID: 1642340383}
- component: {fileID: 1642340382}
- component: {fileID: 1642340381}
- component: {fileID: 1642340384}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
@ -641,9 +642,26 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1642340380}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalPosition: {x: 600, y: 450, z: 600}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1642340384
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1642340380}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 736deb7fdc898e84e9c0d76a5dafa65f, type: 3}
m_Name:
m_EditorClassIdentifier:
MaximumFOV: 150
MinimumFOV: 5
ZoomSpeed: 75
Speed: 200
Sensitivity: 5

View file

@ -0,0 +1,80 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Camera))]
public class DebugCameraController : MonoBehaviour
{
public float MaximumFOV = 100f;
public float MinimumFOV = 10f;
public float ZoomSpeed = 5f;
public float Speed = 10f;
public float Sensitivity = 5f;
bool CursorLocked
{
get
{
return Cursor.lockState == CursorLockMode.Locked;
}
set
{
if (value)
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
else
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}
}
float FOV
{
get
{
return _camera.fieldOfView;
}
set
{
_camera.fieldOfView = value;
}
}
float _rotationX = 0f;
float _rotationY = 0f;
Camera _camera;
private void Start()
{
_camera = GetComponent<Camera>();
CursorLocked = true;
}
void Update()
{
if (CursorLocked)
{
var currentSpeed = Speed * (Input.GetKey(KeyCode.LeftShift) ? 2f : 1f);
var forwardAxis = (Input.GetKey(KeyCode.W) ? 1f : 0f) - (Input.GetKey(KeyCode.S) ? 1f : 0f);
var rightAxis = (Input.GetKey(KeyCode.D) ? 1f : 0f) - (Input.GetKey(KeyCode.A) ? 1f : 0f);
var mouseX = Input.GetAxisRaw("Mouse X");
var mouseY = Input.GetAxisRaw("Mouse Y");
_rotationY += mouseX * Sensitivity;
_rotationX -= mouseY * Sensitivity;
_rotationX = Mathf.Clamp(_rotationX, -90f, 90f);
transform.rotation = Quaternion.Euler(_rotationX, _rotationY, 0f);
transform.position += transform.forward * forwardAxis * currentSpeed * Time.deltaTime;
transform.position += transform.right * rightAxis * currentSpeed * Time.deltaTime;
}
if (Input.GetKeyDown(KeyCode.LeftControl))
CursorLocked = !CursorLocked;
var fov = FOV;
fov -= (Input.GetKey(KeyCode.Z) ? 1f : 0f) * ZoomSpeed * Time.deltaTime;
fov += (Input.GetKey(KeyCode.X) ? 1f : 0f) * ZoomSpeed * Time.deltaTime;
FOV = Mathf.Clamp(fov, MinimumFOV, MaximumFOV);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 736deb7fdc898e84e9c0d76a5dafa65f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: