- Home /
Is it possible to override the default editor controls?
I would like to override a few of the default editor controls from my custom editor. However the following script doesn't work to override the F key, the X key or the Spacebar. If the solution means having to use Reflection for this then that's okay but I can't find any examples as to how to go about achieving this.
public void OnSceneGUI(SceneView sceneView)
{
if (Event.current.isKey)
{
if (Event.current.Equals(Event.KeyboardEvent("F")))
{
Debug.Log ("F");
//Event.current.type = EventType.Used;
Event.current.Use ();
}
}
}
Do you want to simply use a computer keyboard key? If so, just use:
if (Input.Get$$anonymous$$eyDown("f")){
//Do something here, such as use object
}
If you want to override Unity controls for all platforms (sorry, it's so drawn out):
Go to the tab - Edit > Project Settings > Input
Open the "Axes" drop-down in the inspector
Find the axis you need (Ex. "Fire1" for left mouse-button)
If you do not see the input you want, in the "Axes" drop-down:
Change "size" (inside the "Axes" drop-down) to the next highest number (Ex. if it is set to 15, change it to 16)
In the lowest axis on the list (which will be a duplicate of the one above it) change the name to anything (Ex. If it is a sprint button, change the name to "Sprint", or anything similar)
Change the "Positive Button" to whatever the key is. (If it's a movement or action that has two opposites, such as move left and move right, use the "Negative Button" to the other of the two controls)
If your movement or action has only one button to be pressed, use this if statement:
If (Input.GetButtonDown("AxisNameGoesHere")){
//Do something here
}
If your movement or action has two opposite keys (like we mentioned earlier), Then call the if statement:
if (Input.GetAxis("AxisNameGoesHere")){
//Do something here
}
The reason you would do that long version, is because when you export your game to any platform such as Wii, Xbox or Playstation, it will still register those user inputs.
If your game is exported to one of those platforms without using custom axes, it will not recognize the user inputs.
So keep in $$anonymous$$d, for a PC/$$anonymous$$ac game, use the first option.
Happy Coding!
Noah.
Thanks Noah, great info but from what I've read the input$$anonymous$$anager isn't applicable to custom editor windows.
What is interesting is that if I set the active game object to null when pressing F then the focus doesn't activate which tells me that the editor is responding to the F key after calling OnSceneGUI.
Sorry, I misunderstood the question. Oops. Anyway I've been learning Custom Editor Scripting myself recently, so I can't really help. Sorry again!
Just completely ignore my stupid comment. :)
Answer by Jamora · Mar 07, 2014 at 09:00 AM
Have your code in the SceneView callback, like you apparently have now. The following seems to work:
//register to the delegate in OnEnable
SceneView.onSceneGUIDelegate += SceneGUI;
//in SceneGUI
if(Event.current.commandName == "FrameSelected"){
Event.current.commandName = "";
}
As for X and Spacebar (it's shift-spacebar in 4.3), you can change those in Preferences -> Keys. Alternatively, you can check for the key itself:
if(Event.current.keyCode == KeyCode.X)
Event.current.Use();
Your answer