Author Topic: UIToggle  (Read 52881 times)

Quen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: UIToggle
« Reply #30 on: March 09, 2014, 06:35:55 AM »
Thank You

Worked perfectly :-)

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: UIToggle
« Reply #31 on: June 07, 2014, 03:39:35 AM »
I have a couple toggles as children of a uisprite working as a menu.

When i toggle the root gameobject in Start the check texture for both toggles disappear.  the values of both toggles are correct but the display is wrong.

  1. //Menu_Test_GO.SetActive(Menu_Test_Toggle);
  2.  

any ideas?  if i comment out the line in Start and leave the menu showing - the toggle works as it should.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIToggle
« Reply #32 on: June 07, 2014, 09:42:55 PM »
Based on my understanding of your description, no -- I can't say that I do. I gave it a test on my end -- created a toggle as a child of a widget. Put a script on the widget that reacts to OnClick (and gave it a collider). In OnClick I set the SetActive state to the opposite of what it is now, targeting the child game object (the toggle). All works as expected.

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: UIToggle
« Reply #33 on: June 08, 2014, 01:34:56 PM »
after struggling with this for several days now.  i do not think it is specific to the uitoggle.  rather that the "check" texture is disappearing.  i am using ngui prefab's.

also, the background of the colored slider disappears around 90% of the time.  oddly enough it does appear at random though.  this control is also a child to the same background sprite.  all the controls/values are working correctly - its the disappearing texture that is the problem.  weird because another slider background works fine that isnt related to that group of controls.

attached is a screenshot of the hierarchy.  i will start over and see if the results are the same.


edit:  adding everything as a child to a parent panel has fixed the toggles.  it must have been some sort of depth issue in combination with bad hierarchy child.
« Last Edit: June 08, 2014, 06:01:04 PM by devomage »

Huacanacha

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: UIToggle
« Reply #34 on: June 11, 2014, 04:36:21 PM »
I had a problem with this script overriding the alpha of the activeSprite.  My 'on' state sprite had about 60% alpha but UIToggle would always set it to a glaring 100% opacity.  Here's my solution... I recommend adding something like this in an NGUI update.

1. Add a float targetAlpha field.

2. Put this first thing in Start()
  1. if (activeSprite != null) {
  2.         targetAlpha = activeSprite.color.a;
  3. }

3. Replace the 3-4 instances of "1f" with targetAlpha

Enjoy!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIToggle
« Reply #35 on: June 12, 2014, 02:41:49 AM »
Don't modify code. Remember -- alpha is nested. So if you have this:

UIWidget (alpha 60%)
- Sprite (tween alpha)

...then everything will work as expected.

Huacanacha

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: UIToggle
« Reply #36 on: June 12, 2014, 02:53:48 AM »
Ok.  I've reverted to this method.  I'd much rather not modify code unless absolutely necessary.

It does seem counter-intuitive to me that a toggle has side effects.  Wouldn't turning the game object on/off be a much cleaner way to achieve this?

derkoi

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 57
    • View Profile
Re: UIToggle
« Reply #37 on: June 15, 2014, 11:00:43 AM »
I'm instantiating a group of Toggles but laid out like a list box (see attached image) for each .txt file in a folder.

I need to know if any of the Toggles in the groups state has changed and if so, run a function in my script. Now I know I can get the active toggle but I'm not sure when I should do this? Not every frame I assume? Hence why I'd like to know when a toggle in the groups state has changed then I can get the active toggle and process accordingly.

So, how can I find which toggle in a group is active only when the selection changes?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIToggle
« Reply #38 on: June 16, 2014, 09:12:12 AM »
@Huacanacha: Toggle transitions smoothly by adjusting the alpha. Swapping active state won't give a smooth transition.

@derkoi: UIToggle.curent always tells you what toggle triggered the event, and UIToggle.list is an up-to-date list of all the active toggles in the scene that you can loop through if you like.

ArtemKoval

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: UIToggle
« Reply #39 on: July 07, 2014, 05:06:08 AM »
Hi!

I'm not sure whether my question belongs here, but it's for sure related to UIToggle.

I've got simple controls setup:
1. Grid of buttons which are tabs headers. Buttons have UIToggle and UIToggled objects.
2. For each header tab I've got Widget -> ScrollView -> Grid -> Bunch of buttons.
3. Each header tab is set up to activate it's ScrollView and deactivate others.

Each button in a ScrollView has a script attached with logic to disable this button and disable specified button in other ScrollView (which is inactive at the time when child button is disabled).

So logically everything works fine. But I've got strange visual effect.

1. Press and effectively disable button in active scroll view
2. Then click on other header tab and its' ScrollView become visible
3. (BUG) For a split second disabled button in a newly activated ScrollView is enabled and then it become disabled.

What can be the source of such problem?

Thanks, Artem.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIToggle
« Reply #40 on: July 08, 2014, 01:20:52 PM »
Only set things it should activate. The deactivate state is going to be done by default.

ArtemKoval

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: UIToggle
« Reply #41 on: July 08, 2014, 01:56:28 PM »
Hi!

It's setup like you've said. But unwanted effect is still there. Please take a look at this short video https://dl.dropboxusercontent.com/u/19764309/Caelum%202014-07-08%2022-48-05-01.avi

And this is screenshot of how things are setup at the moment

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIToggle
« Reply #42 on: July 09, 2014, 02:34:46 PM »
Button state change is not immediate unless you make it so. Look at UIButton.SetState function. It has a boolean that determines whether the change should be immediate or not.

ArtemKoval

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: UIToggle
« Reply #43 on: July 10, 2014, 01:25:02 AM »
Hi!

Thanks, that was the problem together with minor logic bug.

Regards, Artem.

jimbob926

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: UIToggle
« Reply #44 on: July 15, 2014, 11:09:23 AM »
How do I make it so that the original sprite fades out and the new one fades in, like a toggleable button? At the moment, the new sprite just gets faded in on top of the original one.