Class ModularContextMenu
- Namespace
- Fallencake.UI
- Assembly
- Fallencake.UI.dll
A modular popup menu appears upon user interaction, such as a right-click mouse operation.
[AddComponentMenu("Modular UI/Context Menu")]
public class ModularContextMenu : ContextMenuBase
- Inheritance
-
objectObjectComponentBehaviourMonoBehaviourModularContextMenu
- Inherited Members
Fields
_offset
[SerializeField]
protected RectOffset _offset
Field Value
- RectOffset
_subMenuOffset
[SerializeField]
protected Vector2 _subMenuOffset
Field Value
- Vector2
Properties
backgroundColor
Background overlay color used when interactive background is enabled.
public Color backgroundColor { get; set; }
Property Value
- Color
isCloseOnClick
If true, clicking on the interactive background closes the menu.
public bool isCloseOnClick { get; set; }
Property Value
- bool
offset
The offset added around the content element to the point at which the menu opens.
public RectOffset offset { get; set; }
Property Value
- RectOffset
panelPosition
Current quadrant of the menu relative to the cursor/area bounds.
public PanelPosition panelPosition { get; }
Property Value
subMenuOffset
Relative offset applied when spawning a submenu next to the parent item.
public Vector2 subMenuOffset { get; }
Property Value
- Vector2
Methods
AddButton(string, UnityAction, Sprite, bool)
Adds a clickable button item with optional icon.
public ContextMenuItem AddButton(string name, UnityAction onClick, Sprite icon = null, bool rebuild = true)
Parameters
namestringDisplay text.
onClickUnityActionClick callback.
iconSpriteOptional icon.
rebuildboolIf true, calls UpdateContent().
Returns
AddItem(ContextMenuItem, bool)
Adds a preconfigured item and optionally rebuilds the menu.
public void AddItem(ContextMenuItem item, bool rebuild = true)
Parameters
itemContextMenuItemItem to add.
rebuildboolIf true, calls UpdateContent().
AddNewItem()
Adds a new empty item to the menu. Prefer AddItem/AddButton/AddSeparator.
[Obsolete("Use AddItem(ContextMenuItem) / AddButton / AddSeparator")]
public void AddNewItem()
AddSeparator(bool)
Adds a visual separator item.
public ContextMenuItem AddSeparator(bool rebuild = true)
Parameters
rebuildboolIf true, calls UpdateContent().
Returns
AddSubMenu(string, List<ContextSubMenuItem>, Sprite, bool)
Adds a submenu with provided items.
public ContextMenuItem AddSubMenu(string name, List<ContextSubMenuItem> items, Sprite icon = null, bool rebuild = true)
Parameters
namestringSubmenu header text.
itemsList<ContextSubMenuItem>Child submenu items.
iconSpriteOptional icon.
rebuildboolIf true, calls UpdateContent().
Returns
ClearItems(bool)
Clears all menu items.
public void ClearItems(bool rebuild = true)
Parameters
rebuildboolIf true, calls UpdateContent().
OpenAt(Vector2)
Shows the menu at a specific screen position.
public void OpenAt(Vector2 screenPosition)
Parameters
screenPositionVector2Position in screen pixels.
OpenAt(Vector2, bool)
Shows the menu at a specific screen position with optional content rebuild.
When isUpdateContent is true, items are rebuilt before showing.
public void OpenAt(Vector2 screenPosition, bool isUpdateContent)
Parameters
screenPositionVector2Position in screen pixels.
isUpdateContentboolIf true, calls UpdateContent() before showing.
OpenAtCursor()
Shows the menu at the current cursor position.
public void OpenAtCursor()
SetItems(List<ContextMenuItem>, bool)
Sets the entire items list and optionally rebuilds the menu.
public void SetItems(List<ContextMenuItem> items, bool rebuild = true)
Parameters
itemsList<ContextMenuItem>New list of items to display.
rebuildboolIf true, calls UpdateContent().
UpdateContent()
Rebuilds menu items based on the current items list and repositions the menu.
public void UpdateContent()
UpdatePositionFromCursor()
Updates internal cursor position (based on current input system) and repositions the menu.
public void UpdatePositionFromCursor()