# Selection Area

## Overview

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

The **abstract class&#x20;**<mark style="color:blue;">**ASelectionArea**</mark> facilitates communication between the <mark style="color:blue;">**UnitSelector**</mark> 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:**

* <mark style="color:yellow;">**2D Screen Space Rectangle**</mark>: Fully supported, ideal for straightforward rectangular selection interfaces.
* <mark style="color:yellow;">**3D World Space Cube**</mark>: 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

<mark style="color:blue;">**UnitSelector**</mark> manages the **SelectionArea** behaviour with the following interface:

```csharp
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**.

In case you have any trouble implementing it, please reach out to us [#general-support](https://travljen.gitbook.io/unit-selection/welcome/support-and-community#general-support "mention").
