You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

46 lines
1.4 KiB

using UnityEngine;
using UnityEditor;
public class SceneViewCameraTest
{
[MenuItem("Tools/Camera/Snap Scene To Camera #c")]
static public void MoveSceneViewCamera()
{
if(Camera.main == null)
{
Debug.LogError("No Main camera in scene");
return;
}
Vector3 position = Camera.main.transform.position;
Quaternion rotation = Camera.main.transform.rotation;
//SceneView.lastActiveSceneView.size = 0.1f;
SceneView.lastActiveSceneView.rotation = rotation;
SceneView.lastActiveSceneView.pivot = position;
SceneView.lastActiveSceneView.pivot += Camera.main.transform.forward * SceneView.lastActiveSceneView.size;
SceneView.lastActiveSceneView.Repaint();
}
[MenuItem("Tools/Camera/Snap Camera To Scene &#c")]
static public void MoveCameraToScene()
{
if (Camera.main == null)
{
Debug.LogError("No Main camera in scene");
return;
}
GameObject camera = Camera.main.gameObject;
Undo.RegisterCompleteObjectUndo(camera.transform, "Snapped Camera to Scene View");
camera.transform.position = SceneView.lastActiveSceneView.pivot;
camera.transform.rotation = SceneView.lastActiveSceneView.rotation;
camera.transform.position -= Camera.main.transform.forward * SceneView.lastActiveSceneView.size;
}
}