Class ContextMenuBase
- Namespace
- Fallencake.UI
- Assembly
- Fallencake.UI.dll
Base class for context menu implementations providing lifecycle, content management and popup animation orchestration via PopupTweenAnimator.
public abstract class ContextMenuBase : MonoBehaviour
- Inheritance
-
objectObjectComponentBehaviourMonoBehaviourContextMenuBase
- Derived
Fields
_content
[SerializeField]
protected Transform _content
Field Value
- Transform
_contentRectTransform
protected RectTransform _contentRectTransform
Field Value
- RectTransform
_isActive
protected bool _isActive
Field Value
- bool
_itemsContainer
[SerializeField]
protected Transform _itemsContainer
Field Value
- Transform
_popupAnimator
[SerializeField]
protected PopupTweenAnimator _popupAnimator
Field Value
Properties
isActive
Indicates whether the menu is currently shown.
public bool isActive { get; }
Property Value
- bool
Methods
ClearAllItems()
Destroys all child items from the items container.
protected virtual void ClearAllItems()
Close()
Triggers the popup animator to hide the context menu with animation and sets the menu as inactive.
public virtual void Close()
CloseInstantly()
Instantly hides the menu without animation by calling the popup animator's HideInstantly(Action).
protected virtual void CloseInstantly()
CloseOnClick()
Closes the menu on click.
public virtual void CloseOnClick()
GetMenuWidth()
Gets current menu content width in pixels.
public float GetMenuWidth()
Returns
- float
InitContent()
Ensures content transform exists and caches UnityEngine.RectTransform.
protected virtual void InitContent()
InitItemsContainer()
Ensures items container exists under content.
protected virtual void InitItemsContainer()
InitPopupAnimator()
Ensures popup animator component is available.
protected virtual void InitPopupAnimator()
Open()
Displays the context menu with an opening animation and sets its active state to true.
public virtual void Open()
SetProperty<T>(ref T, T, Action)
Helper method used to set a given property if it has changed.
protected virtual void SetProperty<T>(ref T currentValue, T newValue, Action onSet)
Parameters
currentValueTReference to the current value.
newValueTProposed new value.
onSetActionCallback invoked when the value actually changes.
Type Parameters
TType of the property.
UpdateItemsWithDelay(float)
Rebuilds items after a small delay to ensure layout is updated.
protected virtual IEnumerator UpdateItemsWithDelay(float time)
Parameters
timefloatDelay in seconds (unscaled).
Returns
- IEnumerator