Unit Selection
  • Welcome
    • πŸ‘‹Hello
    • πŸ—ΊοΈRoadmap
    • ⛑️Support & Community
    • πŸŽ“Changelog
  • Getting started
    • πŸ”ŒImport package
    • πŸ› οΈAdd selection to scene
    • 🦲Add selection to units
    • β›³Add visuals to units
  • How it works
    • 🎯Active Selections
    • 🫡Unit Selector
    • πŸ”’Quick Access Selector
    • ⬛Selection Area
      • πŸ”²2D Rectangle
      • 🧊3D Cube
    • πŸ’ Selectable Unit
      • πŸ“Selection Bounds
      • β­•Selection Indicator
    • Selectable Group Unit
    • ⌨️Input Controls
    • πŸ‘·β€β™€οΈUnit Management
Powered by GitBook
On this page
  • Overview
  • Configuration
  • Customisation
  1. How it works

Selectable Unit

Everything about SelectableUnit component.

Previous3D CubeNextSelection Bounds

Last updated 7 months ago

Overview

SelectableUnit component implements state management for the unit selection along with updating the Selection Indicator reference (if one is set). This component provides out of the box functionality for unit selection by implementing ISelectable interface. This is default single selection behaviour, for selecting a unit as group of units see the extension component Selectable Group Unit.

Configuration

There are only few things this component does, so options to customise also reflect this.

  • Selection Indicator reference is used for updating visual state of the unit.

    More details selection indicators can be found here Selection Indicator.

  • Indicator Priority defines which of the visual states is shown when both are active (selected and highlighted). Simple example of this scenario would be when unit is already selected and mouse hovers over it. Should it keep selected state showing or override it with highlighted state.

  • OnSelectionStateChange is Unity Event invoked when any of the selection states on unit change. You can use this to update custom any data needed managed by your components or updating custom selection indicator that does not use ASelectionIndicator abstraction

Customisation

Communication between units and selection system is done with ISelectable interface. To replace the use of SelectableUnit component, create or use existing mono behaviour to implement your own management of the unit state. Example:

class MySelectionUnit : MonoBehaviour, ISelectable // ISelectable is key here
{
    // And implementation of required properties and methods for the interface.
    public bool IsSelected { get; private set; } = false;

    public bool IsHighlighted { get; private set; } = false;

    public void Select()
    {
        // Select my unit
        IsSelected = true;

        // Here you can update your visuals for the unit
    }

    public void Deselect()
    {
        // Deselect my unit
        IsSelected = false;
    }

    public void Highlight()
    {
        // Highlight my unit
        IsHighlighted = true;
    }

    public void Unhighlight()
    {
        // Unhighlight my unit
        IsHighlighted = false;
    }
}

πŸ’ 
SelectableUnit component