public void BindData <T>(string templatedName, List <T> dataList, System.Action <GameObject, T> bindEvent, bool itemCanClick = true, bool showSelectedItem = false) { ShowSelectedItem = showSelectedItem; int childCount = Content.transform.childCount; for (int i = childCount - 1; i >= 0; i--) { MultiObjectManager.Despawn(Content.transform.GetChild(i)); } float totalHeight = 0; foreach (T t in dataList) { Transform item = MultiObjectManager.Spawn(templatedName); item.GetComponent <RectTransform>().SetParent(Content.transform); if (itemCanClick) { Button btnCtr = item.GetComponent <Button>(); if (btnCtr != null && item.GetComponent <ButtonClickListener>() == null) { ButtonClickListener btnListener = item.gameObject.AddComponent <ButtonClickListener>(); btnListener.OnClick = MenuItem_OnClicked; btnCtr.transition = Selectable.Transition.None; btnCtr.onClick.RemoveAllListeners(); btnCtr.onClick.AddListener(() => { btnListener.OnClicked(); }); } } bindEvent(item.gameObject, t); if (item.GetComponent <LayoutElement>() != null) { totalHeight += item.GetComponent <LayoutElement>().preferredHeight; } } }
public void Clear() { int childCount = Content.transform.childCount; for (int i = childCount - 1; i >= 0; i--) { MultiObjectManager.Despawn(Content.transform.GetChild(i)); } }
public void ClearAll() { int childCount = Content.transform.childCount; for (int i = childCount - 1; i >= 0; i--) { Transform child = Content.transform.GetChild(i); if (child.name == "ListHeader" || child.name == "ListFooter") { continue; } MultiObjectManager.Despawn(Content.transform.GetChild(i)); } }
private void CreateItem(int index, ref float totalHeight) { Transform item = MultiObjectManager.Spawn(TemplatedName, Content.transform); RectTransform itemRect = item.GetComponent <RectTransform>(); //itemRect.SetParent(Content.transform); if (item.GetComponent <DataItemControl>() == null) { item.gameObject.AddComponent <DataItemControl>(); } item.GetComponent <DataItemControl>().DataIndex = index; BindEvent(item.gameObject, DataList[index]); float offsetMinY = -totalHeight - itemRect.GetComponent <LayoutElement>().preferredHeight - Spacing; float offsetMaxY = -totalHeight - Spacing; if (!ItemList.ContainsKey(index)) { ItemList.Add(index, new ItemLayoutInfo() { MinOffsetY = offsetMinY, MaxOffsetY = offsetMaxY }); } //设置item的位置 itemRect.anchoredPosition3D = new Vector3(0, 1, 0); itemRect.offsetMax = new Vector2(0, offsetMaxY); itemRect.offsetMin = new Vector2(0, offsetMinY); totalHeight += itemRect.GetComponent <LayoutElement>().preferredHeight + Spacing; if (ItemCanClick) { Button btnCtr = item.GetComponent <Button>(); if (btnCtr != null && item.GetComponent <ButtonClickListener>() == null) { ButtonClickListener btnListener = item.gameObject.AddComponent <ButtonClickListener>(); btnListener.OnClick = MenuItem_OnClicked; btnCtr.transition = Selectable.Transition.None; btnCtr.onClick.RemoveAllListeners(); btnCtr.onClick.AddListener(() => { btnListener.OnClicked(); }); } } }
private Transform ClearOutMask() { Vector3[] myCorners = new Vector3[4]; this.GetComponent <RectTransform>().GetWorldCorners(myCorners); int childCount = Content.transform.childCount; for (int i = childCount - 1; i >= 0; i--) { Transform child = Content.transform.GetChild(i); if (child.GetComponent <DataItemControl>() == null) { continue; } if (!IsInMask(myCorners, child.GetComponent <RectTransform>())) { MultiObjectManager.Despawn(child); } } return(null); }
protected override void Init() { base.Init(); MultiObjectManager.Load(GameObject.Find("MultiObjectManager")); Footer.ExcuteInit(); FriendBox.ExcuteInit(); EventListener.Get(MaJiang.gameObject).onClick = OnMaJiangClicked; EventListener.Get(DiaoSanGong.gameObject).onClick = OnDiaoSanGongClicked; EventListener.Get(ButtonJion.gameObject).onClick = OnButtonJionClicked; EventListener.Get(ButtonCreat.gameObject).onClick = OnButtonCreatClicked; EventListener.Get(ButtonJFind.gameObject).onClick = OnButtonJFindClicked; EventListener.Get(ButtonGoldBattle.gameObject).onClick = OnButtonGoldBattleClicked; EventListener.Get(ButtonDiamonBattle.gameObject).onClick = OnButtonDiamonBattleClicked; EventListener.Get(ButtonDiamon10.gameObject).onClick = OnButtonDiamonClicked; EventListener.Get(ButtonDiamon50.gameObject).onClick = OnButtonDiamonClicked; EventListener.Get(ButtonDiamon100.gameObject).onClick = OnButtonDiamonClicked; EventListener.Get(BtnDay7.gameObject).onClick = OnBtnDay7Clicked; EventListener.Get(BtnTask.gameObject).onClick = OnBtnTaskClicked; EventListener.Get(PokerType1.gameObject).onClick = OnPokerTypeClicked; EventListener.Get(PokerType2.gameObject).onClick = OnPokerTypeClicked; EventListener.Get(PokerType3.gameObject).onClick = OnPokerTypeClicked; EventListener.Get(PokerType4.gameObject).onClick = OnPokerTypeClicked; EventListener.Get(PokerType5.gameObject).onClick = OnPokerTypeClicked; SoundManager.Instance.PlayBackground("音效/背景音乐"); UpdateAccountData(); }