Author Topic: OnHover should run if the mouse releases outside of the collider  (Read 3838 times)

Disastercake

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 87
  • www.disastercake.com
    • View Profile
    • Disastercake
Hey Aren!  So this is something that's been bothering me about NGUI for years now.  If you are hovering over an object and then left click, and then drag the mouse off of the collider before releasing the mouse, it will never register with that object that it is no longer being hovered over.  I believe that after the event of the mouse releasing, NGUI should natively be checking to see what it is now hovering over.  This seems more intuitive than the current way it is handled.

Several use case examples are provided below.  The steps in bold are what I would not expect NGUI to do.

Case 1
Works as expected:
  • User hovers over collider.
  • OnHover(true) is ran.
  • User moves mouse outside of collider.
  • OnHover(false) is ran.

Case 2
Does NOT work as expected:
  • User hovers over collider.
  • OnHover(true) is ran
  • User clicks and releases immediately over collider
  • OnHover(true) is ran again.
  • OnHover(false) is never ran.

Expected:
  • User hovers over collider.
  • OnHover(true) is ran
  • User clicks and releases immediately over collider
  • OnHover(true) is not ran again.
  • OnHover(false) is not ran.

Case 3
Does NOT work as expected:
  • User hovers over collider.
  • OnHover(true) is ran
  • User clicks, but does not release yet.
  • User drags the mouse off the collider
  • User releases the mouse outside of the collider
  • OnHover(false) is never ran.


Expected Results:
  • User hovers over collider.
  • OnHover(true) is ran
  • User clicks, but does not release yet.
  • User drags the mouse off the collider
  • OnHover(false) is ran.
  • User releases the mouse outside of the collider



I am able to fix this issue by using the following code in the object that is having the problem:
  1. private void OnDrag()
  2.         {
  3.                 if ( UICamera.hoveredObject != MyGameObject)
  4.                         OnHover (false);
  5.         }

But this seems rather unintuitive to need to deal with OnDrag when I don't want it to have dragging functionality.

What are your thoughts on this?
« Last Edit: February 01, 2015, 01:49:56 PM by Disastercake »
Creator of Soul Saga.
http://www.disastercake.com

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnHover should run if the mouse releases outside of the collider
« Reply #1 on: February 02, 2015, 01:38:57 AM »
Hover state gets canceled by the Press state. You only get OnHover(false) if you move your mouse away without pressing on the button. You get OnDragOut() if you press and drag the mouse away.