float CreateItemView(HeroData heroData, float position) { GameObject go = Object.Instantiate(m_itemViewPrefab.gameObject) as GameObject; RectTransform rectTrans = go.transform as RectTransform; rectTrans.anchorMin = new Vector2(0.5f, 1); rectTrans.anchorMax = new Vector2(0.5f, 1); rectTrans.pivot = new Vector2(0.5f, 1); rectTrans.SetParent(m_contentTransform, false); rectTrans.anchoredPosition = new Vector2(0.5f, -position); // Setting the itemView HeroListItemView itemView = go.GetComponent <HeroListItemView>(); itemView.SetToggleGroup(GetToggleGroup()); itemView.SetData(heroData); itemView.onSelected = OnItemViewSelected; m_itemViewList.Add(itemView); // return(position + rectTrans.sizeDelta.y + m_spacing); //itemView.toggle }
void OnItemViewSelected(HeroListItemView itemView, bool isSelected) { if (itemView == null) { return; } HeroData hero = itemView.data; if (isSelected) { m_selectedHero = hero; } if (onSelected != null) { onSelected(this, m_selectedHero); } }