Author Topic: How to disable just the slider or any element in the ngui in code...  (Read 11782 times)

sk1989

  • Guest
Hi, I just want to know how to disable and enable slider.


normally in unity you can disable things by setting the enabled to false.

just wondering how to do it for NGUI elements.

Thanks in advance...

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: How to disable just the slider or any element in the ngui in code...
« Reply #1 on: July 18, 2012, 01:47:59 PM »
When you say "disable" do you mean:

A)  Make them inactive so they do not respond to input, yet are still visible or

B)  Deactivate and hide them.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to disable just the slider or any element in the ngui in code...
« Reply #2 on: July 18, 2012, 02:30:21 PM »
NGUITools.SetActive(sliderGameObject, false).

StridingDragon

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
How would you go about making the slider visible and generate OnHover() events, but not respond to mouse clicks? I'm using them for health bars, but the sliders' inherent ability to be adjusted using the mouse interferes with that somewhat.  ;)
« Last Edit: May 17, 2013, 08:27:43 PM by StridingDragon »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Put the collider on the background sprite instead of the slider, and do your OnHover handling there. If you need, forward press events to the actual slider game object.

StridingDragon

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
It works but boy, does it create convoluted code, especially since I have numerous sliders in the same panel. There's no better way? No way, to just tell the slider to ignore mouse presses and drags?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Slider script was designed with event handling in mind. You could write your own slider that does exactly what you need it to. Use the slider code as the template.

StridingDragon

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
Just sent you an expanded version of the UISlider that allows people to turn user interaction on and off through a Toggle in the Editor. Hope you can use it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You are welcome to post those two files here as an attachment in case someone else needs this functionality.

StridingDragon

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
Here are expanded versions of NGUI's UISlider component. This version has a toggle in the Inspector to make it static, which means that the user will not be able to manipulate it with the mouse or keyboard. Unlike simply removing the collider from the object to achieve the same result, this version still generates an onHover event, making it perfect for bar graphics, such as health bars, etc. where additional information, such as the actual points) can be displayed as an OnHover tooltip.

Note: These files replace the original files, which means that they will be overwritten by the next NGUI update in your Assets folder, unless our friend Arenmook should decide to actually make these expanded versions part of the package. *hint* *hint*