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
public IReadOnlySelectables Selections;
Description: Provides read-only access to all currently selected objects.
ActiveSelections
public IEnumerable<ISelectable> ActiveSelections;
Description: Returns currently active selected objects.
Count
public int Count;
Description: Returns the total number of currently selected objects.
SelectionOrNull
public ISelectable SelectionOrNull;
Description: Returns the first selected object or null if no selection exists.
HasSelection
public bool HasSelection;
Description: Indicates whether there are any selected objects.
maxSelections
public int maxSelections;
Description: Maximum number of objects that can be selected simultaneously. Default is 12.
IsMaxSelections
public bool IsMaxSelections;
Description: Indicates whether the maximum selection limit has been reached. Always returns false in infinity selection mode.
IsInfinitySelectionMode
public virtual bool IsInfinitySelectionMode;
Description: Indicates whether infinite selection mode is active (maxSelections < 0).
Events
OnChanged
public UnityEvent<IReadOnlySelectables> OnChanged;
Description: Triggered whenever any change occurs in the selection state.
OnSelectionChanged
public UnityEvent<IReadOnlySelectables> OnSelectionChanged;
Description: Triggered when the selection set changes.
OnSubGroupChanged
UnityEvent<IReadOnlySelectables> OnSubGroupChanged;
Description: Triggered when the active subgroup changes.
Methods
New
public virtual int New(IEnumerable<ISelectable> selectables)
Creates a new selection, clearing all previous selections.
Parameters:
selectables
: Collection of objects to select
Returns: Number of objects successfully selected
Add
public virtual int Add(IEnumerable<ISelectable> selectables)
Adds new objects to the current selection.
Parameters:
selectables
: Collection of objects to add to selection
Returns: Number of objects successfully added
Deselect
public virtual int Deselect(IEnumerable<ISelectable> selectables)
public virtual bool Deselect(ISelectable selectable)
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
public virtual int DeselectAll()
Clears all current selections.
Returns: Number of objects deselected
TryActiveNextSubGroup
public virtual bool TryActiveNextSubGroup()
Attempts to activate the next subgroup in the selection.
Returns:
true
if successful,false
otherwise
TryActivePreviousSubGroup
public virtual bool TryActivePreviousSubGroup()
Attempts to activate the previous subgroup in the selection.
Returns:
true
if successful,false
otherwise
IsSelected
public virtual bool IsSelected(ISelectable selectable)
Checks if an object is currently selected.
Parameters:
selectable
: Object to check
Returns:
true
if the object is selected,false
otherwise
Last updated