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 Howey-Do-It · Apr 19, 2013 at 09:13 PM · editoreventwindowrepaint

How do I repaint/refresh/focus without calling Key Events multiple times?

My question is very specific.

My Goal:

I am creating an editor window that changes the scene view to create an orthographic, topdown, map navigation system. I have a grid of 12 x 8 GUILayout buttons in my editor window that refer to specific camera locations in the scene. Essentially easy topdown screen-based navigation for building levels. Think Zelda Classic(ZQuest).

The button that is green indicates where you currently are in the scene. This works perfectly, clicking on each grid box/button moves the scene cam to the proper location and updates my custom editor window so that the proper button is colored green.

         if(grid000 == true)
             GUI.color = Color.green;
         else
             GUI.color = Color.white;
         
         if(GUILayout.Button("", GUILayout.Width(width), GUILayout.Height(height)))
         {
                 sceneCamX = 0 * -12; sceneCamZ = 0 * 11; SceneView.RepaintAll();
         }
         
 
         if(grid001 == true)
             GUI.color = Color.green;
         else
             GUI.color = Color.white;
         
         if(GUILayout.Button("", GUILayout.Width(width), GUILayout.Height(height)))
         {
                 sceneCamX = 1 * -12; sceneCamZ = 0 * 11; SceneView.RepaintAll();
         }

My Problem:

I am also using WASD keys to move the camera around as well because this is quite convenient. Which also works perfectly except that the editor window is not updated properly to reflect where you are currently on the map(green button doesn't update to the correct one). I am using the Event.current.character to get key presses.

Also, if I use Repaint() or Focus(), it causes problems. Whenever I press WASD it moves more than one screen over, usually all the way to the maximum map bounds I have set.

         if(Event.current.character == 'a' & sceneCamX < 0)
         {
             sceneCamX += 6;
             SceneView.RepaintAll();
         }    
         
         if(Event.current.character == 'd' & sceneCamX > -11 * 12)
         {
             sceneCamX -= 6;
             SceneView.RepaintAll();
         }
         
         if(Event.current.character == 'w' & sceneCamZ > 0)
         {
             sceneCamZ -= 5.5f;
             SceneView.RepaintAll();
         }
         
         if(Event.current.character == 's' & sceneCamZ < 7 * 11)
         {
             sceneCamZ += 5.5f;
             SceneView.RepaintAll();
         }

My Question:

Is there a way to refresh/repaint/focus that does not call the Event multiple times? Or perhaps a different way in an editor window to GetKeyDown so that it is only called a maximum of one time?

If you need more information to answer, please let me know, I didn't want to post the entire 2,400 line script in here, unless it was necessary.

Thanks for your help!

Howey

Comment
Add comment · Show 1
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 Howey-Do-It · Apr 20, 2013 at 08:48 PM 0
Share

Thanks iwaldrop! That worked perfectly. I attempted previously to use EventType.$$anonymous$$eyDown, but I didn't understand how it worked fully. I added Repaint() under the currentEvent.character if statement and it updates the grid correctly.

As you can see, this is my first question, so I don't understand how the upvoting system works. I tried to up-vote you, but it says I don't have permission.

Thanks again! $$anonymous$$uch appreciated. I spent a whole week trying to solve this. Thanks for the quick response.

1 Reply

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

Answer by iwaldrop · Apr 20, 2013 at 01:02 AM

If I understand the question correctly, then you should try this:

 Event currentEvent = Event.current;

 if(curentEvent.type == EventType.KeyDown)
 {
     if (currentEvent.character == 'a' && sceneCamX < 0)
     {
         sceneCamX += 6;
         SceneView.RepaintAll();
     }

     if...
 }
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

12 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How can an editor script know when another script was removed from the project? 1 Answer

Repaint a system Editor window 1 Answer

Mouse click in edit mode. ✱✺✸❁ 1 Answer

[Unity Editor] Emulate Touch Input - Still Asking 12/10 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