public void OpenSubMenu(IContextMenuItem subMenuItem) { // Find Item ContextMenuCardController cardController = m_CardControllers[subMenuItem.Id]; Vector3 position = cardController.transform.position + new Vector3(m_size.x / 2, 0); // Create a new submenu at its spot _SubMenu = ContextMenuManager.Instance.CreateContextMenu(Camera.main.ScreenToWorldPoint(position), subMenuItem.GetSubMenu(), this); }
public void Init(Vector3 screenPositionOfClick, IContextMenu menu, IContextMenuController parent) { name = $"ContextMenu {menu.Id}"; _Menu = menu; _Parent = parent; m_CardControllers = new Dictionary <uint, ContextMenuCardController>(); m_size = m_MinSize; foreach (IContextMenuItem item in menu.Items) { ContextMenuCardController card = Instantiate(m_ContextMenuCardPrefab); card.transform.SetParent(m_ContextMenuCardHolder); card.Init(item, this); m_size.x = Mathf.Max(m_size.x, m_CharacterSize * item.GetDisplayString().Length); m_size.y += m_LineSize; m_CardControllers.Add(item.Id, card); } GetComponent <RectTransform>().sizeDelta = m_size; // Set the position make sure to offset so that the mouse appears in uper left corner GetComponent <RectTransform>().position = screenPositionOfClick + (new Vector3(m_size.x, m_size.y * -1) * .9f) / 2; // TODO add a button handler so that when the user clicks off the menu they close the menu m_IsMouseOverThisMenu = false; ClickOffMenuHandler = new ButtonHandler(ButtonHandler.RightClick, // Down (handler, position) => { if (!m_IsMouseOverThisMenu && _SubMenu == null) { CloseMenu(); } }, // Up (handler, position) => { }); ClickOffMenuHandler.IgnoreUI = false; ClickOffMenuHandler.OnlyUI = false; InputController.Instance.RegisterHandler(ClickOffMenuHandler); }