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

  • 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

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 deselect

    • selectable: 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

Dependencies

  • Inherits from SingletonMonoBehaviour<SelectionManager>

  • Requires ISelectable interface implementation for selectable objects

  • Uses UnityEvent system for event handling

Last updated