Class BaseSelector
- Namespace
- Fallencake.UI
- Assembly
- Fallencake.UI.dll
Base component for selectable UI controls that manage a list of items and synchronize labels, icons, indicators, animations, and saving behavior.
public abstract class BaseSelector : MonoBehaviour, ISaveable
- Inheritance
-
objectObjectComponentBehaviourMonoBehaviourBaseSelector
- Implements
- Derived
Remarks
Provides common properties for visibility, spacing, scaling, saving, and events. Derived selectors implement content update hooks and selection logic via SelectItem(int).
Fields
OnSelectedIndexChanged
Invoked when the selected index changes.
public SelectedIndexEvent OnSelectedIndexChanged
Field Value
OnSelectedTextChanged
Invoked when the displayed text changes due to selection.
public SelectedTextEvent OnSelectedTextChanged
Field Value
PlayerPrefsKeyPrefix
protected const string PlayerPrefsKeyPrefix = "ModularSelector_"
Field Value
- string
_basicContentLayout
[SerializeField]
protected HorizontalOrVerticalLayoutGroup _basicContentLayout
Field Value
- HorizontalOrVerticalLayoutGroup
_basicIcon
[SerializeField]
protected Image _basicIcon
Field Value
- Image
_basicTextLabel
[SerializeField]
protected TMP_Text _basicTextLabel
Field Value
- TMP_Text
_contentSpacing
The spacing between the content components.
[SerializeField]
[Range(0, 100)]
protected int _contentSpacing
Field Value
- int
_defaultItemIndex
The index of the default item in the items list used when the selector is initialized if saving is disabled.
[SerializeField]
protected int _defaultItemIndex
Field Value
- int
_iconScale
The scale of the icon component when it is enabled.
[SerializeField]
[Range(0.25, 5)]
protected float _iconScale
Field Value
- float
_indicatorPrefab
[SerializeField]
protected GameObject _indicatorPrefab
Field Value
- GameObject
_indicatorsContainer
[SerializeField]
protected Transform _indicatorsContainer
Field Value
- Transform
_invertAnimation
When enabled, creates an inverted animation behavior. When selecting the next item in the Items list, it will play the previous animation, and when selecting the previous item, it will play the next animation.
[SerializeField]
protected bool _invertAnimation
Field Value
- bool
_invokeOnInitialization
Determines whether callbacks should be invoked when the selector is initialized. When enabled, the events will be triggered during initialization.
[SerializeField]
protected bool _invokeOnInitialization
Field Value
- bool
_isIconEnabled
Controls the visibility of icon components and affects the layout of selector content.
[SerializeField]
protected bool _isIconEnabled
Field Value
- bool
_isIndicatorsEnabled
Controls the visibility of indicators container component.
[SerializeField]
protected bool _isIndicatorsEnabled
Field Value
- bool
_isInitialized
protected bool _isInitialized
Field Value
- bool
_isSavingEnabled
Determines whether the selector's state can be saved and loaded.
[SerializeField]
protected bool _isSavingEnabled
Field Value
- bool
_isTextEnabled
Controls the visibility of text components and affects the layout of selector content.
[SerializeField]
protected bool _isTextEnabled
Field Value
- bool
_items
[SerializeField]
protected List<SelectorItem> _items
Field Value
- List<SelectorItem>
_loopSelection
When enabled, the selector will loop through the items when the first or last item is selected.
[SerializeField]
protected bool _loopSelection
Field Value
- bool
_nextAnimator
[SerializeField]
protected ModularAnimator _nextAnimator
Field Value
_previousAnimator
[SerializeField]
protected ModularAnimator _previousAnimator
Field Value
_saveKey
The string key used to save and load the selector's state in PlayerPrefs.
[SerializeField]
protected string _saveKey
Field Value
- string
_secondaryContentLayout
[SerializeField]
protected HorizontalOrVerticalLayoutGroup _secondaryContentLayout
Field Value
- HorizontalOrVerticalLayoutGroup
_secondaryIcon
[SerializeField]
protected Image _secondaryIcon
Field Value
- Image
_secondaryTextLabel
[SerializeField]
protected TMP_Text _secondaryTextLabel
Field Value
- TMP_Text
_selectedItemIndex
protected int _selectedItemIndex
Field Value
- int
s_IndicatorWarning
protected static readonly string s_IndicatorWarning
Field Value
- string
s_ItemsValidationWarning
protected static readonly string s_ItemsValidationWarning
Field Value
- string
s_TextLabelWarning
protected static readonly string s_TextLabelWarning
Field Value
- string
Properties
ContentSpacing
public int ContentSpacing { get; set; }
Property Value
- int
DefaultItemIndex
public int DefaultItemIndex { get; set; }
Property Value
- int
IconScale
public float IconScale { get; set; }
Property Value
- float
InvertAnimation
public bool InvertAnimation { get; set; }
Property Value
- bool
InvokeOnInitialization
public bool InvokeOnInitialization { get; set; }
Property Value
- bool
IsIconEnabled
public bool IsIconEnabled { get; set; }
Property Value
- bool
IsIndicatorsEnabled
public bool IsIndicatorsEnabled { get; set; }
Property Value
- bool
IsInitialized
Whether the selector finished its initialization routine.
public bool IsInitialized { get; }
Property Value
- bool
IsSavingEnabled
Enables save/load behavior for the component.
public bool IsSavingEnabled { get; set; }
Property Value
- bool
IsTextEnabled
public bool IsTextEnabled { get; set; }
Property Value
- bool
LoopSelection
public bool LoopSelection { get; set; }
Property Value
- bool
SaveKey
PlayerPrefs key used to persist the state.
public string SaveKey { get; set; }
Property Value
- string
SelectedItemIndex
Current selected item index within _items.
public int SelectedItemIndex { get; set; }
Property Value
- int
Methods
Awake()
protected virtual void Awake()
HandleSelectedIndexChanged()
protected virtual void HandleSelectedIndexChanged()
HandleSelectedTextChanged()
protected virtual void HandleSelectedTextChanged()
Initialize()
protected virtual void Initialize()
InvokeInitialSelection()
protected virtual void InvokeInitialSelection()
IsDestroyed()
Indicates whether this component has been destroyed.
public virtual bool IsDestroyed()
Returns
- bool
True if the component instance is no longer valid.
LoadState()
Loads the current selection from persistent storage, or uses DefaultItemIndex if disabled.
public virtual void LoadState()
SaveState()
Persists the current selected index if IsSavingEnabled is true.
public virtual void SaveState()
SelectItem(int)
Selects an item by index and updates visuals in derived implementations.
public abstract void SelectItem(int index)
Parameters
indexintZero-based index of the item to select.
UpdateContentLayout()
protected abstract void UpdateContentLayout()
UpdateIndicators()
protected abstract void UpdateIndicators()
UpdateLabelAndIcon()
protected abstract void UpdateLabelAndIcon()
UpdateVisuals()
protected virtual void UpdateVisuals()
ValidateComponents()
protected virtual bool ValidateComponents()
Returns
- bool