} //父菜单是否可以点击 public void Init(RectTransform rect, int count, Type t, IList dataList = null) { if (!typeof(ParentItem).IsAssignableFrom(t)) { throw new Exception("传入类型必须是ParentItem的派生类"); } childMenu = transform.Find("childMenu").gameObject; itemRect = rect; this.count = count; childs = new RectTransform[this.count]; offset = new Vector3(0, itemRect.rect.height); for (int i = 0; i < this.count; i++) { childs[i] = Instantiate(itemRect, childMenu.transform); ParentItem parentComponent = childs[i].GetComponent(t) as ParentItem; if (parentComponent == null) { parentComponent = childs[i].gameObject.AddComponent(t) as ParentItem; } parentComponent.FindItem(childs[i]); parentComponent.FillItem(dataList[i]); childs[i].gameObject.SetActive(true); } childMenu.gameObject.SetActive(false); isOpening = false; isCanClick = true; GetComponent <Button>().onClick.AddListener(OnButtonClick); }
public void CreatScrool(IDictionary info, Type t, Type t1) { if (!typeof(ParentItem).IsAssignableFrom(t)) { throw new Exception("传入类型必须是ParentItem的派生类"); } if (!typeof(ParentItem).IsAssignableFrom(t1)) { throw new Exception("传入类型必须是ParentItem的派生类"); } if (!isHorizontal) { parentOffset = new Vector3(0, parentRect.rect.height); childOffset = new Vector3(0, childRect.rect.height); parentArr = new RectTransform[info.Count]; cntArr = new int[info.Count]; //初始化content高度 content.sizeDelta = new Vector2(content.rect.width, parentArr.Length * parentRect.rect.height); var Values = info.Values.GetEnumerator(); var Keys = info.Keys.GetEnumerator(); int i = 0; while (Keys.MoveNext()) { IList list = info[Keys.Current] as IList; cntArr[i] = list.Count; parentArr[i] = Instantiate(parentRect, content.transform); ParentItem parentComponent = parentArr[i].GetComponent(t) as ParentItem; if (parentComponent == null) { parentComponent = parentArr[i].gameObject.AddComponent(t) as ParentItem; } parentComponent.FindItem(parentArr[i]); parentComponent.FillItem(Keys.Current); parentArr[i].localPosition -= i * parentOffset; parentArr[i].GetComponent <ParentMenu>().Init(childRect, list.Count, t1, list); int j = i; parentArr[i].GetComponent <Button>().onClick.AddListener(() => { OnButtonClick(j); }); parentArr[i].gameObject.SetActive(true); i++; } } }