public void OnClick() { if (node.children.Count > 0) { if (!panelOpen) { RectTransform panel = Instantiate(panelPrefab, CLIManager.Instance.transform).GetComponent <RectTransform>(); panel.SetParent(CLIManager.Instance.transform); CLIMenu.Instance.openPanels.Add(panel); //RectTransform parent = transform.parent.GetComponentInParent<RectTransform>(); RectTransform parentPanel = transform.parent.GetComponent <RectTransform>(); //panel.anchoredPosition = parent.anchoredPosition + new Vector2(parent.rect.width, 0); panel.anchoredPosition = parentPanel.anchoredPosition + new Vector2(parentPanel.rect.width, rectTransform.anchoredPosition.y); foreach (var n in node.children) { RectTransform menuItem = Instantiate(menuItemPrefab).GetComponent <RectTransform>(); menuItem.SetParent(panel); menuItem.GetComponentInChildren <Text>().text = n.name; CLIMenuItem m = menuItem.GetComponent <CLIMenuItem>(); m.node = n; if (n.children.Count > 0) { m.arrow.gameObject.SetActive(true); } else { m.arrow.gameObject.SetActive(false); } } panelOpen = true; } } else { if (node.method.GetParameters().Length == 0) { node.method.Invoke(node.monoBehaviour, null); CLIMenu.Instance.ResetAllMenuButtons(); CLIMenu.Instance.DestroyAllOpenPanels(); } else { Debug.LogWarning("Methods with parameters in the button menu are not supported yet!"); } } }
public void OnClick() { if (!panelOpen) { CLIMenu.Instance.ResetAllMenuButtons(); CLIMenu.Instance.DestroyAllOpenPanels(); RectTransform rectTransform = GetComponent <RectTransform>(); RectTransform panel = Instantiate(menuDropdownPrefab).GetComponent <RectTransform>(); panel.transform.SetParent(CLIManager.Instance.transform); CLIMenu.Instance.openPanels.Add(panel); panel.anchoredPosition = rectTransform.anchoredPosition - new Vector2(rectTransform.rect.width / 2, rectTransform.rect.height / 2); CLIMenuItemPanel p = panel.GetComponent <CLIMenuItemPanel>(); p.button = this; CLIMenu.Instance.openPanels.Add(panel); foreach (var node in node.children) { RectTransform menuItem = Instantiate(menuItemPrefab).GetComponent <RectTransform>(); menuItem.SetParent(panel); menuItem.GetComponentInChildren <Text>().text = node.name; CLIMenuItem m = menuItem.GetComponent <CLIMenuItem>(); m.node = node; if (node.children.Count > 0) { m.arrow.gameObject.SetActive(true); } } panelOpen = true; } }