Author Topic: UIToggle  (Read 52932 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIToggle
« Reply #45 on: July 16, 2014, 12:02:01 AM »
Exactly like that. Have one sprite cover the other and fade out the top one.

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: UIToggle
« Reply #46 on: August 07, 2014, 04:08:48 AM »
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.

when loading a large amount of data in the Start() method, NGUI in general does weird stuff.  i moved my data init's to another scene and it fixed the oddities completely.  for example, my scrollview scrollbars were disabling themselves randomly at start.  similar to the uitoggle problems several weeks back.

fyi for someone who might have a similar problem...

hangemHigh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UIToggle
« Reply #47 on: September 06, 2014, 04:20:07 AM »
I want to toggle UIToggle programmatically. I've been stuck here for hours. Is there any function to do this?
Below is what I have.
public UIToggle soundchkbox;
soundchkbox= soundchkbox.GetComponent<UIToggle>();
soundchkbox.startsActive = true;

I can read the value but I want to be able to toggle it programmatically. Any help will be appreciated. Thanks.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIToggle
« Reply #48 on: September 07, 2014, 08:51:17 AM »
UIToggle.value = true;

radu1234

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: UIToggle
« Reply #49 on: October 28, 2014, 06:59:34 PM »
Hello,

Hope this isn't already answered somewhere else. So I have two UIToggles which both do exactly the same thing, but are placed on different "pages" and have different names. And I want when I modify one of them, the other to change it's state automatically. Basically like reverse radio buttons, when I press one, the other changes accordingly to match it, not be opposite.

Is there an easy way to do this ?

Thank you in advance ! Great GUI by the way ;)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIToggle
« Reply #50 on: October 29, 2014, 05:37:11 AM »
Hmm... well, you can have one toggle's OnChange state call a function that would set the other's state as well. Problem is I assume you want it backwards as well, but if you set the 2nd one's state to change the first, then you effectively end up with a circular reference, which is bad. I would suggest having some kind of a controller class. When you change one toggle's value, it tells the controller which then ensures that both toggles have the correct state.

radu1234

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: UIToggle
« Reply #51 on: October 29, 2014, 09:29:47 AM »
Hmm, I understand, so i'll have to program some trick to do it.

Thanks a lot for your quick response ;)

Have a nice day !

PabloAM

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 58
    • View Profile
Re: UIToggle
« Reply #52 on: November 07, 2014, 12:53:03 PM »
Hello I have done a toggle buttons that shows a list.

When loads Scene, the button is clicked and shows correct list. But when I press a button to move the panels of list, button toggle disappear.

Why that happen?

Attached some screens:


Thanks!!

srgcrafty

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UIToggle
« Reply #53 on: January 29, 2015, 04:00:43 PM »
Hey ArenMook,

I am having an issue with the fact that UIToggle calls OnValueChanged on startup. I have a couple UIToggles in a menu, as part of a HUD, one of which is for enabling/disabling the minimap. Because this menu is not enabled when the payer starts the game, and only when they hit the Options button, I don't want the minimap to suddenly get turned off (or on for that matter) when they open up the menu with the UIToggle component in it. Is there a way to make sure that this is not called when the player first opens up the menu (thus, disabling the GameObject)?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIToggle
« Reply #54 on: January 30, 2015, 03:06:41 PM »
OnValueChanged is called for consistency to ensure that the callbacks are in the same state as the toggle. If you don't want it, check something inside your callback itself -- is it done loading etc? No? Ignore.

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: UIToggle
« Reply #55 on: October 23, 2015, 03:45:27 AM »
We have 3 windows, each of which have their own buttons which run a tween to open and close them. The buttons also have a toggle to highlight or not depending on whether the window is open or closed.

Each button can also close either of the other windows if the are open, by running the other window's tween.

The problem is how to control the toggle on the button associated with the "other" windows.

I can't see how to do this using standard NGUI features, and after having been through all the posts on here but don't see how to control the state of a toggle from script.

Thanks in advance for any suggestions.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIToggle
« Reply #56 on: October 24, 2015, 04:59:07 AM »
Control the toggle on the button associated with the other windows? I am not sure what you mean.

Assuming your toggles are in the same group, one toggle's activation will automatically deactivate others.

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: UIToggle
« Reply #57 on: October 29, 2015, 03:43:55 AM »
Thanks for the response, have found it which is simply:

UIToggle B1Tog = GameObject.Find("B1").GetComponent<UIToggle>();
B1Tog.value = false;
« Last Edit: October 29, 2015, 04:12:59 AM by KeithT »

amraffay

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: UIToggle
« Reply #58 on: October 02, 2016, 02:42:01 PM »
In some other ui kits, whenever there is UIToggle, there is also another component like ToggleGroup which is used for adding event listeners.

Currently if we have 10 toggles with a group of lets say 2 (radio buttons) then we have to attach event to all those 10 toggles. But with a single ToggleGroup we can do the same thing.

I checked UIToggle code
  1. // Uncheck all other toggles
  2.                         if (group != 0 && state)
  3.                         {
  4.                                 for (int i = 0, imax = list.size; i < imax; )
  5.                                 {
  6.                                         UIToggle cb = list[i];
  7.                                         if (cb != this && cb.group == group) cb.Set(false);
  8.                                        
  9.                                         if (list.size != imax)
  10.                                         {
  11.                                                 imax = list.size;
  12.                                                 i = 0;
  13.                                         }
  14.                                         else ++i;
  15.                                 }
  16.                         }

A quick dirty solution is to dispatch a static event from there, so no need of a adding listeners to all 10 toggles.

Can you provide a better solution here?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIToggle
« Reply #59 on: October 11, 2016, 10:55:21 AM »
You don't need to assign listeners to all of them. Just one. When you have a grouped toggle, activating one will automatically deactivate another. Inside your callback, simply check which toggle in your group has the 'true' state.