Author Topic: Killing UISlider input  (Read 11697 times)

stapledon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Killing UISlider input
« on: February 25, 2014, 10:56:59 AM »
I've got a UISlider and a pop-up UI.

The pop-up UI appears if a condition isn't met when sliding the slider.

I have a script which toggles collisions in the UI. This works for buttons.

The slider however continues to trigger it's OnValueChange as long as the user keeps the mouse down and drags.

What's the proper way to disable a slider (and other UI Components)? I need the UI to stay visible, so SetActive isn't an option, and setting the UISlider.enabled = false doesn't work either -- continuing to drag seems to just keep it alive.

Perhaps I've a bug in my code, I'm still looking because it's driving me a bit nuts, but am I doing something that isn't NGUI friendly here?


stapledon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Killing UISlider input
« Reply #1 on: February 25, 2014, 11:19:17 AM »
Ok so I've have to set some flags to bypass OnValueChange calls.

However the slider is still draggable. It's collider can't be disabled, I expect this is by design, and putting a UISlider.enabled = false on a timer and re-enabling it... it works, but the thing is still dragging if you don't release the mouse when it's re-enabled. FFS.

A similar post:

http://www.tasharen.com/forum/index.php?topic=1062.0

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Killing UISlider input
« Reply #2 on: February 25, 2014, 01:40:00 PM »
Disabling the ability to drag the slider is trivial:
  1. slider.collider.enabled = false;
Canceling the current drag operation:
  1. UICamera.currentTouch.pressed = null;
  2. UICamera.currentTouch.dragged = null;

stapledon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Killing UISlider input
« Reply #3 on: February 25, 2014, 05:09:59 PM »
Yeah the collider disabling is obvious, but it refuses to be disabled, either in code or manually in the inspector. The only difference between my slider and the example sliders is, I have the Background sprite on the same GO as the UISlider component...is that an issue?

The currentTouch code is very useful though, thanks for that.



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Killing UISlider input
« Reply #4 on: February 26, 2014, 03:10:17 PM »
Disabling the collider will flat out prevent events from being received. However it won't stop the current set of drag events. Once the drag operation begins, it's locked onto a specific object, and disabling the collider won't help. Setting the currentTouch pressed and dragged to null should, however.

richardn66

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Killing UISlider input
« Reply #5 on: April 18, 2014, 06:59:29 AM »
I am also having a problem disabling a UISlider.
I have 2 sliders in the scene used for selecting the volume for Music and Effects with each having a Mute checkbox.
When clicking the Mute checkbox I want to disable the respective slider.
Although I can get the UISlider component I have a problem disabling it.
I found that if I disabled the Box Collider when running the scene through the Editor worked I could not programmatically do this as it appears to be resetting the collider to being enabled.
I have tried the isEnabled for the the slider object and this partially works.
When I load the scene the saved settings are loaded and each Mute checkbox is set accordingly and then it will find the respective slider and set it (slider.enabled = !isChecked;). This works as it appears to remove the UIEvent Listener Script (UIEventListener) component; and when I uncheck the Mute checkbox (and thus the enabled state of the slider is changed back to enabled) the listener component is added.
However, when I change a checkbox so that it is checked and thus the slider should be disabled the UIEvent Listener Script component is not removed - if i deleted the component when running the scene then the slider is disabled (wont change the value when clicking/dragging) but then clicking on the Mute checkbox the slider does not re-add the listener component even though the slider has been set to enabled.

I will try to do a work around whereby after enabling the slider it will check whether the component exists and if it doesn't then it will add it and when disabling then the reverse.

richardn66

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Killing UISlider input
« Reply #6 on: April 18, 2014, 08:04:05 AM »
Found that I don't need to change the UISlider code or add a method to it instead you can change the slider's collider enabled state (no need to look for the Box Collider) - slider.collider.enabled = !isChecked;


This switches the box collider on/off and thus means that when off both the slider can't be moved and the colours of the slider (background and foreground) won't tween.
« Last Edit: April 18, 2014, 08:18:19 AM by richardn66 »