public ToggleGroup m_kinGroup; // 见上图中的 Kin Group的设置
void Awake()
{
// 需要动态变化;
m_Grid.sizeDelta = new Vector2(m_Grid.sizeDelta.x, 101 * 20);
}
//刷新帮会列表
public void OnKinListUpdate(gamelogic_KinJoinOnKinListUpdate_C listInfo)
{
...
// 设置Group
Toggle tg = gridKinList.items[gridKinList.items.Count - 1].GetComponent<Toggle>();
if (tg)
{
tg.group = m_kinGroup;
}
}
-----------------------------------------------------------------------------------------------------------------------------------
// 实例化预制件,加入到UI中
GameObject tmpKinItemInfoCell = GameObject.Instantiate(m_KinItemInfoCellPrefab);
tmpKinItemInfoCell.transform.SetParent(m_Grid.transform, false);
// 加入父容器中
Toggle toggle = tmpKinItemInfoCell.GetComponent<Toggle>();
if (toggle != null)
{
toggle.group = m_kinGroup;
}
// 注册点击事件监听
toggle.onValueChanged.AddListener(cell.OnClick);
-----------------------------------------------------------------------------------------------------------------------------------
或者
在Cell中设置点击事件:
void Awake()
{
Toggle tg = GetComponent<Toggle>();
if (tg)
{
tg.onValueChanged.AddListener(OnClick);
}
}