public void Init(ContextMenuData node) { nameText.text = node.name; bool hasSubMenu = node.children.Count > 0; subContextIcon.gameObject.SetActive(hasSubMenu); if (hasSubMenu) { button.onClick.AddListener( () => { var container = Utility.CreatePrefab <ContextContainer>("Prefabs/ContextContainer", subContextTransform); container.Init(node.children /*[0].children*/.ToArray()); SignalSystem.InvokeMenuItemClicked(node, container); } ); } else { button.onClick.AddListener( () => { node.callback?.Invoke(); } ); } }
public void Show(ContextMenuData context, Vector2 pos) { _root = Utility.CreatePrefab <ContextContainer>("Prefabs/ContextContainer", _rect); _root.Init(context.children.ToArray()); _rect.localPosition = pos; gameObject.SetActive(true); }
public ContextMenuBuilder AddChild(ContextMenuData child) { int lastIndex = _root.children.Count - 1; var targetNode = _root.children[lastIndex]; child.parent = targetNode; targetNode.children.Add(child); return(this); }
private void OnMenuItemClicked(ContextMenuData data, ContextContainer container) { List <ContextContainer> toRemove = new List <ContextContainer>(); foreach (var item in _subContainers) { if (item.depthLevel > data.Level) { toRemove.Add(item); } } foreach (var item in toRemove) { Destroy(item.gameObject); _subContainers.Remove(item); } _subContainers.Add(container); }
public ContextMenuData BuildHierarchy(string path) { path = path.Replace("\\", "/"); string[] split = path.Split('/'); ContextMenuData menu_item = _root; int index = 0; while (index < split.Length) { bool found = false; for (int i = 0; i < menu_item.children.Count; ++i) { if (menu_item.children[i].name == split[index]) { menu_item = menu_item.children[i]; ++index; found = true; break; } } if (!found) { var new_menu_item = new ContextMenuData(split[index]) { parent = menu_item }; // new_menu_item.callback = callback; menu_item.children.Add(new_menu_item); menu_item = new_menu_item; ++index; found = true; } } return(menu_item); }
public void SetContextMenu(ContextMenuData ctx) { _contextMenuData = ctx; }
public ContextMenuBuilder() { _root = new ContextMenuData(""); }
public static void InvokeMenuItemClicked(ContextMenuData data, ContextContainer container) { OnMenuItemClicked?.Invoke(data, container); }