단축키, UndoRedo 일단 완료
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db5fa9d863041c147a4bca71f282b241
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,543 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UVC.Core;
|
||||
|
||||
namespace UVC.Studio.Cameras
|
||||
{
|
||||
/// <summary>
|
||||
/// 마우스 입력에 따라 카메라를 이동, 회전, 줌하는 컨트롤러입니다.
|
||||
/// - 마우스 가운데 버튼 드래그: 카메라 평행 이동 (Pan)
|
||||
/// - 마우스 오른쪽 버튼 드래그: 카메라 회전 (Orbit)
|
||||
/// - 마우스 휠 스크롤: 카메라 줌 (Zoom)
|
||||
/// </summary>
|
||||
public class StudioCameraController : SingletonScene<StudioCameraController>
|
||||
{
|
||||
[Header("Panning Speed")]
|
||||
[Tooltip("카메라 높이가 임계값보다 낮을 때의 평행 이동 속도")]
|
||||
[SerializeField]
|
||||
private float lowAltitudePanSpeed = 0.5f;
|
||||
|
||||
[Tooltip("카메라 높이가 임계값보다 높을 때의 평행 이동 속도")]
|
||||
[SerializeField]
|
||||
private float highAltitudePanSpeed = 10f;
|
||||
|
||||
[Tooltip("카메라 회전 속도")]
|
||||
[SerializeField]
|
||||
private float rotationSpeed = 300f;
|
||||
|
||||
[Tooltip("카메라 줌 속도")]
|
||||
[SerializeField]
|
||||
private float zoomSpeed = 10f;
|
||||
|
||||
[Header("Movement Smoothing")]
|
||||
[Tooltip("패닝 시 마우스 이동량의 최대값을 제한하여, 프레임 드랍 시 카메라가 급격하게 튀는 현상을 방지합니다.")]
|
||||
[SerializeField]
|
||||
private float maxPanDelta = 50f;
|
||||
|
||||
[Header("Camera")]
|
||||
[Tooltip("카메라 최소 높이")]
|
||||
[SerializeField]
|
||||
private float minCameraY = 2f;
|
||||
|
||||
[Tooltip("카메라 최대 높이")]
|
||||
[SerializeField]
|
||||
private float maxCameraY = 80f;
|
||||
|
||||
[Tooltip("카메라의 최소 수직 회전 각도 (X축)")]
|
||||
[SerializeField]
|
||||
private float minPitch = 20f;
|
||||
|
||||
[Tooltip("카메라의 최대 수직 회전 각도 (X축)")]
|
||||
[SerializeField]
|
||||
private float maxPitch = 85f;
|
||||
|
||||
[Tooltip("카메라의 최소 수평 회전 각도 (y축)")]
|
||||
[SerializeField]
|
||||
private float minYaw = -45f;
|
||||
|
||||
[Tooltip("카메라의 최대 수평 회전 각도 (y축)")]
|
||||
[SerializeField]
|
||||
private float maxYaw = 45f;
|
||||
|
||||
[Tooltip("마우스를 이용 한 회전 사용 여부")]
|
||||
[SerializeField]
|
||||
public bool EnabledRotation = true;
|
||||
|
||||
[Tooltip("마우스를 이용 한 확대/축소 사용 여부")]
|
||||
[SerializeField]
|
||||
public bool EnabledZoom = true;
|
||||
|
||||
/// <summary>
|
||||
/// 카메라의 변형이 변경될 때 발생합니다.
|
||||
/// </summary>
|
||||
/// <remarks>이 이벤트는 카메라의 변형이 업데이트될 때마다 트리거되며,
|
||||
/// 구독자는 위치, 회전 또는 크기 변경에 응답할 수 있습니다. 이 이벤트를 사용하여
|
||||
/// UI 요소 업데이트 또는 종속 값 재계산과 같은 작업을 수행할 수 있습니다.</remarks>
|
||||
public Action<Transform> OnCameraChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 카메라 위치가 변경될 때 발생합니다.
|
||||
/// </summary>
|
||||
/// <remarks>이 이벤트는 카메라 위치가 업데이트될 때마다 트리거됩니다. 구독자는
|
||||
/// 이 이벤트를 사용하여 UI 요소를 업데이트하거나 새 위치를 기반으로 계산을 수행하는 등 카메라 위치 변경에 대응할 수 있습니다.
|
||||
///</remarks>
|
||||
public Action<Vector3> OnCameraPositionChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 카메라 높이가 변경될 때 발생합니다.
|
||||
/// </summary>
|
||||
/// <remarks>이 이벤트는 카메라 높이가 업데이트될 때마다 트리거됩니다. 구독자는
|
||||
/// 이 이벤트를 사용하여 UI 요소를 업데이트하거나 새 높이를 기반으로 계산을 수행하는 등 카메라 높이 변경에 대응할 수 있습니다.
|
||||
///</remarks>
|
||||
public Action<float> OnCameraPositionUpChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 카메라의 회전이 변경될 때 발생합니다.
|
||||
/// </summary>
|
||||
/// <remarks>이 이벤트는 카메라의 회전이 업데이트될 때마다 트리거됩니다. 구독자는
|
||||
/// 이 이벤트를 사용하여 카메라 방향의 변경에 응답할 수 있습니다.</remarks>
|
||||
public Action<Quaternion> OnCameraRotationChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 정의된 범위 내에서 카메라의 정규화된 수직 위치를 가져옵니다.
|
||||
/// </summary>
|
||||
/// <remarks>값은 카메라의 현재 수직 위치를 기반으로 계산되며
|
||||
/// [0, 1] 범위로 고정됩니다.</remarks>
|
||||
public float CameraYRate
|
||||
{
|
||||
get
|
||||
{
|
||||
// 카메라 높이에 따라 0~1 사이의 값을 반환합니다.
|
||||
return Mathf.Clamp01((transform.position.y - minCameraY) / (maxCameraY - minCameraY));
|
||||
}
|
||||
}
|
||||
|
||||
private Quaternion prevRotation; // 이전 카메라 각도
|
||||
private Vector3 prevPosition; // 이전 카메라 위치
|
||||
|
||||
private Vector3 lastPanPosition;
|
||||
private Vector3 rotationPivot;
|
||||
private bool isRotating = false;
|
||||
|
||||
private Coroutine focusCoroutine; // 현재 실행 중인 포커싱 코루틴을 저장할 변수
|
||||
|
||||
public bool Enable = false; // 카메라 컨트롤 활성화 여부
|
||||
|
||||
void Start()
|
||||
{
|
||||
// 스크립트 시작 시, 회전의 기준이 되는 중심점을 카메라 앞쪽으로 초기화합니다.
|
||||
rotationPivot = transform.position + transform.forward * 10f;
|
||||
this.prevRotation = transform.rotation; // 초기 카메라 각도 저장
|
||||
this.prevPosition = transform.position; // 초기 카메라 위치 저장
|
||||
}
|
||||
|
||||
private void StopFocusCoroutine()
|
||||
{
|
||||
if (focusCoroutine != null)
|
||||
{
|
||||
StopCoroutine(focusCoroutine);
|
||||
focusCoroutine = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void DispatchEvnet()
|
||||
{
|
||||
if (prevPosition != transform.position || prevRotation != transform.rotation)
|
||||
{
|
||||
OnCameraChanged?.Invoke(transform);
|
||||
if (prevPosition != transform.position)
|
||||
{
|
||||
OnCameraPositionChanged?.Invoke(transform.position);
|
||||
if (prevPosition.y < transform.position.y) OnCameraPositionUpChanged?.Invoke(transform.position.y - prevPosition.y);
|
||||
}
|
||||
if (prevRotation != transform.rotation)
|
||||
{
|
||||
OnCameraRotationChanged?.Invoke(transform.rotation);
|
||||
}
|
||||
}
|
||||
prevRotation = transform.rotation; // 현재 카메라 각도 저장
|
||||
prevPosition = transform.position; // 현재 카메라 위치 저장
|
||||
}
|
||||
|
||||
private void ValidateCameraTransform()
|
||||
{
|
||||
// 카메라의 위치가 최소/최대 높이 범위를 벗어나지 않도록 합니다.
|
||||
Vector3 currentPosition = transform.position;
|
||||
currentPosition.y = Mathf.Clamp(currentPosition.y, minCameraY, maxCameraY);
|
||||
transform.position = currentPosition;
|
||||
ValidateCameraRotation();
|
||||
|
||||
// 카메라의 위치가 너무 멀리 떨어지지 않도록 합니다.
|
||||
//float distance = Vector3.Distance(transform.position, rotationPivot);
|
||||
//if (distance > 100f) // 예시로 100f를 최대 거리로 설정
|
||||
//{
|
||||
// transform.position = rotationPivot + (transform.position - rotationPivot).normalized * 100f;
|
||||
//}
|
||||
}
|
||||
|
||||
private void ValidateCameraRotation()
|
||||
{
|
||||
// 현재 회전값을 오일러 각으로 가져옵니다.
|
||||
Vector3 eulerAngles = transform.eulerAngles;
|
||||
// 오일러 각의 X축(Pitch) 값을 정규화하고 제한합니다.
|
||||
// 각도가 180도를 넘어가면 음수 값으로 변환하여 처리합니다. (예: 350도 -> -10도)
|
||||
float angleX = eulerAngles.x;
|
||||
if (angleX > 180f) angleX -= 360f;
|
||||
angleX = Mathf.Clamp(angleX, minPitch, maxPitch);
|
||||
eulerAngles.x = angleX;
|
||||
|
||||
float angleY = eulerAngles.y;
|
||||
if (angleY > 180f) angleY -= 360f;
|
||||
angleY = Mathf.Clamp(angleY, minYaw, maxYaw);
|
||||
eulerAngles.y = angleY;
|
||||
|
||||
// Z축 회전(롤)을 0으로 설정하여 카메라가 옆으로 기울어지는 것을 방지합니다.
|
||||
eulerAngles.z = 0f;
|
||||
|
||||
// 수정된 오일러 각을 다시 쿼터니언으로 변환하여 적용합니다.
|
||||
transform.rotation = Quaternion.Euler(eulerAngles);
|
||||
}
|
||||
|
||||
private Quaternion ValidateRotation(Quaternion rotation)
|
||||
{
|
||||
// 현재 회전값을 오일러 각으로 가져옵니다.
|
||||
Vector3 eulerAngles = rotation.eulerAngles;
|
||||
// 오일러 각의 X축(Pitch) 값을 정규화하고 제한합니다.
|
||||
// 각도가 180도를 넘어가면 음수 값으로 변환하여 처리합니다. (예: 350도 -> -10도)
|
||||
float angleX = eulerAngles.x;
|
||||
if (angleX > 180f) angleX -= 360f;
|
||||
angleX = Mathf.Clamp(angleX, minPitch, maxPitch);
|
||||
eulerAngles.x = angleX;
|
||||
|
||||
float angleY = eulerAngles.y;
|
||||
if (angleY > 180f) angleY -= 360f;
|
||||
angleY = Mathf.Clamp(angleY, minYaw, maxYaw);
|
||||
eulerAngles.y = angleY;
|
||||
|
||||
// Z축 회전(롤)을 0으로 설정하여 카메라가 옆으로 기울어지는 것을 방지합니다.
|
||||
eulerAngles.z = 0f;
|
||||
|
||||
// 수정된 오일러 각을 다시 쿼터니언으로 변환하여 적용합니다.
|
||||
return Quaternion.Euler(eulerAngles);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Update 대신 LateUpdate를 사용하여 카메라 움직임이 다른 모든 업데이트 이후에 처리되도록 합니다.
|
||||
// 이를 통해 카메라의 떨림이나 끊김 현상을 줄일 수 있습니다.
|
||||
void LateUpdate()
|
||||
{
|
||||
if (!Enable) return; // 카메라 컨트롤이 비활성화된 경우, 업데이트를 건너뜁니다.
|
||||
HandlePanning();
|
||||
if (EnabledRotation) HandleRotation();
|
||||
if (EnabledZoom) HandleZoom();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 마우스 가운데 버튼으로 카메라를 평행 이동시킵니다.
|
||||
/// 프레임 지연으로 인한 급격한 이동을 방지하기 위해 이동량을 제한합니다.
|
||||
/// </summary>
|
||||
private void HandlePanning()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(2))
|
||||
{
|
||||
StopFocusCoroutine();
|
||||
lastPanPosition = Input.mousePosition;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButton(2))
|
||||
{
|
||||
Vector3 delta = Input.mousePosition - lastPanPosition;
|
||||
|
||||
// 프레임 드랍 시 델타 값이 너무 커져서 카메라가 튀는 것을 방지하기 위해 최대값을 제한합니다.
|
||||
if (delta.magnitude > maxPanDelta)
|
||||
{
|
||||
delta = delta.normalized * maxPanDelta;
|
||||
}
|
||||
|
||||
// 높이에 따라 동적으로 패닝 속도 결정.
|
||||
float currentPanSpeed = Mathf.Lerp(lowAltitudePanSpeed, highAltitudePanSpeed, CameraYRate); // 현재 카메라 높이에 따라 패닝 속도를 보간합니다.
|
||||
|
||||
// 카메라의 로컬 좌표계를 기준으로 이동 방향을 계산합니다.
|
||||
Vector3 moveDirection = (transform.right * -delta.x) + (transform.forward * -delta.y);
|
||||
moveDirection.y = 0; // Y축 이동을 막습니다.
|
||||
|
||||
// 계산된 방향으로 카메라를 이동시킵니다.
|
||||
transform.Translate(moveDirection.normalized * delta.magnitude * currentPanSpeed * Time.deltaTime, Space.World);
|
||||
|
||||
ValidateCameraTransform();
|
||||
|
||||
lastPanPosition = Input.mousePosition;
|
||||
DispatchEvnet();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 마우스 오른쪽 버튼으로 카메라를 회전시킵니다.
|
||||
/// 회전 축이 변하는 것을 방지하여 안정적인 회전을 구현합니다.
|
||||
/// </summary>
|
||||
private void HandleRotation()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
StopFocusCoroutine();
|
||||
isRotating = true;
|
||||
// 마우스 클릭 지점으로 Ray를 쏴서 회전의 중심점(pivot)을 설정합니다.
|
||||
Ray ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 1000f))
|
||||
{
|
||||
rotationPivot = hit.point;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ray가 아무 오브젝트에도 맞지 않았다면, 카메라 앞쪽의 특정 거리를 중심점으로 사용합니다.
|
||||
rotationPivot = transform.position + transform.forward * 10f;
|
||||
}
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonUp(1))
|
||||
{
|
||||
isRotating = false;
|
||||
}
|
||||
|
||||
if (isRotating && Input.GetMouseButton(1))
|
||||
{
|
||||
float mouseX = Input.GetAxis("Mouse X") * rotationSpeed * Time.deltaTime;
|
||||
float mouseY = Input.GetAxis("Mouse Y") * rotationSpeed * Time.deltaTime;
|
||||
|
||||
// 현재 X축 회전 각도를 가져와서 -180 ~ 180 범위로 정규화합니다.
|
||||
float currentPitch = transform.eulerAngles.x;
|
||||
if (currentPitch > 180f) currentPitch -= 360f;
|
||||
|
||||
// 현재 Y축 회전 각도를 가져와서 -180 ~ 180 범위로 정규화합니다.
|
||||
float currentYaw = transform.eulerAngles.y;
|
||||
if (currentYaw > 180f) currentYaw -= 360f;
|
||||
|
||||
// 마우스 입력으로 인해 Pitch 또는 Yaw 각도가 한계를 벗어나는지 확인합니다.
|
||||
if ((mouseY > 0 && currentPitch >= maxPitch) || (mouseY < 0 && currentPitch <= minPitch)
|
||||
|| (mouseX < 0 && currentYaw >= maxYaw) || (mouseX > 0 && currentYaw <= minYaw))
|
||||
{
|
||||
return; // 한계를 넘어서는 회전은 막습니다.
|
||||
}
|
||||
|
||||
// 수평 회전으로 인해 수직 회전 축(transform.right)이 변질되는 것을 방지하기 위해
|
||||
// 회전 전의 right 벡터를 미리 저장해 둡니다.
|
||||
Vector3 verticalRotationAxis = transform.right;
|
||||
|
||||
// 설정된 중심점을 기준으로 카메라를 회전시킵니다.
|
||||
// 1. 수평 회전 (월드 Y축 기준)
|
||||
transform.RotateAround(rotationPivot, Vector3.up, -mouseX);
|
||||
// 2. 수직 회전 (미리 저장해 둔 카메라의 오른쪽 축 기준)
|
||||
transform.RotateAround(rotationPivot, verticalRotationAxis, mouseY);
|
||||
|
||||
ValidateCameraTransform();
|
||||
|
||||
DispatchEvnet();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 마우스 휠로 카메라를 줌 인/아웃합니다.
|
||||
/// </summary>
|
||||
private void HandleZoom()
|
||||
{
|
||||
float scroll = Input.GetAxis("Mouse ScrollWheel");
|
||||
if (scroll != 0f)
|
||||
{
|
||||
// 현재 X축 회전 각도를 확인하여 한계 범위 밖이면 줌을 막습니다.
|
||||
float currentPitch = transform.eulerAngles.x;
|
||||
if (currentPitch > 180f) currentPitch -= 360f;
|
||||
if (currentPitch < minPitch || currentPitch > maxPitch) return;
|
||||
|
||||
Ray ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
Vector3 zoomTarget;
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit))
|
||||
{
|
||||
zoomTarget = hit.point;
|
||||
}
|
||||
else
|
||||
{
|
||||
zoomTarget = ray.GetPoint(1000);
|
||||
}
|
||||
|
||||
Vector3 direction = zoomTarget - transform.position;
|
||||
Vector3 moveVector = direction.normalized * scroll * zoomSpeed;
|
||||
|
||||
// 카메라가 아래로 움직이려 하고(moveVector.y < 0), 이미 최소 높이에 도달했다면 중단합니다.
|
||||
if (moveVector.y < 0 && transform.position.y <= minCameraY) return;
|
||||
|
||||
// 카메라가 위로 움직이려 하고(moveVector.y > 0), 이미 최대 높이에 도달했다면 중단합니다.
|
||||
if (moveVector.y > 0 && transform.position.y >= maxCameraY) return;
|
||||
|
||||
StopFocusCoroutine();
|
||||
|
||||
// 줌 실행
|
||||
transform.position += direction.normalized * scroll * zoomSpeed;
|
||||
|
||||
ValidateCameraTransform();
|
||||
|
||||
DispatchEvnet();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 지정된 Transform을 중심으로 카메라를 포커싱합니다.
|
||||
/// </summary>
|
||||
/// <param name="equipmentPosition">포커스할 대상의 Transform</param>
|
||||
/// <param name="distance">대상과의 거리</param>
|
||||
public void FocusOnTargetFast(Vector3 equipmentPosition, float distance)
|
||||
{
|
||||
if (equipmentPosition == null) return;
|
||||
|
||||
Vector3 position = equipmentPosition;
|
||||
if (position.y < minCameraY)
|
||||
{
|
||||
position.y = minCameraY; // 최소 높이 제한
|
||||
}
|
||||
else if (position.y > maxCameraY)
|
||||
{
|
||||
position.y = maxCameraY; // 최대 높이 제한
|
||||
}
|
||||
|
||||
|
||||
// 카메라가 바라볼 대상의 중심점
|
||||
Vector3 targetPosition = equipmentPosition;
|
||||
|
||||
// 현재 카메라의 회전각을 유지하면서 타겟을 바라보는 방향 설정
|
||||
Vector3 directionToTarget = (targetPosition - transform.position).normalized;
|
||||
|
||||
// 타겟으로부터 지정된 거리만큼 떨어진 위치 계산
|
||||
Vector3 newPosition = targetPosition - directionToTarget * distance;
|
||||
|
||||
// 카메라 위치 설정 및 타겟을 바라보도록 함
|
||||
transform.position = newPosition;
|
||||
transform.LookAt(targetPosition);
|
||||
|
||||
// 회전 피봇 포인트 업데이트
|
||||
rotationPivot = targetPosition;
|
||||
|
||||
ValidateCameraTransform();
|
||||
|
||||
DispatchEvnet();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 지정된 Transform을 중심으로 카메라를 포커싱합니다.
|
||||
/// </summary>
|
||||
/// <param name="equipmentPosition">포커스할 대상의 Transform</param>
|
||||
/// <param name="distance">대상과의 거리</param>
|
||||
/// <param name="duration">이동에 걸리는 시간(초), 기본값 1초</param>
|
||||
public void FocusOnTarget(Vector3 equipmentPosition, float distance, float cameraPitch = 45, float duration = 1.0f, bool keepYRotation = true)
|
||||
{
|
||||
if (equipmentPosition == null) return;
|
||||
|
||||
StopFocusCoroutine();
|
||||
|
||||
Vector3 position = equipmentPosition;
|
||||
if (position.y < minCameraY)
|
||||
{
|
||||
position.y = minCameraY; // 최소 높이 제한
|
||||
}
|
||||
else if (position.y > maxCameraY)
|
||||
{
|
||||
position.y = maxCameraY; // 최대 높이 제한
|
||||
}
|
||||
|
||||
// 코루틴을 사용하여 부드러운 이동 구현
|
||||
focusCoroutine = StartCoroutine(SmoothFocusOnTarget(position, distance, cameraPitch, duration, keepYRotation));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 카메라를 앞쪽 방향으로 지정된 거리만큼 바깥쪽으로 부드럽게 이동합니다.
|
||||
/// </summary>
|
||||
/// <remarks>이 메서드는 코루틴을 사용하여 카메라의 위치를 앞쪽 방향으로 바깥쪽으로 부드럽게 전환합니다.
|
||||
/// 전환은 지정된 시간 동안 수행되므로
|
||||
/// 시각적으로 부드러운 움직임을 구현할 수 있습니다.</remarks>
|
||||
/// <param name="distance">카메라를 현재 위치에서 바깥쪽으로 이동할 거리(단위)입니다.</param>
|
||||
/// <param name="duration">카메라 전환이 발생하는 시간(초)입니다. 기본값은 1.0초입니다.</param>
|
||||
public void FocusOut(float distance, float cameraPitch = 45, float duration = 1.0f)
|
||||
{
|
||||
|
||||
StopFocusCoroutine();
|
||||
|
||||
// 현재 카메라 위치와 회전값을 저장
|
||||
Vector3 startPosition = transform.position;
|
||||
Quaternion startRotation = transform.rotation;
|
||||
// 카메라가 바라보는 방향으로 지정된 거리만큼 이동
|
||||
Vector3 targetPosition = transform.position + transform.forward * distance;
|
||||
// 코루틴을 사용하여 부드러운 이동 구현
|
||||
focusCoroutine = StartCoroutine(SmoothFocusOnTarget(targetPosition, distance, cameraPitch, duration));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 부드럽게 타겟까지 이동하는 코루틴
|
||||
/// </summary>
|
||||
private IEnumerator SmoothFocusOnTarget(Vector3 targetTransform, float distance, float cameraPitch, float duration, bool keepYRotation = true)
|
||||
{
|
||||
// 카메라가 바라볼 대상의 중심점
|
||||
Vector3 targetPosition = targetTransform;
|
||||
|
||||
// 시작 위치와 회전 저장
|
||||
Vector3 startPosition = transform.position;
|
||||
Quaternion startRotation = transform.rotation;
|
||||
|
||||
// 최종 회전값 계산
|
||||
// keepYRotation 플래그에 따라 Y축 회전값을 결정합니다.
|
||||
float targetYaw = keepYRotation ? startRotation.eulerAngles.y : Quaternion.LookRotation(targetPosition - startPosition).eulerAngles.y;
|
||||
Quaternion endRotation = Quaternion.Euler(cameraPitch, targetYaw, 0);
|
||||
|
||||
// 최종 위치 계산: 목표 지점에서 지정된 거리만큼, 계산된 최종 회전 방향의 반대쪽으로 이동합니다.
|
||||
Vector3 endPosition = targetPosition - (endRotation * Vector3.forward) * distance;
|
||||
|
||||
// 회전값 검증 및 수정
|
||||
endRotation = ValidateRotation(endRotation);
|
||||
|
||||
// 이동 시간 계산을 위한 변수
|
||||
float elapsedTime = 0f;
|
||||
|
||||
while (elapsedTime < duration)
|
||||
{
|
||||
elapsedTime += Time.deltaTime;
|
||||
float t = Mathf.Clamp01(elapsedTime / duration);
|
||||
|
||||
// 부드러운 이동을 위한 Easing 함수 적용
|
||||
float smoothT = EaseInOutCubic(t);
|
||||
|
||||
// 위치와 회전 보간
|
||||
transform.position = Vector3.Lerp(startPosition, endPosition, smoothT);
|
||||
transform.rotation = Quaternion.Slerp(startRotation, endRotation, smoothT);
|
||||
|
||||
ValidateCameraTransform();
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// 정확한 최종 위치와 회전 설정
|
||||
transform.position = endPosition;
|
||||
transform.rotation = endRotation;
|
||||
|
||||
// 회전 피봇 포인트 업데이트
|
||||
rotationPivot = targetPosition;
|
||||
|
||||
ValidateCameraTransform();
|
||||
|
||||
DispatchEvnet();
|
||||
focusCoroutine = null; // 코루틴 완료 후 참조를 null로 설정
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cubic ease-in/out 함수로 부드러운 이동 효과를 줍니다.
|
||||
/// </summary>
|
||||
private float EaseInOutCubic(float t)
|
||||
{
|
||||
return t < 0.5f ? 4f * t * t * t : 1f - Mathf.Pow(-2f * t + 2f, 3f) / 2f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c058a2c1e8d0c514fbbdeff941c1fc72
|
||||
@@ -1,6 +1,8 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UVC.Core;
|
||||
using UVC.Studio.Manager;
|
||||
using UVC.UI.Commands;
|
||||
using UVC.UI.Window.PropertyWindow;
|
||||
|
||||
@@ -141,19 +143,48 @@ namespace UVC.Studio.Command
|
||||
_transform.localScale = value;
|
||||
break;
|
||||
}
|
||||
|
||||
// PropertyWindow UI 업데이트
|
||||
UpdatePropertyWindowUI(value);
|
||||
|
||||
// Gizmo 새로고침
|
||||
GizmoUndoBridge.Instance?.RefreshGizmos();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PropertyWindow UI를 업데이트합니다.
|
||||
/// </summary>
|
||||
private void UpdatePropertyWindowUI(Vector3 value)
|
||||
{
|
||||
if (InjectorAppContext.Instance == null) return;
|
||||
|
||||
var propertyWindow = InjectorAppContext.Instance.Get<PropertyWindow>();
|
||||
if (propertyWindow == null) return;
|
||||
|
||||
string propertyId = _propertyType switch
|
||||
{
|
||||
"position" => "transform_position",
|
||||
"rotation" => "transform_rotation",
|
||||
"scale" => "transform_scale",
|
||||
_ => ""
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(propertyId))
|
||||
{
|
||||
propertyWindow.SetPropertyValue(propertyId, value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanMerge(IUndoableCommand other)
|
||||
{
|
||||
// 같은 Transform의 같은 속성 변경은 병합
|
||||
return other is TransformPropertyChangeCommand otherCmd &&
|
||||
otherCmd._transform == _transform &&
|
||||
otherCmd._propertyType == _propertyType;
|
||||
// PropertyWindow에서의 변경은 각각 독립적인 Undo로 기록
|
||||
// (병합하면 중간 상태가 손실됨)
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Merge(IUndoableCommand other)
|
||||
{
|
||||
// 불변 객체이므로 실제 병합은 StudioHistoryManager에서 처리
|
||||
// 병합하지 않음
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,11 +41,6 @@ namespace UVC.Studio.Manager
|
||||
/// </summary>
|
||||
private readonly List<Transform> _dragTargets = new();
|
||||
|
||||
/// <summary>
|
||||
/// RTUndo 비활성화 여부 (UVC Undo 수행 중일 때)
|
||||
/// </summary>
|
||||
private bool _isUVCUndoRedoInProgress = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity Lifecycle
|
||||
@@ -57,12 +52,6 @@ namespace UVC.Studio.Manager
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// RTUndo 이벤트 구독 (RTGLite의 Undo/Redo 발생 시)
|
||||
if (RTUndo.get != null)
|
||||
{
|
||||
RTUndo.get.undoRedo += OnRTUndoRedo;
|
||||
}
|
||||
|
||||
// UVC UndoRedoManager 이벤트 구독
|
||||
if (UndoRedoManager.Instance != null)
|
||||
{
|
||||
@@ -99,12 +88,6 @@ namespace UVC.Studio.Manager
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
// 이벤트 구독 해제
|
||||
if (RTUndo.get != null)
|
||||
{
|
||||
RTUndo.get.undoRedo -= OnRTUndoRedo;
|
||||
}
|
||||
|
||||
if (UndoRedoManager.Instance != null)
|
||||
{
|
||||
UndoRedoManager.Instance.OnUndo -= OnUVCUndo;
|
||||
@@ -238,26 +221,7 @@ namespace UVC.Studio.Manager
|
||||
|
||||
#endregion
|
||||
|
||||
#region RTUndo Integration
|
||||
|
||||
/// <summary>
|
||||
/// RTUndo의 Undo/Redo 이벤트 핸들러
|
||||
/// RTGLite 자체 단축키로 Undo/Redo가 실행될 때 호출됩니다.
|
||||
/// </summary>
|
||||
private void OnRTUndoRedo(bool isRedo)
|
||||
{
|
||||
// UVC에서 Undo/Redo 중이면 무시 (중복 방지)
|
||||
if (_isUVCUndoRedoInProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log($"[GizmoUndoBridge] RTUndo {(isRedo ? "Redo" : "Undo")} detected");
|
||||
|
||||
// RTGLite에서 직접 Undo/Redo가 발생하면
|
||||
// UVC의 Undo 스택과 동기화가 필요할 수 있음
|
||||
// 현재는 로그만 출력하고, 필요시 추가 동기화 로직 구현
|
||||
}
|
||||
#region UVC Undo/Redo Integration
|
||||
|
||||
/// <summary>
|
||||
/// UVC UndoRedoManager의 Undo 이벤트 핸들러
|
||||
@@ -285,8 +249,9 @@ namespace UVC.Studio.Manager
|
||||
|
||||
/// <summary>
|
||||
/// 모든 활성 Gizmo를 새로고침합니다.
|
||||
/// PropertyWindow에서 Transform 속성 변경 시에도 호출됩니다.
|
||||
/// </summary>
|
||||
private void RefreshGizmos()
|
||||
public void RefreshGizmos()
|
||||
{
|
||||
if (RTGizmos.get == null) return;
|
||||
|
||||
@@ -313,40 +278,5 @@ namespace UVC.Studio.Manager
|
||||
public bool IsDraggingOrJustEnded => _isDragging || _framesSinceDragEnd < 2;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// RTUndo 기능을 일시적으로 비활성화합니다.
|
||||
/// UVC에서 Undo/Redo 실행 시 RTUndo와의 충돌을 방지합니다.
|
||||
/// </summary>
|
||||
public void DisableRTUndo()
|
||||
{
|
||||
if (RTUndo.get != null)
|
||||
{
|
||||
RTUndo.get.PushEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// RTUndo 기능을 다시 활성화합니다.
|
||||
/// </summary>
|
||||
public void EnableRTUndo()
|
||||
{
|
||||
if (RTUndo.get != null)
|
||||
{
|
||||
RTUndo.get.PopEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UVC Undo/Redo 진행 중 플래그를 설정합니다.
|
||||
/// </summary>
|
||||
public void SetUVCUndoRedoInProgress(bool inProgress)
|
||||
{
|
||||
_isUVCUndoRedoInProgress = inProgress;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -712,6 +712,8 @@ namespace UVC.Studio.Manager
|
||||
{
|
||||
if (_currentDisplayedChildTransform == null) return;
|
||||
|
||||
bool transformChanged = false;
|
||||
|
||||
switch (e.PropertyId)
|
||||
{
|
||||
case "transform_position":
|
||||
@@ -719,6 +721,7 @@ namespace UVC.Studio.Manager
|
||||
{
|
||||
_currentDisplayedChildTransform.localPosition = childPos;
|
||||
RecordTransformPropertyChange(_currentDisplayedChildTransform, "position", oldChildPos, childPos);
|
||||
transformChanged = true;
|
||||
}
|
||||
break;
|
||||
case "transform_rotation":
|
||||
@@ -726,6 +729,7 @@ namespace UVC.Studio.Manager
|
||||
{
|
||||
_currentDisplayedChildTransform.localEulerAngles = childRot;
|
||||
RecordTransformPropertyChange(_currentDisplayedChildTransform, "rotation", oldChildRot, childRot);
|
||||
transformChanged = true;
|
||||
}
|
||||
break;
|
||||
case "transform_scale":
|
||||
@@ -733,9 +737,16 @@ namespace UVC.Studio.Manager
|
||||
{
|
||||
_currentDisplayedChildTransform.localScale = childScale;
|
||||
RecordTransformPropertyChange(_currentDisplayedChildTransform, "scale", oldChildScale, childScale);
|
||||
transformChanged = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Transform이 변경되었으면 Gizmo 새로고침
|
||||
if (transformChanged)
|
||||
{
|
||||
GizmoUndoBridge.Instance?.RefreshGizmos();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -745,6 +756,8 @@ namespace UVC.Studio.Manager
|
||||
{
|
||||
if (_currentDisplayedObject?.GameObject == null) return;
|
||||
|
||||
bool transformChanged = false;
|
||||
|
||||
switch (e.PropertyId)
|
||||
{
|
||||
case "object_name":
|
||||
@@ -755,6 +768,7 @@ namespace UVC.Studio.Manager
|
||||
{
|
||||
_currentDisplayedObject.GameObject.transform.localPosition = pos;
|
||||
RecordTransformPropertyChange(_currentDisplayedObject.GameObject.transform, "position", oldPos, pos);
|
||||
transformChanged = true;
|
||||
}
|
||||
break;
|
||||
case "transform_rotation":
|
||||
@@ -762,6 +776,7 @@ namespace UVC.Studio.Manager
|
||||
{
|
||||
_currentDisplayedObject.GameObject.transform.localEulerAngles = rot;
|
||||
RecordTransformPropertyChange(_currentDisplayedObject.GameObject.transform, "rotation", oldRot, rot);
|
||||
transformChanged = true;
|
||||
}
|
||||
break;
|
||||
case "transform_scale":
|
||||
@@ -769,6 +784,7 @@ namespace UVC.Studio.Manager
|
||||
{
|
||||
_currentDisplayedObject.GameObject.transform.localScale = scale;
|
||||
RecordTransformPropertyChange(_currentDisplayedObject.GameObject.transform, "scale", oldScale, scale);
|
||||
transformChanged = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -776,6 +792,12 @@ namespace UVC.Studio.Manager
|
||||
RecordPropertyChange(e);
|
||||
break;
|
||||
}
|
||||
|
||||
// Transform이 변경되었으면 Gizmo 새로고침
|
||||
if (transformChanged)
|
||||
{
|
||||
GizmoUndoBridge.Instance?.RefreshGizmos();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -82,6 +82,8 @@ namespace UVC.Studio
|
||||
await InjectorAppContext.Instance.WaitForInitializationAsync();
|
||||
Setting setting = InjectorAppContext.Instance.Get<Setting>();
|
||||
|
||||
RTGizmos.get.skin.viewGizmoStyle.screenPadding = new Vector2(300f, 40f);
|
||||
|
||||
// Grid 크기 설정에 즉시 적용
|
||||
RTGrid.get.settings.cellSize = new Vector3(setting.Data.general.gridSize, setting.Data.general.gridSize, setting.Data.general.gridSize);
|
||||
// RTGizmos 위치/회전/스케일 스냅 설정에 즉시 적용
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#nullable enable
|
||||
using UVC.Studio.Cameras;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -22,11 +22,11 @@ namespace UVC.Studio.UI.Buttons
|
||||
|
||||
private void OnSceneInitialized()
|
||||
{
|
||||
PropertyWindow propertyWindow = InjectorAppContext.Instance.Get<PropertyWindow>();
|
||||
if (propertyWindow != null)
|
||||
{
|
||||
propertyWindow.Hide();
|
||||
}
|
||||
// PropertyWindow propertyWindow = InjectorAppContext.Instance.Get<PropertyWindow>();
|
||||
// if (propertyWindow != null)
|
||||
// {
|
||||
// propertyWindow.Hide();
|
||||
// }
|
||||
}
|
||||
|
||||
private void OnToggleValueChanged(bool visible)
|
||||
|
||||
Reference in New Issue
Block a user