コード例 #1
0
        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();
                }
                    );
            }
        }
コード例 #2
0
 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);
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public void SetContextMenu(ContextMenuData ctx)
 {
     _contextMenuData = ctx;
 }
コード例 #7
0
 public ContextMenuBuilder()
 {
     _root = new ContextMenuData("");
 }
コード例 #8
0
 public static void InvokeMenuItemClicked(ContextMenuData data, ContextContainer container)
 {
     OnMenuItemClicked?.Invoke(data, container);
 }