- 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;
- }
- }
|