- Home /
Extending editor without script on GameObject?
I wrote this script to extend the Editor with the purpose to hide the cursor when right clicking in scene view. It works; however, I have to be selected on the object with the script first. Is it possible to extend the Editor like this, but have it not be limited to selecting the gameobject with the script every time?
@CustomEditor (NoRightMouseInScene)
class NoRightMouseInSceneEditor extends Editor{
function OnSceneGUI ()
{
if(Event.current.type == EventType.MouseDown && Event.current.button == 1)
{
Screen.showCursor = false;
}
else if(Event.current.type == EventType.MouseUp && Event.current.button == 1)
{
Screen.showCursor = true;
}
}
}
Thanks.
Answer by AchillesWF · Apr 22, 2012 at 02:50 AM
You have that code in an inspector, and so it will only run (I think) when the object is selected. Try moving the code into the OnGUI() function of an object.
Thanks for the reply. What do you mean I have the code in an inspector? The code has to be a class in the editor folder because it uses Events. I would like to be able to run a class that extends the editor without having to place a script on any object. Is that even possible?
I don't think you need to have an editor class to do this.
Any object can get the Event in its OnGUI() function, regardless of if it is an Editor (ScriptableObject) or $$anonymous$$onoBehavior.
Thanks, I didn't know that. However it only works in game mode, because OnGUI doesn't run in edit mode, even with @script ExecuteInEdit$$anonymous$$ode. When it does run in game mode, the mouse only disappears over the game window, not the scene window, which is what I would like.
Just FYI you can register an object function to be called in the OnSceneGUI() stack.
SceneView.onSceneGUIDelegate += YourFunction;
You can then have your function do the work you are talking about perhaps. Note this is C#, JS has other methods of using delegates.
Your answer
![](https://koobas.hobune.stream/wayback/20220613070608im_/https://answers.unity.com/themes/thub/images/avi.jpg)