Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: TomA6 on September 01, 2012, 03:47:01 AM

Title: UISlider not reporting changed values in UIEventListener
Post by: TomA6 on September 01, 2012, 03:47:01 AM
Ok
If I do:
  1.         mysliderGO.GetComponent<UISlider>().functionName = "onSlideLevel";
  2.         mysliderGO.GetComponent<UISlider>().eventReceiver=gameObject;
  3.  
  4.         public void onSlideLevel (float value) {...    
  5.  

Then I see every change of the slider but I only want to track the value change after the user let's go of the UISlider.

If I try it this way
  1. UIEventListener.Get(mysliderGO).onPress += onSlideLevel;
  2. // or UIEventListener.Get(mysliderGO).onSelect += onSlideLevel;
  3. // or UIEventListener.Get(mysliderGO).onDrag += onSlideLevel;
  4. // onClick seems dead here...
  5.  
  6. public void onSlideLevel (GameObject sender, bool state) // Vector2 level) // for onDrag instead
  7.         {
  8.                 float selection = sender.GetComponent<UISlider>().sliderValue;
  9.                 print(sender.name+" : "+selection
  10.                 //      +" "+level.x); // for onDrag
  11.                 +" "+state); // for onPress or onSelect
  12.         }
  13.  

Then I only see values change when the user clicks away from the slide marker and or drags. Like you click somewhere far below or far above the marker or far left, far right depending if it's a horizontal slider. If I try to actually drag the slide marker away from it's original position no values are reported as changed although the marker has been moved. I understand that the bool state is suppose to help detect if selected, or let go but I don't get the trigger to fire if the marker moved from direct contact.

It seems to get worse when trying to resize the collider / center for touch control bias a.k.a mobile phones.

Is this a bug?
Title: Re: UISlider not reporting changed values in UIEventListener
Post by: ArenMook on September 01, 2012, 06:27:32 AM
Use uiSlider.onValueChange += YourCallback.
Title: Re: UISlider not reporting changed values in UIEventListener
Post by: TomA6 on September 01, 2012, 09:19:13 AM
I do not see onValueChange (http://www.tasharen.com/ngui/docs/class_u_i_slider.html) ?

Were you thinking of the private callbacks for onPressThumb & onDragThumb?

In any case I would like to see a callback that can report true/false slider pressed anywhere state for if the slider value changes... Thanks.
Title: Re: UISlider not reporting changed values in UIEventListener
Post by: ArenMook on September 01, 2012, 05:03:41 PM
You just reminded me to update the docs. :)

It's there, it was added about two versions ago. If you don't have it, you should update your NGUI.
Title: Re: UISlider not reporting changed values in UIEventListener
Post by: TomA6 on September 02, 2012, 02:31:25 PM
Thanks I updated to the latest release of NGUI v2.1.6.

But I do not see the point of using:
Use uiSlider.onValueChange += YourCallback.

Isn't this behaving exactly like my first post ?
  1. //      mysliderGO.GetComponent<UISlider>().functionName = "onValueChange";
  2.         mysliderGO.GetComponent<UISlider>().eventReceiver=gameObject;
  3.  
  4.         public void onValueChange (float value) {...   
  5.  

Then I see every change of the slider but I only want to track the value change after the user let's go of the UISlider.

Do you understand that I want to see a Slider Value change only after the user releases the Thumb icon? Let's say that the Thumb is set to 0.1f and the user drags the slider to 1.0f releasing the Thumb marker. I would like to get a slider change reported as 1f. Instead I get every moment the Thumb was dragged from 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1f. Which is reporting overkill in my particular case.

I would expect OnPress to support this behavior...
  1. float sliderValue = 0.5f;
  2.         public void onSliderValueChangeRelease (GameObject sender, bool pressed)
  3.         {
  4.                 if (!pressed) // on finger Released
  5.                 {
  6.                         float selection = sender.GetComponent<UISlider>().sliderValue;
  7.                         sliderValue=(float)System.Math.Round(selection, 2, System.MidpointRounding.AwayFromZero);
  8.                         print(sender.name+" : "+sliderValue+" "+pressed);
  9.                 }
  10.         }

But it doesn't seem to work.  :'( :'( :'( :'( :'( :'( :'(
Title: Re: UISlider not reporting changed values in UIEventListener
Post by: ArenMook on September 02, 2012, 04:11:42 PM
Keep in mind the thumb is a separate object from the slider. If you start dragging by pressing on the thumb, it's the thumb that will get OnPress(true/false) event. if you start dragging by pressing on the slider, the slider will get OnPress(true/false). If you don't want this behavior, disable the collider on the thumb.
Title: Re: UISlider not reporting changed values in UIEventListener
Post by: TomA6 on September 02, 2012, 04:21:02 PM
I'm confused. Are you saying to disable the collider to the Thumb? Then wont the Thumb not slide back and forth? Kinda defeats the purpose.

Or are you saying that I can add a callback to the Thumb with OnPress ? If so can you please provide an example. Thank you.
Title: Re: UISlider not reporting changed values in UIEventListener
Post by: ArenMook on September 02, 2012, 04:28:16 PM
The events that were going to the thumb would automatically fall through to the slider's collider, so everything will move just fine.
Title: Re: UISlider not reporting changed values in UIEventListener
Post by: TomA6 on September 02, 2012, 04:53:43 PM
I see. Thank you for clarifying. I think this will resolve the issue I'm having.  ;D