//Inititalize this menu item by setting // its parent, name and base events public void Configure(NestedMenu parent, string name) { this.name = name; this.GetComponentInChildren <Text>().text = name; this.parentMenu = parent; AddEvent(EventTriggerType.PointerEnter, this.OpenSubMenu); AddEvent(EventTriggerType.PointerExit, this.CloseSubMenu); }
//Add a submenu to this item public NestedMenu AddSubMenu() { GameObject nestedMenuGO = GameObject.Instantiate( Resources.Load <GameObject>("NestedMenu")); NestedMenu nestedMenu = nestedMenuGO. GetComponent <NestedMenu>(); //Inset the menu item GetComponent <RectTransform>() .SetInsetAndSizeFromParentEdge (RectTransform.Edge.Right, -nestedMenu.menuWidth, nestedMenu.menuWidth); nestedMenu.transform.SetParent(this.transform); nestedMenu.parentMenuItem = this; this.subMenu = nestedMenu; subMenu.gameObject.SetActive(false); return(nestedMenu); }