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
// Get reference to SelectionManager
var selectionManager = SelectionManager.Instance;
// Create a new selection
selectionManager.New(new[] { selectable1, selectable2 });
// Add more objects to selection
selectionManager.Add(new[] { selectable3 });
// Check if object is selected
bool isSelected = selectionManager.IsSelected(selectable1);
// Deselect specific object
selectionManager.Deselect(selectable1);
// Clear all selections
selectionManager.DeselectAll();
// Navigate between subgroups
selectionManager.TryActiveNextSubGroup();
Properties
Selections
Description: Provides read-only access to all currently selected objects.
ActiveSelections
Description: Returns currently active selected objects.
Count
Description: Returns the total number of currently selected objects.
SelectionOrNull
Description: Returns the first selected object or null if no selection exists.
HasSelection
Description: Indicates whether there are any selected objects.
maxSelections
Description: Maximum number of objects that can be selected simultaneously. Default is 12.
IsMaxSelections
Description: Indicates whether the maximum selection limit has been reached. Always returns false in infinity selection mode.
IsInfinitySelectionMode
Description: Indicates whether infinite selection mode is active (maxSelections < 0).
Events
OnChanged
Description: Triggered whenever any change occurs in the selection state.
OnSelectionChanged
Description: Triggered when the selection set changes.
OnSubGroupChanged
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:
trueif successful,falseotherwise
TryActivePreviousSubGroup
Attempts to activate the previous subgroup in the selection.
Returns:
trueif successful,falseotherwise
IsSelected
Checks if an object is currently selected.
Parameters:
selectable: Object to check
Returns:
trueif the object is selected,falseotherwise
Last updated