Author Topic: UIToggle... how to use?  (Read 11484 times)

Haim

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
UIToggle... how to use?
« on: October 12, 2013, 12:50:48 PM »
Hi,

i'm kind of new to NGUI, i want to create menu with radio selection and i found out that i need to use UItoggle for this.
so i managed to create the menu structure but i don't know how to read the values of it.
means, i don't know how to check which option i selected...

can anyone help with sample code?

thanks!
« Last Edit: October 13, 2013, 02:17:05 PM by Haim »

Haim

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: UIToggle... how to use?
« Reply #1 on: October 13, 2013, 07:19:32 AM »
as a temporary fix i added a button message script on each option but i'm sure there is a smarter way to do that.
so if any one can help, please do so...

thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIToggle... how to use?
« Reply #2 on: October 13, 2013, 10:05:27 AM »
UIToggle.current.value

Haim

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: UIToggle... how to use?
« Reply #3 on: October 13, 2013, 10:10:39 AM »
hmmm.... yes, right... this should return if one of the option is selected... as far as i understand.
but how do i know which option?
say i have 5 options? how do i know which one is selected?
what if i have multiple groups of radio buttons? how do i access to each group?




ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIToggle... how to use?
« Reply #4 on: October 13, 2013, 10:13:15 AM »
UIToggle.current is the reference to the UIToggle. Do what you want with it. You can also always do UIToggle.list and loop through them, matching the group ID of your choice if you need all of them.

Haim

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: UIToggle... how to use?
« Reply #5 on: October 13, 2013, 10:22:55 AM »
can you point me to some code sample? or something?
the samples that come with NGUI (full version... yes,i paid for it) doesn't show how to use it with code.
and the class reference on the web doesn't show code samples as well.

this might be obvious for experienced programmer but not for me...

thanks.

Haim

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: UIToggle... how to use?
« Reply #6 on: October 13, 2013, 02:15:49 PM »
well, i got it... i hope:

  1. public void CheckSelectedOptions ()
  2.         {
  3.                 if(UIToggle.current.name=="ThePhantom" && UIToggle.current.value ){
  4.                         gamestate.Instance.setPlaneType ("Phantom");
  5.                         Debug.Log (UIToggle.current.name);
  6.                         }
  7.                        
  8.                         if(UIToggle.current.name=="TheSpider"  && UIToggle.current.value){
  9.                         gamestate.Instance.setPlaneType ("Spider");
  10.                         Debug.Log (UIToggle.current.name);
  11.            
  12.                         }
  13.            
  14.         }

drag the object with the script to "on value change" -> "notify" and selected the method.
i hope i'm doing it right... any way it's works like that.

i had to dig youtube for your video "NGUI 3 tutorial", in minute 29 you describe something like this...
it wasn't too hard once i got it and i believe you could explain this in a second.




 

« Last Edit: October 13, 2013, 02:46:30 PM by Haim »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIToggle... how to use?
« Reply #7 on: October 13, 2013, 09:18:21 PM »
It's one way to do it, sure. You could also create two different functions -- one called SetToPhantom() another -- SetToSpider(), and have each the "ThePhantom" toggle reference the former, and "TheSpider" reference the latter. Then inside the functions just check the UIToggle.current.value state. No need to match names.

Haim

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: UIToggle... how to use?
« Reply #8 on: October 14, 2013, 06:49:53 AM »
this is what i have done in first place but for some reason it seems that every time i change selection both method run.
never mind... it works now.

i just learned from other post that you develop uGUI. hope you doing good job like you doing on NGUI... :)

thanks for you help.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIToggle... how to use?
« Reply #9 on: October 14, 2013, 09:47:54 AM »
Yes, both methods will be executed. One to indicate that the state is now 'false', the other indicating that the state is now 'true'.