SelectionManager.cs
SelectionManager
is a singleton class that manages selectable objects in a game system. It provides functionality for managing selections and handling selection groups.
Usage Example
Properties
Selections
Type:
IReadOnlySelectables
Description: Provides read-only access to all currently selected objects.
ActiveSelections
Type:
IEnumerable<ISelectable>
Description: Returns currently active selected objects.
Count
Type:
int
Description: Returns the total number of currently selected objects.
SelectionOrNull
Type:
ISelectable
Description: Returns the first selected object or null if no selection exists.
HasSelection
Type:
bool
Description: Indicates whether there are any selected objects.
maxSelections
Type:
int
Description: Maximum number of objects that can be selected simultaneously. Default is 12.
IsMaxSelections
Type:
bool
Description: Indicates whether the maximum selection limit has been reached. Always returns false in infinity selection mode.
IsInfinitySelectionMode
Type:
bool
Description: Indicates whether infinite selection mode is active (maxSelections < 0).
Events
OnChanged
Type:
UnityEvent<IReadOnlySelectables>
Description: Triggered whenever any change occurs in the selection state.
OnSelectionChanged
Type:
UnityEvent<IReadOnlySelectables>
Description: Triggered when the selection set changes.
OnSubGroupChanged
Type:
UnityEvent<IReadOnlySelectables>
Description: Triggered when the active subgroup changes.
Methods
New
Creates a new selection, clearing all previous selections.
Parameters:
selectables
: Collection of objects to select
Returns: Number of objects successfully selected
Add
Adds new objects to the current selection.
Parameters:
selectables
: Collection of objects to add to selection
Returns: Number of objects successfully added
Deselect
Removes objects from the current selection.
Parameters:
selectables
: Collection of objects to deselectselectable
: Single object to deselect
Returns: Number of objects deselected or boolean indicating success
DeselectAll
Clears all current selections.
Returns: Number of objects deselected
TryActiveNextSubGroup
Attempts to activate the next subgroup in the selection.
Returns:
true
if successful,false
otherwise
TryActivePreviousSubGroup
Attempts to activate the previous subgroup in the selection.
Returns:
true
if successful,false
otherwise
IsSelected
Checks if an object is currently selected.
Parameters:
selectable
: Object to check
Returns:
true
if the object is selected,false
otherwise
Dependencies
Inherits from
SingletonMonoBehaviour<SelectionManager>
Requires
ISelectable
interface implementation for selectable objectsUses
UnityEvent
system for event handling
Last updated