Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Active toggle in ToggleGroup

Discussion in 'UGUI & TextMesh Pro' started by PhilAllcock, Aug 24, 2014.

  1. PhilAllcock

    PhilAllcock

    Joined:
    Sep 3, 2013
    Posts:
    27
    Hi Guys,

    Is there any way (currently implemented or planned/to be implemented) which will allow code to grab the active toggle(s) from a toggle group without having to loop through a ToggleGroup's children? We already have the ability to check if there are any active toggles from the toggle group, but it would be a lot nicer if we could grab the active toggle(s)

    Thanks
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,183
    API oversight. I have added this locally now.
     
    PhilAllcock likes this.
  3. PhilAllcock

    PhilAllcock

    Joined:
    Sep 3, 2013
    Posts:
    27
  4. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    389
    If you have a ToggleGroup where only one Toggle must be selected, in my case a language selector, how do you make the ToggleGroup remember which Toggle was the one previously selected, after leaving and returning to the scene?

    Thanks
     
  5. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Are you using PlayerPrefs?
    And calling Save()? https://docs.unity3d.com/ScriptReference/PlayerPrefs.Save.html
     
  6. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    389
    No, I have not tried Save()

    Will report later and thanks a lot!
     
  7. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    389
    I asked around and got terrific answers, all of which pointed to persistent data, like you also mentioned.

    But I realized I was using SystemLanguage so I could get the language users had selected and update Toggles accordingly.

    Thanks a lot

    Code (CSharp):
    1. void SetActiveToggle () {
    2.         switch (LanguageController.GetLanguage())
    3.         {
    4.             case SystemLanguage.English:
    5.                 _aryOfToggles[0].isOn = true;
    6.                 break;
    7.             case SystemLanguage.Unknown:
    8.                 _aryOfToggles[1].isOn = true;
    9.                 break;
    10.             case SystemLanguage.French:
    11.                 _aryOfToggles[2].isOn = true;
    12.                 break;
    13.             case SystemLanguage.Spanish:
    14.                 _aryOfToggles[3].isOn = true;
    15.                 break;
    16.             case SystemLanguage.German:
    17.                 _aryOfToggles[4].isOn = true;
    18.                 break;
    19.             default:
    20.                 break;
    21.         }
    22.     }
     
    IzzySoft likes this.