- Home /
Editor Extension, OnSceneGUI Problem
I want to write a quite simple unity editor extension which need to know mouse click position in Scene Space.It is not a Custom Editor but a Editor Window. My code is below which is not currently working.(I think OnSceneGUI is not supported by EditorWindow class, but what is the alternative way to do that) Help me pls
using UnityEngine;
using UnityEditor;
using System.Collections;
public class qwerty : EditorWindow{
[MenuItem("HAKAN/Qwerty")]
public static void ShowWindow()
{
var window=GetWindow<qwerty>();
window.title="Qwerty";
}
public void OnSeceneGUI(SceneView sceneView)
{
Event evt=Event.current;
if(evt.isMouse)
{
Debug.Log ("Mouse Down!");
Event.current.Use();
}
}
}
Answer by Jamora · Sep 26, 2013 at 03:44 PM
You need to register the callback before you can use the function. Add the following to do just this:
void OnEnable(){
SceneView.onSceneGUIDelegate += OnSeceneGUI;
}
void OnDisable(){
SceneView.onSceneGUIDelegate -= OnSeceneGUI;
}
Finally an answer. Thank you man. It works great!! One more thing that I wanna ask you is that, even I search for EditorWindow and Editor classes documentation(http://docs.unity3d.com/Documentation/ScriptReference/EditorWindow.html) I could not find anything about that you say.Is there something wrong with the documentation?
Well, it depends on the way you look at it. There are a lot classes / functions which aren't documented. In general it's an indication that a certain class isn't ment to be used because it might get deprecated in the next release. However the SceneView is a fundamental class which exists since the very beginning of Unity and it's most likely that it won't get deprecated even in the far future.
So the answer should be: yes, it's missing in the documentation.
Your answer

Follow this Question
Related Questions
Accessing OnSceneGUI with EditorWindow in JS 1 Answer
Unity Editor Event System 1 Answer
Changes to Object made in custom Editor Window don't persist 0 Answers
Keep equal width for panels in EditorGUILayout.HorizontalScope 0 Answers
Execute editor window scripts when project errors are present 0 Answers