- Home /
Move scene camera to gameObject via Editor script
When you double click on object in hierarchy view the scene camera moves to this object on scene and adjust it's size to fit the object size.
I need to acheive this through Editor script (in custom inspector, by button click). I don't neet this object to be selected in Inspector though, just ping it in hierarchy with EditorGUIUtility.PingObject
Answer by Deadcow_ · Apr 08, 2015 at 04:35 PM
Wow-wow I made it!
if (GUILayout.Button(i.ToString(), EditorStyles.toolbarButton, GUILayout.Width(20)))
{
EditorGUIUtility.PingObject(item);
var currentlActive = Selection.activeGameObject;
Selection.activeGameObject = item.gameObject;
SceneView.lastActiveSceneView.FrameSelected();
Selection.activeGameObject = currentlActive;
}
It works like a charm! It even keeps current hierarchy scroll position of selected object! Regardless of that I swap selected objects. Phew :)
Answer by IMD · Jun 06, 2017 at 08:41 PM
Hello!
Unity provides a function which will take a Vector3 and automatically lerp the scene view camera to that position as if it's being focused on via the Unity UI. Example below:
SceneView.lastActiveSceneView.LookAt(nextSceneViewPos);
Hope that helps some people :)
That is most helpful, thank you. The only issue is that it doesn't zoom the same way the Focus function does. Do you know what the function might be that calls LookAt and Focus?
Answer by Targaryen · Apr 08, 2015 at 03:11 PM
If you want to move the camera to an specify GameObject, you can use the Vector3.Lerp function. You can find all the info about this in here: http://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
But in the end, it takes 3 parameters:
the initial position of the gameObject (From Vector3)
The destination of the gameObject (To Vector3)
The speed you want to move the gameObject (for this you can setup a var like speed and then you can use "speed * Time.deltaTime")
Hope this helps!
$$anonymous$$y english is barely readable sometimes, since I'm not a native speaker, but I mention Editor script and scene camera (ins$$anonymous$$d of game camera). Once again - I want to focus camera on object in Scene View through Editor Script. But thanks for trying to help anyway
ok! now i understand! I don't even now if it's possible to create scripts to modify the Scene camera; Hopefully someone knows more about it.
sry!