private MenuButtonItem FindMenuButtonItem(string buttonName, MenuButtonItem item = null) { List <MenuButtonItem> itemList = item.GetChilds(); if (itemList != null) { for (int i = 0; i < itemList.Count; i++) { if (itemList[i].buttonName == buttonName) { return(itemList[i]); } } for (int i = 0; i < itemList.Count; i++) { if (itemList[i] != null) { MenuButtonItem data = FindMenuButtonItem(buttonName, itemList[i]); if (data != null) { return(data); } } } } return(null); }
public void Add(MenuButtonItem item, string parentName = null) { if (string.IsNullOrEmpty(item.rootButtonName)) { if (menuButtonList == null) { menuButtonList = new List <MenuButtonItem>(); } menuButtonList.ForEach(x => { if (x.buttonName == item.buttonName) { Debug.Log("菜单父类名称重复"); return; } }); GameObject buttonObj = (GameObject)Instantiate(rootButton); buttonObj.transform.SetParent(transform); buttonObj.GetComponentInChildren <Text>().text = item.buttonName; buttonObj.SetActive(true); buttonObj.name = item.buttonName; menuButtonList.Add(item); buttonObj.GetComponent <Button>().onClick.AddListener(() => { CloseWindow(); MenuButtonItem data = FindMenuButton(item.buttonName); if (data != null && data.GetChilds() != null && data.GetChilds().Count != 0) { GameObject viewObj = CreateComponent(data, buttonObj.transform); viewObj.GetComponent <MenuButtonComponent>().SetPostion(new Vector2(0, -buttonObj.GetComponent <RectTransform>().sizeDelta.y)); } }); } else { MenuButtonItem parentItem = FindMenuButtonItem(item.rootButtonName, parentName); if (parentItem != null) { parentItem.AddChild(item); } else { Debug.Log(parentName + "失踪"); } } }
public GameObject CreateComponent(MenuButtonItem data, Transform parent) { backGround.SetActive(true); GameObject viewObj = (GameObject)Instantiate(defaultButtonView); viewObj.transform.SetParent(parent); viewObj.SetActive(true); viewObj.GetComponent <MenuButtonComponent>().Init(data.GetChilds()); return(viewObj); }
public void CreateButton(MenuButtonItem item) { if (item == null) { return; } GameObject buttonObj = (GameObject)Instantiate(defaultButton); buttonObj.transform.SetParent(transform); buttonObj.SetActive(true); buttonObj.GetComponent <MenuButton>().onClick.AddListener(() => { item.GetClick(); menuButtonView.CloseWindow(); }); buttonObj.GetComponent <MenuButton>().action = () => { ClearChild(); if (item.GetChilds() != null && item.GetChilds().Count != 0) { GameObject viewObj = menuButtonView.CreateComponent(item, buttonObj.transform); childView = viewObj.GetComponent <MenuButtonComponent>(); viewObj.GetComponent <MenuButtonComponent>().SetPostion(new Vector2(buttonObj.GetComponent <RectTransform>().sizeDelta.x, 0)); } }; buttonObj.GetComponentInChildren <Text>().text = item.buttonName; buttonObj.name = item.buttonName; if (item.hasLine) { GameObject line = (GameObject)Instantiate(lineObj); line.transform.SetParent(transform); line.SetActive(true); } if (item.enableCheckEvent != null && !item.enableCheckEvent.Invoke()) { buttonObj.GetComponent <MenuButton>().interactable = false; } }