Class DropdownMenu
- Namespace
- Fallencake.UI
- Assembly
- Fallencake.UI.dll
Configurable dropdown UI component supporting tween or Animator-based open/close, item selection, sounds, and optional state saving.
public class DropdownMenu : UIBehaviour, IDropdownMenu, IDropdownAudioProvider, IAudioProvider, ISaveable
- Inheritance
-
objectObjectComponentBehaviourMonoBehaviourUIBehaviourDropdownMenu
- Implements
Fields
OnItemTextChanged
public DropdownMenu.ItemTextChangedEvent OnItemTextChanged
Field Value
OnValueChanged
public DropdownEvent OnValueChanged
Field Value
animationType
public AnimationType animationType
Field Value
index
[HideInInspector]
public int index
Field Value
- int
isOn
[HideInInspector]
public bool isOn
Field Value
- bool
itemSpacing
[Range(0, 100)]
public float itemSpacing
Field Value
- float
items
[SerializeField]
public List<DropdownItem> items
Field Value
- List<DropdownItem>
setItemImage
[HideInInspector]
public Image setItemImage
Field Value
- Image
setItemText
[HideInInspector]
public TextMeshProUGUI setItemText
Field Value
- TextMeshProUGUI
siblingIndex
[HideInInspector]
public int siblingIndex
Field Value
- int
Properties
AnimationCurve
Easing curve for tween-based animation.
public AnimationCurve AnimationCurve { get; }
Property Value
- AnimationCurve
AnimationRunner
"The MonoBehaviour component used to run coroutines or for attaching the Animator component."
public MonoBehaviour AnimationRunner { get; }
Property Value
- MonoBehaviour
Animator
Animator used when UnityAnimator is selected.
public Animator Animator { get; }
Property Value
- Animator
AudioSource
AudioSource used for playing dropdown sounds.
public AudioSource AudioSource { get; set; }
Property Value
- AudioSource
CloseSound
Sound data for closing the dropdown.
public AudioData CloseSound { get; }
Property Value
ClosingTime
Close animation duration (seconds, unscaled).
public float ClosingTime { get; }
Property Value
- float
Component
Owning component used by handlers for context and coroutines.
public MonoBehaviour Component { get; }
Property Value
- MonoBehaviour
ContentOffset
Offset in pixels between header and list panel.
public float ContentOffset { get; }
Property Value
- float
CurrentAnimationType
Gets/sets current animation type and reinitializes handler when changed.
public AnimationType CurrentAnimationType { get; set; }
Property Value
DeselectSound
Sound played on deselect.
public AudioData DeselectSound { get; }
Property Value
EnableSounds
Enables UI sounds via IDropdownAudioHandler.
public bool EnableSounds { get; set; }
Property Value
- bool
IsHighPriority
If true, ensures the list renders on top using a dedicated Canvas.
public bool IsHighPriority { get; set; }
Property Value
- bool
IsIconEnabled
public bool IsIconEnabled { get; set; }
Property Value
- bool
IsInteractable
Controls user interaction availability.
public bool IsInteractable { get; set; }
Property Value
- bool
IsItemSelectedAtUpdate
When true, invokes selected item events during UpdateDropdown().
public bool IsItemSelectedAtUpdate { get; }
Property Value
- bool
IsSavingEnabled
Enables save/load behavior for the component.
public bool IsSavingEnabled { get; set; }
Property Value
- bool
IsTriggerEnabled
If true, clicking outside closes the dropdown via an invisible overlay trigger.
public bool IsTriggerEnabled { get; set; }
Property Value
- bool
ItemListCanvasGroup
CanvasGroup used for list open/close transitions.
public CanvasGroup ItemListCanvasGroup { get; }
Property Value
- CanvasGroup
ItemListRect
RectTransform of the list content panel.
public RectTransform ItemListRect { get; }
Property Value
- RectTransform
ItemPadding
Get or set the padding of items in the container. Value format: (left, right, top, bottom) Default value: (8, 25, 8, 8)
public RectOffset ItemPadding { get; set; }
Property Value
- RectOffset
ItemPrefab
Prefab used to instantiate list items.
public GameObject ItemPrefab { get; set; }
Property Value
- GameObject
OpenSound
Sound data for opening the dropdown.
public AudioData OpenSound { get; }
Property Value
OpeningTime
Open animation duration (seconds, unscaled).
public float OpeningTime { get; }
Property Value
- float
OutOnPointerExit
If true, pointer exit will close the dropdown.
public bool OutOnPointerExit { get; set; }
Property Value
- bool
PanelDirection
Direction from the header where the list opens.
public DropdownDirection PanelDirection { get; }
Property Value
PanelHeight
Target list panel height while opened.
public float PanelHeight { get; }
Property Value
- float
PressSound
Sound played on press/submit.
public AudioData PressSound { get; }
Property Value
SaveKey
PlayerPrefs key used to persist the state.
public string SaveKey { get; set; }
Property Value
- string
SelectItemSound
Sound data for selecting an item.
public AudioData SelectItemSound { get; }
Property Value
SelectSound
Sound played on select/hover.
public AudioData SelectSound { get; }
Property Value
Selectable
Underlying UnityEngine.UI.Selectable for navigation/select.
public Selectable Selectable { get; }
Property Value
- Selectable
SelectedImage
Image that displays selected item icon.
public Image SelectedImage { get; }
Property Value
- Image
SelectedItemIndex
Index of the currently selected item; setter selects item and updates view.
public int SelectedItemIndex { get; set; }
Property Value
- int
SelectedText
Label that displays selected item text.
public TextMeshProUGUI SelectedText { get; }
Property Value
- TextMeshProUGUI
Volume
Master volume multiplier for sounds (0..1).
public float Volume { get; set; }
Property Value
- float
Methods
Animate()
Toggles the open/close state and triggers the active animation handler and sounds.
public void Animate()
Awake()
protected override void Awake()
CreateNewItem(string)
public void CreateNewItem(string title)
Parameters
titlestring
CreateNewItem(string, bool)
public void CreateNewItem(string title, bool notify)
Parameters
titlestringnotifybool
CreateNewItem(string, Sprite, bool)
public void CreateNewItem(string title, Sprite icon, bool notify)
Parameters
titlestringiconSpritenotifybool
InitTrigger()
Creates and configures click-outside trigger overlay in play mode when enabled.
public void InitTrigger()
InitializeAudio()
public void InitializeAudio()
LoadState()
Loads selected item index from UnityEngine.PlayerPrefs.
public void LoadState()
OnDeselect(BaseEventData)
Called by the EventSystem when a new object is being selected.
public void OnDeselect(BaseEventData eventData)
Parameters
eventDataBaseEventData
OnDestroy()
protected override void OnDestroy()
OnEnable()
protected override void OnEnable()
OnPointerClick(PointerEventData)
Use this callback to detect clicks.
public void OnPointerClick(PointerEventData eventData)
Parameters
eventDataPointerEventData
OnPointerEnter(PointerEventData)
Use this callback to detect pointer enter events
public void OnPointerEnter(PointerEventData eventData)
Parameters
eventDataPointerEventData
OnPointerExit(PointerEventData)
Use this callback to detect pointer exit events
public void OnPointerExit(PointerEventData eventData)
Parameters
eventDataPointerEventData
OnSelect(BaseEventData)
public void OnSelect(BaseEventData eventData)
Parameters
eventDataBaseEventData
OnSubmit(BaseEventData)
public void OnSubmit(BaseEventData eventData)
Parameters
eventDataBaseEventData
PlayCloseSound()
Plays dropdown close sound.
public void PlayCloseSound()
PlayDeselectSound()
Plays UI deselect sound via audio handler.
public void PlayDeselectSound()
PlayOpenSound()
Plays dropdown open sound.
public void PlayOpenSound()
PlayPressSound()
Plays UI press sound via audio handler.
public void PlayPressSound()
PlaySelectItemSound()
Plays item selected sound.
public void PlaySelectItemSound()
PlaySelectSound()
Plays UI select sound via audio handler.
public void PlaySelectSound()
RemoveItem(string)
public void RemoveItem(string itemTitle)
Parameters
itemTitlestring
RemoveItem(string, bool)
public void RemoveItem(string itemTitle, bool notify)
Parameters
itemTitlestringnotifybool
SaveState()
Saves selected item index to UnityEngine.PlayerPrefs.
public void SaveState()
SelectItem(int, bool, bool, bool)
Selects item by index, saves state if enabled and updates UI optionally.
public void SelectItem(int itemIndex, bool updateView = true, bool playSound = true, bool selectDropdown = true)
Parameters
itemIndexintItem index to select.
updateViewboolWhether to update label/icon.
playSoundboolWhether to play selection sound.
selectDropdownboolWhether to programmatically select the dropdown.
SetIconEnabled(bool)
Sets the visibility of the selected item's icon.
public void SetIconEnabled(bool value)
Parameters
valueboolWhether to enable or disable the icon gameobject.
UpdateAnimator()
Reinitializes the tween animator handler when using tween mode.
public void UpdateAnimator()
UpdateDropdown()
Sets up the dropdown menu by creating items and updating the UI.
public void UpdateDropdown()
UpdateItemLayout()
public void UpdateItemLayout()
UpdateSelectable()
Updates the interactable state of the Selectable component
public void UpdateSelectable()