> 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

##


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://santutu.gitbook.io/rts-selection-system/api/groupselectionmanager.cs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
