// 109x44はmiuraのデバグボタンのサイズ public Menu( float itemWidth = 100f, float itemHeight = 40f, Direction direction = Direction.Right, string name = "") : base((string.IsNullOrEmpty(name) ? "Menu" : name), itemWidth, itemHeight, direction) { activeIndex = 0; activeMenu = this; SelectedColor = new Color32(128, 128, 128, 192); SelectedTextColor = new Color32(0, 0, 0, 255); }
public bool ToChild() { var ret = false; if ((activeIndex >= 0) && (activeIndex < activeMenu.ItemCount)) { var item = activeMenu.GetItem(activeIndex); if (item.menu != null) { item.button.Click(); activeMenu = item.menu; activeIndex = 0; } ret = true; } return(ret); }
public void RemoveSubMenu(SubMenu subMenu) { CloseSub(); int dst = 0; for (int i = 0; i < items.Count; i++) { items[dst] = items[i]; if (items[dst].menu == subMenu) { RemoveChild(items[dst].button); RemoveChild(subMenu); } else { dst++; } } items.RemoveRange(dst, items.Count - dst); Layout(); }
public Button AddSubMenu( SubMenu subMenu, Direction subMenuDirection = Direction.Down) { subMenu.Parent = this; subMenu.Enabled = false; subMenu.Color = Color; subMenu.TextColor = TextColor; subMenu.PointerDownColor = PointerDownColor; subMenu.PointerDownTextColor = PointerDownTextColor; var button = new Button(subMenu.Name, itemWidth, itemHeight) { Color = Color, TextColor = TextColor, PointerDownColor = PointerDownColor, PointerDownTextColor = PointerDownTextColor, OnClick = () => { // サブメニューを閉じる bool opened = subMenu.Enabled; CloseSub(); if (!opened) { subMenu.Enabled = true; } } }; Add(button); Add(subMenu); Item item; item.button = button; item.menu = subMenu; item.menuDirection = subMenuDirection; items.Add(item); Layout(); return(button); }
public bool ToParent() { var ret = false; var parent = activeMenu.Parent; if (parent != null) { parent.CloseSub(); int newIndex = 0; for (int i = 0; i < parent.ItemCount; i++) { var item = parent.GetItem(i); if (item.menu == activeMenu) // 見つかったらその番号に戻す { newIndex = i; break; } } activeMenu = parent; activeIndex = newIndex; ret = true; } return(ret); }