How to Rotate Editor Camera in 2D?

I have a 2D platformer game that has levels with varying directions of gravity. So levels are rotated right, some left, and some are even upside-down. The player camera automatically rotates to match the level so the player doesn’t get confused while playing.

However, I’m still at a loss while editing. The level rotation makes it difficult to edit the levels because the levels are at odd angles in the SceneView. How can I rotate the editor camera so that I can see my levels at their custom rotation when editing?

EDIT: This isn’t sufficient. Yes, it rotates the view, but then the controls for manipulating objects is all weird.

I followed this tutorial and came up with this result:

You can change the SceneView’s camera’s rotation, but after you do so, you have to call the camera’s Render() method.

You have to use Quaternion.AngleAxis(angle, Vector3.forward) to set the angle. Setting it to a new Quaternion is less intuitive.

To do this, you have to make a script. Here’s the basic of the two scripts I created:

The Editor Object (goes in the “Assets/Editor” folder)

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;


[CustomEditor(typeof(EditorCameraRotatorObject))]
public class EditorCameraRotator : Editor
{
    EditorCameraRotatorObject ecro;

    public void OnEnable()
    {
        ecro = (EditorCameraRotatorObject)target;
        SceneView.onSceneGUIDelegate = rotateCamera;
    }

    void rotateCamera(SceneView sceneview)
    {
            Quaternion angle = Quaternion.AngleAxis(ecro.rotZ, Vector3.forward);
            if (sceneview.camera.transform.localRotation != angle)
            {
                sceneview.isRotationLocked = false;
                sceneview.camera.transform.localRotation = angle;
                sceneview.camera.Render();
            }
        }
    }
}

The GameObject (goes in the “Assets/Scripts” folder, must have an instance of this in a scene):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EditorCameraRotatorObject : MonoBehaviour {

    public float rotZ = 0;
}

Then, to rotate the camera, just change the rotZ value of the EditorCameraRotatorObject that you have in the scene.

I wrote an editor window based on @shieldgenerator7’s answer. Now it’s easier to use and it doesn’t need MonoBehaviour.
To use, you can open Editor Camera Rotator in Tools menu
Here’s better version:

using System.Reflection;
using UnityEditor;
using UnityEngine;
using Utils;

// ReSharper disable CheckNamespace

namespace EditorTools
{
	public class EditorCameraRotator : EditorWindow
	{
		private float _z = 0;


		[MenuItem("Tools/Editor Camera Rotator")]
		public static void OpenWindow()
		{
			GetWindow<EditorCameraRotator>();
		}

		public void OnEnable()
		{
			SceneView.duringSceneGui -= RotateCamera;
			SceneView.duringSceneGui += RotateCamera;
		}

		private void OnGUI()
		{
			float prevZ = _z;
			EditorGUILayout.BeginHorizontal();
			_z = EditorGUILayout.FloatField(_z, GUILayout.Width(30));
			_z = EditorGUILayout.Slider(_z, -180, 180);
			EditorGUILayout.EndHorizontal();
			if (Mathf.Abs(prevZ - _z) > 0.0001f)
			{
				SceneView view = GetWindow<SceneView>();
				view.GetType().GetMethod("OnGUI", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(view, null);
			}
		}

		private void OnDisable()
		{
			SceneView.duringSceneGui -= RotateCamera;
		}

		void RotateCamera(SceneView sceneview)
		{
			Quaternion angle = Quaternion.AngleAxis(_z, Vector3.forward);
			if (sceneview.camera.transform.localRotation != angle)
			{
				sceneview.isRotationLocked = false;
				sceneview.camera.transform.localRotation = angle;
				sceneview.camera.Render();
			}
		}
	}
}