美文网首页
ToggleGroup组件

ToggleGroup组件

作者: 字子夜 | 来源:发表于2018-12-29 14:09 被阅读0次

需求:下面的Toggle是一组,有共同的ToggleGroup,如何获取你当前选择的Toggle.

解决:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

public class ToggleGroupTest : MonoBehaviour

{

    //ToggleGroup toggleGroup;

// Use this for initialization

void Start () {

        //toggleGroup = transform.GetComponentInChildren<ToggleGroup>();

        List<Toggle> toggleList = new List<Toggle>(transform.GetComponentsInChildren<Toggle>());

        foreach (Toggle item in toggleList)

        {

            item.onValueChanged.AddListener(delegate(bool isOn)

            {

                if (isOn)

                {

                    Debug.Log(item.name + "被选中了");

                }

            });

        }

}

相关文章

网友评论

      本文标题:ToggleGroup组件

      本文链接:https://www.haomeiwen.com/subject/icgulqtx.html