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
// 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
public IReadOnlyDictionary<int, List<ISelectable>> Groups;CurrentGroupIndex
public int? CurrentGroupIndex;Methods
TrySave
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 savedselectables: Collection of selectable objects to save
Returns:
trueif save was successful,falseotherwise
AddSelectionsAt
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 indexselectables: Collection of selectable objects to add
Returns: Number of items successfully added
RemoveSelectionsAt
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 indexselectables: Collection of selectable objects to remove
Returns: Number of items successfully removed
SelectGroup
public virtual bool SelectGroup(int groupIdx)Selects all objects in the specified group.
Parameters:
groupIdx: The index of the group to select
Returns:
trueif group was successfully selected,falseotherwise
RemoveGroup
public virtual bool RemoveGroup(int groupIdx)Removes an entire group.
Parameters:
groupIdx: The index of the group to remove
Returns:
trueif group was successfully removed,falseotherwise
HasGroup
public virtual bool HasGroup(int groupIdx)Checks if a group exists and contains any selectables.
Parameters:
groupIdx: The group index to check
Returns:
trueif group exists and is not empty,falseotherwise
ContainAtGroup
public virtual bool ContainAtGroup(ISelectable selectable, int groupIdx)Checks if a specific selectable object exists in a group.
Parameters:
groupIdx: The group index to checkselectable: The selectable object to look for
Returns:
trueif the object exists in the group,falseotherwise
IsGroupSelected
public virtual bool IsGroupSelected(int groupIdx)Checks if a specific group is currently selected.
Parameters:
groupIdx: The group index to check
Returns:
trueif the specified group is currently selected,falseotherwise
Events
The class listens to the following events:
public UnityEvent<GroupChangedEventArgs> onGroupChanged;public UnityEvent<GroupSelectedEventArgs> onGroupSelected;Dependencies
Inherits from
SingletonMonoBehaviour<SelectionGroupManager>Uses
ISelectableinterface for selectable objects
Last updated