Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Fritsl · Sep 15, 2016 at 01:35 PM · editor-scriptingeditorwindoweditor extension

Error sound on key input EditorWindow OnGUI()

Hi guys,

I'm doing an EditorWindow inherited class, and I need User input such as arrow keys pressed at any time.

Knowing OnGUI() can only listen to Event.current.isKey for such input, I'm using that (though I'd rather not since it causes issues with window must have focus)

I've crossed quite a lot of sync-barriers by placing

 if (Event.current != null && Event.current.isKey)
   {
     Repaint();
   }

at the top of void OnGUI()

.. However one thing I struggle with, is that apparently since there's no input field Unity is returning an system error beep every time a key is pressed.

At least on Mac, have not even tried on Win yet, but even on one platform it's a drag, I'd really like my Editor script not to inform the user he's doing something wrong when he's not :)

Would you know how to 'catch' the input (like it's done in input fields) so no error sounds are returned.. or even better; A (hack) to not rely on Event.current.isKey for user input in EditorWindow?

Thanks! :)

Comment
Add comment
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

2 Replies

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

Answer by Bunny83 · Sep 15, 2016 at 07:52 PM

I don't see that behaviour on Windows. Maybe it's a Mac specific issue...

Have you actually tried "eating" the event?

 Event.current.Use();

btw: You don't have to check if Event.current is null. OnGUI is only called when an event is set. Also keep in mind there are several "key" events that might fire for a single key. You always get at least a key down and a key up. "isKey" is just a shorthand for testing if the current event type is one of the key messages.

EditorWindows can also handle events inside the sceneview. For that you can subscribe a method to the static event SceneView.onSceneGUIDelegate.

But since we have no idea what's the point of your editor window, suggesting things it kind of pointless ^^.

Comment
Add comment · Show 2 · 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
avatar image Fritsl · Sep 16, 2016 at 08:03 AM 0
Share

@Bunny83 : This is pure gold - you've helped me a lot! Thanks.

What I want to do: $$anonymous$$y daily work is often involving Unity effects. This often involves prefabs with multiple GameObjects each with materials, each with textures..

So for instance if I have an old Efx, and I'd like to use a modified version, it is hell as I cannot just go and change the material or the texture of a copy, since they share with the other Efx.

Using Unity's Window Locks and dragging around can be a very time consu$$anonymous$$g task, totally killing creativity.

That is one task I'm now solving with an asset.

Another is a smooth way of solving the apparently ever returning issue of programmers making things as missiles (example) that destroys themselves, and artists who think the missilles smoke should not disappear before it is faded out. (to say it simple)

  • $$anonymous$$aking complex powerups, missiles that spawn children etc can be an overly complex task - and I'm trying to make it overly simple :)

So, I have done a tool, and it's working, and working great, but I need to polish it before releasing it.

Therefore I have run straight into the funny world of mixing #if UNITY_EDITOR EditorWindow Directory.GetFiles AssetDatabase.LoadAssetsAtPath

and now also trying to refactor with Events and 'what users would expect to be able to do with keys' in $$anonymous$$d..

P$$anonymous$$ me if interested, and thanks again! :)

avatar image Fritsl · Sep 16, 2016 at 11:50 AM 0
Share

Facepalm!

I figured you mentioned SceneView with reference to me looking for ways to catch key input without having EditorWindow in focus. But..

SceneView is (another) undocumented class.. With that as a starting point I'm now trying to learn how to work with it from EditorWindow..

Any hints on how to listen to key input via SceneView would be very, very welcome. Thanks.

avatar image
0

Answer by Fritsl · Sep 16, 2016 at 12:58 PM

Ha, got it, here's how to get key input from Scene View via EditorWindow:

public class YourClass : EditorWindow


void OnEnable() {
SceneView.onSceneGUIDelegate += this.OnSceneGUI; }

void OnDisable() { SceneView.onSceneGUIDelegate -= this.OnSceneGUI; }

 void OnSceneGUI(SceneView sceneView)
 {
     Event e = Event.current;
     if (e.isKey)
         Debug.Log("Detected key code from Scene View: " + e.keyCode);
 }
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Creating a custom editor window with a grid 1 Answer

Why does the SceneView camera return jittery values? 0 Answers

Dynamic content in custom EditorWindow 1 Answer

Is there a way to avoid the Animation window drop-down menu with a selected Animator? 0 Answers

How to make multiple EditorWindows dock together? 0 Answers


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