> For the complete documentation index, see [llms.txt](https://santutu.gitbook.io/rts-selection-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://santutu.gitbook.io/rts-selection-system/api/groupselectionmanager.cs.md).

# GroupSelectionManager.cs

`GroupSelectionManager` is a singleton class that manages groups of selectable objects in a game system. It provides functionality to create, modify, and select groups of objects.

## Usage Example

```csharp
// Get reference to GroupSelectionManager
var groupManager = GroupSelectionManager.Instance;

// Save current selection to group 1
groupManager.TrySave(1);

// Add more selections to group 1
groupManager.AddSelectionsAt(1);

// Select group 1
groupManager.SelectGroup(1);

// Remove group 1
groupManager.RemoveGroup(1);
```

##

## Properties

### Groups

```csharp
public IReadOnlyDictionary<int, List<ISelectable>> Groups;
```

### CurrentGroupIndex

<pre class="language-csharp"><code class="lang-csharp"><strong>public int? CurrentGroupIndex;
</strong></code></pre>

## Methods

### TrySave

```csharp
public virtual bool TrySave(int groupIdx)
public virtual bool TrySave(IEnumerable<ISelectable> selectables, int groupIdx)
```

Saves the current selection or specified selectables to a group.

* Parameters:
  * `groupIdx`: The index where the group will be saved
  * `selectables`: Collection of selectable objects to save
* Returns: `true` if save was successful, `false` otherwise

### AddSelectionsAt

```csharp
public virtual int AddSelectionsAt(int groupIdx)
public virtual int AddSelectionsAt(IEnumerable<ISelectable> selectables, int groupIdx)
```

Adds current selections or specified selectables to an existing group.

* Parameters:
  * `groupIdx`: The target group index
  * `selectables`: Collection of selectable objects to add
* Returns: Number of items successfully added

### RemoveSelectionsAt

```csharp
public virtual int RemoveSelectionsAt(int groupIdx)
public virtual int RemoveSelectionsAt(IEnumerable<ISelectable> selectables, int groupIdx)
```

Removes current selections or specified selectables from a group.

* Parameters:
  * `groupIdx`: The target group index
  * `selectables`: Collection of selectable objects to remove
* Returns: Number of items successfully removed

### SelectGroup

```csharp
public virtual bool SelectGroup(int groupIdx)
```

Selects all objects in the specified group.

* Parameters:
  * `groupIdx`: The index of the group to select
* Returns: `true` if group was successfully selected, `false` otherwise

### RemoveGroup

```csharp
public virtual bool RemoveGroup(int groupIdx)
```

Removes an entire group.

* Parameters:
  * `groupIdx`: The index of the group to remove
* Returns: `true` if group was successfully removed, `false` otherwise

### HasGroup

```csharp
public virtual bool HasGroup(int groupIdx)
```

Checks if a group exists and contains any selectables.

* Parameters:
  * `groupIdx`: The group index to check
* Returns: `true` if group exists and is not empty, `false` otherwise

### ContainAtGroup

```csharp
public virtual bool ContainAtGroup(ISelectable selectable, int groupIdx)
```

Checks if a specific selectable object exists in a group.

* Parameters:
  * `groupIdx`: The group index to check
  * `selectable`: The selectable object to look for
* Returns: `true` if the object exists in the group, `false` otherwise

### IsGroupSelected

```csharp
public virtual bool IsGroupSelected(int groupIdx)
```

Checks if a specific group is currently selected.

* Parameters:
  * `groupIdx`: The group index to check
* Returns: `true` if the specified group is currently selected, `false` otherwise

## Events

The class listens to the following events:

```csharp
public UnityEvent<GroupChangedEventArgs> onGroupChanged;
```

```csharp
public UnityEvent<GroupSelectedEventArgs> onGroupSelected;
```

##

## Dependencies

* Inherits from `SingletonMonoBehaviour<SelectionGroupManager>`
* Uses `ISelectable` interface for selectable objects

##
