⬛Selection Area

Read more about how selection areas work

Overview

The selection area is a component responsible for presenting visuals for selection and for detecting any units within its area.

The abstract class ASelectionArea facilitates communication between the UnitSelector and various types of selection areas. This design allows for flexibility in the type of selection area you can implement, supporting a range of both existing and potentially new, user-defined areas.

Supported Selection Areas:

  • 2D Screen Space Rectangle: Fully supported, ideal for straightforward rectangular selection interfaces.

  • 3D World Space Cube: Fully implemented, allowing for cubic selection volumes in the game world.

Currently Unsupported (But Possible):

  • 3D World Space Sphere: While not supported out of the box, this type of selection could also be implemented without a lot of effort, taking any existing implementation as a guide.

Customisation

UnitSelector manages the SelectionArea behaviour with the following interface:

public abstract class ASelectionArea : MonoBehaviour 
{
    // ....
    
    // Returns true if selection should start; invoked when mouse button press starts
    public abstract bool ShouldMouseDragStartSelection(Vector2 startPosition);
    
    // Updates visuals; invoked when mouse button press is active with it's new position
    public abstract void MouseDragContinues(Vector2 newPosition);
    
    // Removes the visuals; invoked when mouse button is released
    public abstract void MouseDragStops();
    
    // Returns current units within the selection area; Retrieved for highlighting
    // and selecting units
    public abstract List<GameObject> GetCurrentObjectsWithinArea(bool sortByDistance);
    
    // ...
}

To implement your own selection area, create a new class that extends ASelectionArea and implements the interface shown above. You can take a look at these supported selection areas as a guide if you get stuck: RectangleSelectionArea, CubeSelectionArea.

Last updated