Author Topic: UIButton's OnClick delegate not getting called within UISlider  (Read 4663 times)

DarkMath

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
I just bought NGUI. I'm pretty happy with it but I can't get an OnClick event called on the UIButton component from within a Slider control.

Has anyone ever had an issue like this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton's OnClick delegate not getting called within UISlider
« Reply #1 on: April 24, 2014, 01:23:40 AM »
A UIButton within a slider control? What do you mean by that? Buttons and sliders are different things. The button script can be used to highlight objects, so I assume that's what you may be doing?

DarkMath

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UIButton's OnClick delegate not getting called within UISlider
« Reply #2 on: April 24, 2014, 01:44:27 AM »
There is a UIButton component within the UISlider control. To reproduce what  I'm seeing just
1)drag a Horizontal Slider Prefab to your scene.
2)Note the UIButton within the Slider root, it defaults to the name "Control - Simple Horizontal Slider"
3)Create some other GameObject and put a script on it with a public method called HandleSliderClicked with a Debug.Log in it.
4)Drag that scripts object to the Slider's UIButton->OnClick
5)Point to the HandleSliderClicked method
6)Run the Scene
7)Click on the Slider background (not the Thumb button).
8)Note that your HandleSliderClicked is never called.

This looks like a bug to me.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton's OnClick delegate not getting called within UISlider
« Reply #3 on: April 24, 2014, 01:46:18 AM »
That would be because the slider's thumb gets moved to where you clicked on the slider, and when you release the mouse, it gets released over the thumb, not the slider. So it's never a complete click because it ends on a different widget.

Remove the collider from the thumb and it will work as expected.

DarkMath

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UIButton's OnClick delegate not getting called within UISlider
« Reply #4 on: April 24, 2014, 01:52:57 AM »
If I remove the collider from the Thumb then I won't get notified if the user clicks on the Thumb. I need to respond to the following:

1)User clicks on slider background
2)User clicks on the thumb

DarkMath

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UIButton's OnClick delegate not getting called within UISlider
« Reply #5 on: April 24, 2014, 01:59:11 AM »
I have an enhancement idea for you: add a boolean to the OnClick component called RespondToDownClick.

In other words OnClick isn't "granular" enough. It would be very helpful to get notified when the user clicks Down on the background or thumb as well as an Up click.

A Click could be either a Down click or an Up Click right?

DarkMath

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UIButton's OnClick delegate not getting called within UISlider
« Reply #6 on: April 24, 2014, 02:07:57 AM »
I was finally able to get this working by using the Slider OnValueChanged callback. So I'm good for now. Maybe the OnClick on the slider's UIButton is a little redundant/ambiguous since by default it won't work until you turn of the BoxCollider on the Thumb button.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton's OnClick delegate not getting called within UISlider
« Reply #7 on: April 25, 2014, 05:26:27 AM »
A click is when you press and release on the same object. OnPress(true) is when you press, OnPress(false) is when you release -- and this event is sent to the same object you got the initial OnPress(true) on (your slider).