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

  • 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

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

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

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

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

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

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

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

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:

  • selectionMgr.OnSelectionChanged: Called when the selection changes, triggers ResetCurrentGroupIndex

Dependencies

  • Inherits from SingletonMonoBehaviour<SelectionGroupManager>

  • Uses ISelectable interface for selectable objects

Last updated