- Home /
get the position of the Editor Camera
Hi, Is there any way to access the Editor camera's position and rotation. What I mean is the camera view from the Editor not the main camera object that you created in the scene.
Answer by Syanyde · Jan 08, 2011 at 12:26 PM
Short Answer:
Long Answer (with example):
The following will create a menu option in the "Window" menu called "SceneViewCameraTest".
Every time you call (or click on) this window, it will show you the Scene View's camera rotation. (converting these to angles is well-documented, so I've not bothered with that in this example.)
Create a c# script called "SceneViewCameraTest.cs" using the following code:
using UnityEngine;
using UnityEditor;
public class SceneViewCameraTest : EditorWindow {
[MenuItem ("Window/SceneViewCameraTest")]
static void Init () {
// Get existing open window or if none, make a new one:
SceneViewCameraTest window = (SceneViewCameraTest)EditorWindow.GetWindow (typeof (SceneViewCameraTest));
}
void OnGUI () {
EditorGUILayout.TextField ("SceneViewCameraAngle", ""+SceneView.lastActiveSceneView.rotation);
}
}
Answer by Jean-Fabre · Nov 19, 2010 at 08:31 AM
Hi,
There is for this a very simple tool to align the camera to the scene view.
1: select the camera you want to align 2: in the Unity menu, select gameObject -> aLignWithView
Done. Not only you have aligned the camera to the scene view so that the game will have the same point of view but you can also know the transform of the scene as a direct side effect ( but I guess aligning the camera was what you wanted to achieve anyway)
Hope it helps,
Bye,
Jean
Hi... I know there is a Align Function in GameOBject... I still want to know how to get that view transform for some other reasons. Can you tell me how can I get the View Transform values?
Well, just like I told you, create a new camera, and then align it, the transform of the camery you just aligned is exactly what you need I think. Or do you mean you want to write some authoring tools that needs this value on the fly?
Answer by SultanZabu · Feb 18, 2014 at 07:56 PM
For what I need it was actually pretty simple.
SceneView.currentDrawingSceneView.camera
getting that let me save the position of the editor camera with a button in the inspector.
It seems that currentDrawingSceneView keeps returing null using lastActiveSceneView solves the problem for me.
Answer by Rodiaz89 · Jun 24, 2015 at 01:29 AM
Here you can take a look at an asset that saves the editor camera angles and you can go back and forward the states you saved: https://www.assetstore.unity3d.com/en/#!/content/39370