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
Properties
Groups
Type:
IReadOnlyDictionary<int, List<ISelectable>>
Description: Read-only dictionary containing all selection groups.
CurrentGroupIndex
Type:
int?
Description: The index of the currently selected group. Can be null if no group is selected.
Methods
TrySave
Saves the current selection or specified selectables to a group.
Parameters:
groupIdx
: The index where the group will be savedselectables
: Collection of selectable objects to save
Returns:
true
if save was successful,false
otherwise
AddSelectionsAt
Adds current selections or specified selectables to an existing group.
Parameters:
groupIdx
: The target group indexselectables
: Collection of selectable objects to add
Returns: Number of items successfully added
RemoveSelectionsAt
Removes current selections or specified selectables from a group.
Parameters:
groupIdx
: The target group indexselectables
: Collection of selectable objects to remove
Returns: Number of items successfully removed
SelectGroup
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
Removes an entire group.
Parameters:
groupIdx
: The index of the group to remove
Returns:
true
if group was successfully removed,false
otherwise
HasGroup
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
Checks if a specific selectable object exists in a group.
Parameters:
groupIdx
: The group index to checkselectable
: The selectable object to look for
Returns:
true
if the object exists in the group,false
otherwise
IsGroupSelected
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:
selectionMgr.OnSelectionChanged
: Called when the selection changes, triggersResetCurrentGroupIndex
Dependencies
Inherits from
SingletonMonoBehaviour<SelectionGroupManager>
Uses
ISelectable
interface for selectable objects
Last updated