Author Topic: NGUI 3.0 radio button groups  (Read 7418 times)

wom

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
NGUI 3.0 radio button groups
« on: October 01, 2013, 07:53:36 AM »
Hi,

I'm very new to NGUI and Unity in general - never used the previous versions or the current Unity GUI for that matter.

I'm working on my very first panel, on which I've decided to plonk a bunch of toggle buttons to make up a radio group.
Please keep in mind this is just example functionality so that I can learn about NGUI radio buttons.

I'm setting my target FPS in my application - to do that I've set up 5 toggle buttons for the different values I want to set.

Then I've attached a script to a "FpsRadioGroup" parent container, with these functions:
  1.   private void SetTargetFramerate(int target){
  2.     Application.targetFrameRate = target;
  3.     GameManager.Instance.LogInfo(
  4.       "attempted to target framerate {0}, application now reports {1}",
  5.       target, Application.targetFrameRate);
  6.   }
  7.  
  8.   public void On15FpsSelected(){
  9.     if( UIToggle.current.value ){
  10.       SetTargetFramerate(15);
  11.     }
  12.   }
  13.  
  14.   public void On30FpsSelected(){
  15.     if (UIToggle.current.value) {
  16.       SetTargetFramerate(30);
  17.     }
  18.   }
  19.  
  20.   public void On60FpsSelected(){
  21.     if (UIToggle.current.value) {
  22.       SetTargetFramerate(60);
  23.     }
  24.   }
  25.  
  26. ...
  27.  
  28.  

I was hoping to have NGUI just call the SetTargetFramerate() method directly with a parameter, or something similar (was originally thinking I'd be able to pass in an enum). 
Am I missing something - or is making a callback method for each toggle button in the radio group the right way to do it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.0 radio button groups
« Reply #1 on: October 01, 2013, 07:09:17 PM »
You can create a radio button group by creating several toggles that use the same group ID.

You can have the toggles trigger a remote function by setting it in the On Value Change section of the toggle script. Assuming you've chosen the functions below, it will work as you expect. You can't pass a parameter to the function as it has to be of void type, so the way you are doing it with several void Func (void) type functions calling SetTargetFramerate is correct.

wom

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: NGUI 3.0 radio button groups
« Reply #2 on: October 02, 2013, 01:24:14 AM »
Quote
You can create a radio button group by creating several toggles that use the same group ID.
Yep - did that, and it worked fine (still need the "if UItoggle.current.value" thing because it gets fired with false when a different toggle is selected).

Thanks for the help.