我已经创建了一个切换组,现在我想用一些最简单的方法检索选定的切换项。
与我分享您的建议...
**编辑:**这里有切换组详细信息:
我用这个代码来检查:
public class RandomMatchMakerPanelController : MonoBehaviour
{
public Sprite defaultPlayerPhoto;
//
[Header ("Player-1")]
public Image player1Photo;
public Text player1NameText;
public Text player1CountryText;
public ToggleGroup player1BallGroup;
[Header ("Player-2")]
public Image player2Photo;
public Text player2NameText;
public Text player2CountryText;
public ToggleGroup player2BallGroup;
void OnEnable ()
{
// StartCoroutine (CreateRandomMatches ());
GetSelectedToggle ();
ShowLocalPlayerDetails ();
}
private void ShowLocalPlayerDetails ()
{
if (DataCollection.localPlayer.ProfilePhoto == null)
player1Photo.sprite = defaultPlayerPhoto;
else
player1Photo.sprite = DataCollection.localPlayer.ProfilePhoto;
player1NameText.text = DataCollection.localPlayer.PlayerName;
player1CountryText.text = DataCollection.localPlayer.Country;
}
private void GetSelectedToggle ()
{
// Toggle[] ballToggles = player1BallGroup.GetComponentsInChildren<Toggle> ();
foreach (Toggle toggle in player1BallGroup.ActiveToggles()) {
Debug.Log ("toggle: "+ toggle.isOn);
}
// May have several selected toggles
// foreach (Toggle toggle in ballToggles) {
// if(toggle.isOn)
// }
}
IEnumerator CreateRandomMatches ()
{
yield return new WaitForSeconds (0.25f);
RandomMatchMaker matchMaker = GameObject.FindGameObjectWithTag (GameConstants.TAG_NETWORK_MANAGER).GetComponent<RandomMatchMaker> ();
matchMaker.FindInternetMatch ("Dodgels-");
}
public void OnBackButtonClick ()
{
SoundManager.Instance.PlayButtonClickSound ();
Camera.main.SendMessage (GameConstants.ACTIVATE_RANDOM_MATCH_MAKER_PANEL, false, SendMessageOptions.DontRequireReceiver);
Camera.main.SendMessage (GameConstants.ACTIVATE_RANDOM_PLAYER_GAMEPLAY, false, SendMessageOptions.DontRequireReceiver);
Camera.main.SendMessage (GameConstants.ACTIVATE_MAIN_MENU_PANEL, true, SendMessageOptions.DontRequireReceiver);
}
}
目前,控制台中未显示任何内容,但一次一个切换始终保持活动状态。
2条答案
按热度按时间1qczuiv01#
您可以使用
ActiveToggles()
函数获取所有激活的切换,该函数选择组中激活的切换集。通常,该集合由唯一的切换组成。vd2z7a6w2#
从切换的父级执行以下方法