- Home /
How can I simulate the "f" hotkey in the editor?
I want to write a script to add a menu item that, when clicked, brings the main character into focus in the Scene view. So far, I can't seem to get it or find any resources on how to change the scene view's camera position/rotation.
How can I set the position/rotation of the scene view's camera in the editor at design-time?
Answer by noahmjohnson · Mar 09, 2011 at 08:21 PM
According to this tread:
You can use:
SceneView.lastActiveSceneView.FrameSelected()
It works for me, although because it is undocumented, it is subject to not work or change.
I have mine set up as an editor script button:
if(GUILayout.Button("Frame Camera", GUILayout.Width(120)))
{
SceneView.lastActiveSceneView.FrameSelected()
}
Hope this helps!
Answer by ThomLaurent · Jan 28, 2017 at 01:24 PM
An alternative to @noahmjohnson 's answer:
SceneView.lastActiveSceneView.SendEvent(EditorGUIUtility.CommandEvent("FrameSelected"));
For the other editor commands, refer to their name in the Edit menu of the Unity Editor window (triming spaces).
See EditorGUIUtility.CommandEvent and EditorWindow.SendEvent
Answer by davebuchhofer · Mar 21, 2010 at 02:35 AM
Try Jaap's answer to my similar question earlier: http://answers.unity3d.com/questions/5875/how-can-i-mimic-the-frame-selected-f-camera-move-zoom-extents-zoom-to-fit
Your answer
Follow this Question
Related Questions
How can I preserve static object/data between editor and play? 2 Answers
HideFlags on children of visible objects. 3 Answers
Unity Editor Scripts: GameObject Added / Removed Event? 1 Answer
How to record the entire game and user behaviour for a research project? 1 Answer
problem with the digits of my timer 1 Answer