Hello Guest

Author Topic: tk2dUIItem .OnHoverOut activated during click  (Read 4675 times)

Vartib

  • Newbie
  • *
  • Posts: 21
    • View Profile
tk2dUIItem .OnHoverOut activated during click
« on: January 25, 2014, 05:30:38 pm »
I've noticed that .OnHoverOut is activated when a button is clicked. This is causing problems since I need .OnClick to be called before .OnHoverOut. I don't understand why it's doing this since the button is still being hovered over when someone clicks it; shouldn't .OnHoverOut only be called when someone actually moves their mouse out of the button's collider?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dUIItem .OnHoverOut activated during click
« Reply #1 on: January 25, 2014, 11:06:16 pm »
I can't change the way it behaviour as it will completely change existing behaviour, but if you need to change the behaviour locally the place to do so is tk2dUIItem.Hover* and tk2dUIManager (search for checkForHovers).

Vartib

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: tk2dUIItem .OnHoverOut activated during click
« Reply #2 on: January 26, 2014, 05:30:06 pm »
That's understandable, you have quite a few users at this point!

In case anyone needs this in the future, I think I got it changed correctly in the tk2dUIManager script under the "checkForHovers" section. I changed this...

Code: [Select]
if (!isPrimaryTouchFound && !isSecondaryTouchFound && hitUIItem == null && !Input.GetMouseButton(0)) //if raycast for a button has not yet been done
{
   hitUIItem = RaycastForUIItem( Input.mousePosition );
}
   else if (Input.GetMouseButton(0)) //if mouse button is down clear it
{
   hitUIItem = null;
}

...to this...

Code: [Select]
if (!isPrimaryTouchFound && !isSecondaryTouchFound && hitUIItem == null && !Input.GetMouseButton(0)) //if raycast for a button has not yet been done
{
   hitUIItem = RaycastForUIItem( Input.mousePosition );
}

If this isn't right please feel free to correct me. Everything seems to be working though :)
« Last Edit: January 26, 2014, 05:48:27 pm by Vartib »

oug

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: tk2dUIItem .OnHoverOut activated during click
« Reply #3 on: August 07, 2015, 10:07:08 am »
That's understandable, you have quite a few users at this point!

In case anyone needs this in the future, I think I got it changed correctly in the tk2dUIManager script under the "checkForHovers" section. I changed this...

Code: [Select]
if (!isPrimaryTouchFound && !isSecondaryTouchFound && hitUIItem == null && !Input.GetMouseButton(0)) //if raycast for a button has not yet been done
{
   hitUIItem = RaycastForUIItem( Input.mousePosition );
}
   else if (Input.GetMouseButton(0)) //if mouse button is down clear it
{
   hitUIItem = null;
}

...to this...

Code: [Select]
if (!isPrimaryTouchFound && !isSecondaryTouchFound && hitUIItem == null && !Input.GetMouseButton(0)) //if raycast for a button has not yet been done
{
   hitUIItem = RaycastForUIItem( Input.mousePosition );
}

If this isn't right please feel free to correct me. Everything seems to be working though :)
A big thank you for finding this fix!