2D Toolkit Forum

2D Toolkit => Support => Topic started by: Vartib on January 25, 2014, 05:30:38 pm

Title: tk2dUIItem .OnHoverOut activated during click
Post by: Vartib 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?
Title: Re: tk2dUIItem .OnHoverOut activated during click
Post by: unikronsoftware 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).
Title: Re: tk2dUIItem .OnHoverOut activated during click
Post by: Vartib 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 :)
Title: Re: tk2dUIItem .OnHoverOut activated during click
Post by: oug 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!