Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

SceneView not documented

Discussion in 'Documentation' started by Stoven, Dec 13, 2014.


Did you know about the SceneView class?

  1. Yes

    12 vote(s)
  2. No

    19 vote(s)
  1. Stoven


    Jul 28, 2014
    I know, "it's internal"... but it is extremely helpful for Editor scripting.

    I wasn't even aware of its existence despite looking through the Documentation and actively searching for it. It was only through a post on Unity Answers that I was even able to find out about it.

    Code (CSharp):
    1.     [MenuItem("Experimental/Toggle SceneView Projection")]
    2.     public static void SceneViewOrtho()
    3.     {
    4.         SceneView sceneView = SceneView.sceneViews[0] as SceneView;
    5.         sceneView.orthographic = !sceneView.orthographic;
    6.     }
    I wouldn't have known that I could do something like that to get Orthographic sight in my initial Scene View outside of the 2D perspective option. The perspective option locks the Scene to X/Y and removes the Gizmo for rotating about the view... but what if I want to preview an Isometric map and use a Gizmo Grid as measurement within the Scene View?

    Code (CSharp):
    1. public class TestWindow : EditorWindow
    2. {
    3.     [MenuItem("Window/" + "Test")]
    4.     public static void Init()
    5.     {
    6.         // Get existing open window or if none, make a new one:
    7.         TestWindow window = GetWindow<TestWindow>();
    8.         window.title = "Test";
    9.     }
    11.     private static void OnScene(SceneView sceneview)
    12.     {
    13.         Debug.Log("This event opens up so many possibilities.");
    14.     }
    16.     public void OnDestroy()
    17.     {
    18.         SceneView.onSceneGUIDelegate -= OnScene;
    19.     }
    21.     public void Update()
    22.     {
    23.         if (SceneView.onSceneGUIDelegate == null)
    24.         {
    26.             SceneView.onSceneGUIDelegate += OnScene;
    28.             //Any other initialization code you would
    29.             //normally place in Init() goes here instead.
    30.         }
    31.     }
    32. }
    @Elecman thanks for this, by the way!

    Wouldn't have known that upon doing this (and docking the new Editor window somewhere out of the way) that I could get updates from the SceneView whenenever I click something or pan my mouse around within the SceneView.

    I'm sure there are many, many other things that can be done simply by having access to the SceneView and being able to modify the view via Editor scripts. I'm just extremely surprised that there is such little information about such a useful class.

    Edit: I now realize that by extending the EditorWindow and using code in its Update script that you can essentially achieve the same effect as the 2nd part, except it will fire all the time (100 times per second as long as that Window is visible) as opposed to just actions within the SceneView window.

    Edit2: I'm an idiot. You can change the camera perspective under the orientation gizmo in 3D mode. Just now realized that when looking for limitations with the SceneView outside of scripting.
    Last edited: Dec 13, 2014
    sok0 likes this.
  2. msklywenn


    Nov 28, 2014
    I wonder how to use it from a property drawer. OnEnable/OnDisable are not sent to those so I don't see where from we should unregister...