유니티 Editor GUI에서 EditorScene 카메라를 오브젝트에게 향하게 하는 방법

검색으로 찾은 방법.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public static void TeleportSceneCamera(Vector3 cam_position, Vector3 cam_forward)
{
    // Can't set transform of camera :(
    // It internally updates every frame:
    //      cam.position = pivot + rotation * new Vector3(0, 0, -cameraDistance)
    // Info: https://forum.unity.com/threads/moving-scene-view-camera-from-editor-script.64920/#post-3388397
 
    var scene_view = UnityEditor.SceneView.lastActiveSceneView;
 
    // SceneView.lastActiveSceneView.cameraDistance is private, compute it.
    var offset = scene_view.pivot - scene_view.camera.transform.position;
    var cameraDistance = offset.magnitude;
 
    scene_view.pivot = cam_position + cam_forward * cameraDistance * -1.0f;
    scene_view.rotation = Quaternion.LookRotation(cam_forward);
}
cs
원본 링크

위와 같은 방법으로 적용하면 내가 카메라를 줌 or 줌 아웃 하면 그거에 따라 거리가 제각각으로 표현되서 수정을 했는데.. 해결 방법을 모르겠다...

댓글

가장 많이 본 글