Selectable Group Unit
More about the behaviour and implementation of a group as selectable unit.
Last updated
More about the behaviour and implementation of a group as selectable unit.
Last updated
There are 2 components required to use the functionality for group selection without any coding. This would be the SelectableGroupUnit (for every moving unit) and SelectableGroup (for group of units). These components extend the Selectable Unit and provide the same functionality with few additions to achieve smooth group selection.
Both selectable group and selectable group unit support selection indicator visuals. Example would be for individual units to show selection circles and group itself to show floating text, health bar or other additional information about the selected or highlighted group unit.
SelectableGroupUnit has all the properties already present on SelectableUnit. Additionally it implements ISelectableGroupUnit interface which provides a reference to the selectable group to which each individual unit belongs.
Group reference must be set for system to be able to match units and their groups together. This can be done within the Editor or dynamically using SetGroup
method on group unit component.
As long as group reference is present, unit will automatically be added or removed from the group. There should be no need to manually modify it's list.
SelectableGroup has again all the properties already present on SelectableUnit. Additionally it implements ISelectableGroup and additionally provides a list of units within the group.
Group units is a dynamic list of units within the group.
Destroy group when emptied flag will specify if group itself should be destroyed when the last unit from it's list is removed. Group component will be disabled if this is set to false
.
OnAllGroupUnitsRemoved is Unity Event invoked when all units were removed from the list.
Center selection indicator specifies if the indicator is updated every frame (when selected or highlighted) to the calculated center of its unit to be used as some floating GUI.
Communication between units and selection system is done with ISelectable. The same as group components, these interfaces are the extension of ISelectable. ISelectableGroup and ISelectableGroupUnit can be used to completely customise behaviour with your own implementations that work with the selection system.
Group example:
Group Unit example: