π·ββοΈUnit Management
Learn how works! Managing selectable unit references for the selection system.
Last updated
Learn how works! Managing selectable unit references for the selection system.
Last updated
This topic is generally the last one you'll need to consider, and many games might not require any changes at all. However, we provide public interfaces allowing full customisation of this behaviour should you need to manage it yourself. Provided component ManageUnitObject implements this behaviour for you, if a custom one is used remove this component from your game objects.
The unit manager is crucial for supplying valid selectable units to the selection system. This communication is facilitated by the IUnitManager
interface. It's primary function is to provide a list of valid units for selection.
By implementing this interface you should provide custom list of valid units at any point, like switching between different lists based on some player action. Though for filtering itself there is a more straightforward approach using filter . Note that if the unit management interface has no selectable units, drag selection will not work, only units present in the list may be selected.
Using the ManageUnitObject component on selectable units means that the UnitManager handles everything, requiring no further action on your part.
This singleton manages all active and valid selectable units that have the ManageUnitObject component. It provides interfaces to add, remove, and clear units, although typically, you won't need to use these directly.
Provides events for managing unit lifecycle events within the game. This class is essential for cleaning up no longer valid unit references in the selection systems. It currently holds only one event named OnUnitRemoved and it should be invoked when unit is no longer valid for selection (was removed from SelectableUnits list). This makes sure that any reference using this object is removed and prevents potential null reference exceptions.
If ManageUnitObject Component is used, this is handled internally. Read it's documentation for further information.
This component is part of drag selection feature and can be added through SelectableUnit component or manually. It notifies the UnitManager singleton about any changes in the unit's state like when they are instantiated, enabled, disabled, unloaded or otherwise destroyed.
When selectable units are no longer valid for selection, destroyed or otherwise disabled, selection system must be notified to prevent using no longer valid game objects. It would look something like this:
If you desire to create your own behaviour instead of using this singleton, you replace it by implementing your own IUnitManager
. All code is accessible and well documented, adjusting it or create your own.
In case you into problems creating your own manager, we are always here for you .