Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: poolts on December 05, 2014, 09:54:57 AM

Title: Using UIEventTrigger to get mouse down on button
Post by: poolts on December 05, 2014, 09:54:57 AM
Hi,

I'm using an EventDelegate to subscribe to an onPress event, but it only seems to be for the initial press (on frame). How do I use the EventDelegate to invoke the method whilst the button is being pressed as opposed to just the initial press?

  1. EventDelegate.Add(m_decreasePriceButtonTrigger.onPress, HandleDecreasePriceButtonPressed);

I've read you can use OnPress() attached to the same GO as your button, but I really want to just have a reference to the button in another script (not on the GO of the button).

Thanks for any help :)
Title: Re: Using UIEventTrigger to get mouse down on button
Post by: ArenMook on December 05, 2014, 04:05:33 PM
Inside the HandleDecreasePriceButtonPressed:
  1. void HandleDecreasePriceButtonPressed (bool isPressed)
  2. {
  3.     if (isPressed) StartCoroutine("DoStuff");
  4.     else StopCoroutine("DoStuff");
  5. }
  6.  
  7. IEnumerator DoStuff()
  8. {
  9.     for (;;)
  10.     {
  11.         // do something here
  12.         yield return null;
  13.     }
  14. }
Title: Re: Using UIEventTrigger to get mouse down on button
Post by: poolts on December 07, 2014, 01:30:26 PM
Hi Aren,

I tried to change the method signature of HandleDecreasePriceButtonPressed() to include the bool isPressed, but I didn't think EventDelegate methods could have params?

It gives an error to say the method signature is incorrect.

If I need to add that method call inside the HandleDecreasePriceButtonPressed() I don't understand where the EventDelegate gets the bool isPressed from.

Thanks for the help.
Title: Re: Using UIEventTrigger to get mouse down on button
Post by: ArenMook on December 09, 2014, 12:40:20 PM
Don't use an EventDelegate in this case. use UIEventListener.Get(targetGameObject).onPress += HandleDecreasePriceButtonPressed;