Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MediaGiant · Mar 05, 2014 at 04:19 AM · editorcontrolsoverride

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 ();
     }
   }
 }
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NoahConstable · Mar 05, 2014 at 04:50 AM 0
Share

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):

  1. Go to the tab - Edit > Project Settings > Input

  2. Open the "Axes" drop-down in the inspector

  3. 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:

  1. Change "size" (inside the "Axes" drop-down) to the next highest number (Ex. if it is set to 15, change it to 16)

  2. 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)

  3. 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.

avatar image MediaGiant NoahConstable · Mar 05, 2014 at 05:15 AM 0
Share

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.

avatar image NoahConstable · Mar 07, 2014 at 05:19 AM 0
Share

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. :)

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

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();
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Override or listen for editor Play button 1 Answer

Controller axes (specifically the triggers) work in-editor but not in build? 0 Answers

Override functions in editor only 1 Answer

OnServerStart not being called in standalone build. Works in editor. 1 Answer

Panning Game Tab 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges