2D Scene View – Reset

This is going to be a fairly short post. Nothing overly complicated but, hopefully, useful.

Long before Unity3D had built-in 2D capabilities (not that the current 2D implementation is overly helpful) it was too easy to accidentally move the scene camera and toss things out of alignment. Now, I know that fixing the scene to a particular plane and orthographic view can easily be achieved via the little scene gizmo at the top/left of the editing window, this action also requires mouse movement and at least a few button clicks. I prefer hotkeys for common operations. Not to mention that having things available through code allows greater control overall.

The steps to achieve this are not complicated.

  • Get the current scene view.
  • Set scene view to orthographic.
  • Rotate scene view to correct angle.
  • Expend scene view to a comfortable size.

that last step is there because Unity has a tendency of zooming in too close to things when performing the camera reset. The comfortable size value itself can be experimented with in order to achieve your own needs.

[MenuItem(MenuName.UtilityItems + "Reset Scene View" + Hotkey.CtrlShift.L)]
public static void Perform()
  var current = SceneView.currentDrawingSceneView;
  current.orthographic = true;
  current.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
  current.size = 2000.0f;

The menu item attribute might bear a little more explaining but that’ll have to wait for another post.

I guess the winter makes you laugh a little slower, Makes you talk a little lower about the things you could not show her…
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s