Files
Studio/Assets/Scripts/ExternalAssets/Gizmo/CameraMovement.cs
2025-05-21 12:10:38 +09:00

44 lines
954 B
C#

using UnityEngine;
namespace Studio.RuntimeGizmo
{
public class CameraMovement : MonoBehaviour
{
#pragma warning disable 0649
[SerializeField]
private float sensitivity = 0.5f;
#pragma warning restore 0649
private Vector3 prevMousePos;
private Transform mainCamParent;
private void Awake()
{
mainCamParent = Camera.main.transform;
}
private void Update()
{
if( Input.GetMouseButtonDown( 0 ) )
prevMousePos = Input.mousePosition;
else if( Input.GetMouseButton( 0 ) )
{
Vector3 mousePos = Input.mousePosition;
Vector2 deltaPos = ( mousePos - prevMousePos ) * sensitivity;
Vector3 rot = mainCamParent.localEulerAngles;
while( rot.x > 180f )
rot.x -= 360f;
while( rot.x < -180f )
rot.x += 360f;
rot.x = Mathf.Clamp( rot.x - deltaPos.y, -89.8f, 89.8f );
rot.y += deltaPos.x;
rot.z = 0f;
mainCamParent.localEulerAngles = rot;
prevMousePos = mousePos;
}
}
}
}