Hey everyone!
I am doing my UI using uGUI (duh) and it’s been going pretty darn well.
Though I am stuck on handling particular events.
In void OnGUI() I’d do something like this to handle events:
void OnGUI()
{
Event e = Event.current;
switch (e.type)
{
case EventType.Repaint:
{
// Repaint Logic
break;
}
case EventType.MouseDown:
{
// Logic
break;
}
case EventType.MouseUp:
{
// Logic
break;
}
case EventType.KeyDown:
{
// Logic
break;
}
case EventType.KeyUp:
{
// Logic
break;
}
case EventType.ScrollWheel:
{
// Logic
break;
}
}
}
- Here’s what I did till now:
- I moved the logic in EventType.Repaint to Update(). Is there a better way to do this? perhaps by implementing IUpdateSelectedHandler?
- For EventType.MouseDown, EventType.MouseUp I implemented IPointer interfaces. (e.g. IPointerDownHandler).
- For EventType.ScrollWheel I used IScrollHandler.
- But I hit a brick wall when trying to implement EventType.KeyDown and EventType.KeyUp. After lots of researching and poking around, I still have no idea where to move this logic to. There’s ISubmitHandler but apparently that’s only for submitting data (as if you were editing in InputField and then hit enter).
-
Important note for helpful people who are eager to hastily answer:
I do realize I can check for input flags in void Update() using Input.GetKeyDown and its other variations. But this approach is NOT desired in my situation.
-
I am really hoping somebody would provide the ultimate answer. Because otherewise I would have to keep OnGUI just for KeyDown & KeyUp.
Update: I tried digging in uGUI’s source code, this might be a candidate starting solution for the problem: uGUI source: InputField’s OnUpdateSelected Really hoping Unity devs or anybody else would provide some directions!