Table of Contents

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
object
Object
Component
Behaviour
MonoBehaviour
ModularContextMenu
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

PanelPosition

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

name string

Display text.

onClick UnityAction

Click callback.

icon Sprite

Optional icon.

rebuild bool

If true, calls UpdateContent().

Returns

ContextMenuItem

AddItem(ContextMenuItem, bool)

Adds a preconfigured item and optionally rebuilds the menu.

public void AddItem(ContextMenuItem item, bool rebuild = true)

Parameters

item ContextMenuItem

Item to add.

rebuild bool

If 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

rebuild bool

If true, calls UpdateContent().

Returns

ContextMenuItem

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

name string

Submenu header text.

items List<ContextSubMenuItem>

Child submenu items.

icon Sprite

Optional icon.

rebuild bool

If true, calls UpdateContent().

Returns

ContextMenuItem

ClearItems(bool)

Clears all menu items.

public void ClearItems(bool rebuild = true)

Parameters

rebuild bool

If true, calls UpdateContent().

OpenAt(Vector2)

Shows the menu at a specific screen position.

public void OpenAt(Vector2 screenPosition)

Parameters

screenPosition Vector2

Position 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

screenPosition Vector2

Position in screen pixels.

isUpdateContent bool

If 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

items List<ContextMenuItem>

New list of items to display.

rebuild bool

If 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()