- Home /
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
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.
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...
}
Your answer
Follow this Question
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