# 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

```csharp
// 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

```csharp
public IReadOnlySelectables Selections;
```

* Description: Provides read-only access to all currently selected objects.

### ActiveSelections

```csharp
public IEnumerable<ISelectable> ActiveSelections;
```

* Description: Returns currently active selected objects.

### Count

```csharp
public int Count;
```

* Description: Returns the total number of currently selected objects.

### SelectionOrNull

```csharp
public ISelectable SelectionOrNull;
```

* Description: Returns the first selected object or null if no selection exists.

### HasSelection

```csharp
public bool HasSelection;
```

* Description: Indicates whether there are any selected objects.

### maxSelections

```csharp
public int maxSelections;
```

* Description: Maximum number of objects that can be selected simultaneously. Default is 12.

### IsMaxSelections

```csharp
public bool IsMaxSelections;
```

* Description: Indicates whether the maximum selection limit has been reached. Always returns false in infinity selection mode.

### IsInfinitySelectionMode

```csharp
public virtual bool IsInfinitySelectionMode;
```

* Description: Indicates whether infinite selection mode is active (maxSelections < 0).

## Events

### OnChanged

```csharp
public UnityEvent<IReadOnlySelectables> OnChanged;
```

* Description: Triggered whenever any change occurs in the selection state.

### OnSelectionChanged

```csharp
public UnityEvent<IReadOnlySelectables> OnSelectionChanged;
```

* Description: Triggered when the selection set changes.

### OnSubGroupChanged

```csharp
UnityEvent<IReadOnlySelectables> OnSubGroupChanged;
```

* Description: Triggered when the active subgroup changes.

## Methods

### New

```csharp
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

```csharp
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

```csharp
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

```csharp
public virtual int DeselectAll()
```

Clears all current selections.

* Returns: Number of objects deselected

### TryActiveNextSubGroup

```csharp
public virtual bool TryActiveNextSubGroup()
```

Attempts to activate the next subgroup in the selection.

* Returns: `true` if successful, `false` otherwise

### TryActivePreviousSubGroup

```csharp
public virtual bool TryActivePreviousSubGroup()
```

Attempts to activate the previous subgroup in the selection.

* Returns: `true` if successful, `false` otherwise

### IsSelected

```csharp
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

##
