89 lines
2.3 KiB
C#
89 lines
2.3 KiB
C#
using UnityEngine;
|
|
|
|
public class FloorPlanCameraController : MonoBehaviour
|
|
{
|
|
[Header("Speed Settings")]
|
|
public float panSpeed = 20f; // 이동 속도
|
|
public float rotationSpeed = 2f; // 회전 속도
|
|
public float zoomSpeed = 50f; // 줌 속도
|
|
|
|
[Header("Zoom Limits")]
|
|
public float minZoom = 5f;
|
|
public float maxZoom = 100f;
|
|
|
|
private Vector3 lastMousePosition;
|
|
private Camera cam;
|
|
|
|
void Awake()
|
|
{
|
|
cam = GetComponent<Camera>();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
HandlePan();
|
|
HandleRotation();
|
|
HandleZoom();
|
|
}
|
|
|
|
void HandlePan()
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
lastMousePosition = Input.mousePosition;
|
|
}
|
|
|
|
if (Input.GetMouseButton(0))
|
|
{
|
|
Vector3 delta = Input.mousePosition - lastMousePosition;
|
|
|
|
Vector3 move = new Vector3(-delta.x, -delta.y, 0) * panSpeed * Time.deltaTime;
|
|
|
|
transform.Translate(move, Space.Self);
|
|
|
|
lastMousePosition = Input.mousePosition;
|
|
}
|
|
}
|
|
|
|
void HandleRotation()
|
|
{
|
|
if (Input.GetMouseButtonDown(1))
|
|
{
|
|
lastMousePosition = Input.mousePosition;
|
|
}
|
|
|
|
if (Input.GetMouseButton(1))
|
|
{
|
|
Vector3 delta = Input.mousePosition - lastMousePosition;
|
|
|
|
float yaw = delta.x * rotationSpeed * 0.1f;
|
|
float pitch = -delta.y * rotationSpeed * 0.1f;
|
|
|
|
Vector3 currentEuler = transform.eulerAngles;
|
|
|
|
transform.Rotate(Vector3.up, yaw, Space.World); // 월드 기준 좌우 회전
|
|
transform.Rotate(Vector3.right, pitch, Space.Self); // 로컬 기준 상하 회전
|
|
|
|
lastMousePosition = Input.mousePosition;
|
|
}
|
|
}
|
|
|
|
void HandleZoom()
|
|
{
|
|
float scroll = Input.GetAxis("Mouse ScrollWheel");
|
|
if (scroll == 0) return;
|
|
|
|
if (cam.orthographic)
|
|
{
|
|
// Orthographic(2D 뷰)일 때
|
|
cam.orthographicSize -= scroll * zoomSpeed;
|
|
cam.orthographicSize = Mathf.Clamp(cam.orthographicSize, minZoom, maxZoom);
|
|
}
|
|
else
|
|
{
|
|
// Perspective(원근감)일 때 FOV 조절
|
|
cam.fieldOfView -= scroll * zoomSpeed * 2f;
|
|
cam.fieldOfView = Mathf.Clamp(cam.fieldOfView, 10f, 90f);
|
|
}
|
|
}
|
|
} |