π²2D Rectangle
Learn more about rectangle selection area
Last updated
Learn more about rectangle selection area
Last updated
Uses mouse drag start and current screen positions to calculate rectangle on screen. Then uses configurations to render the rectangle on screen in the OnGUI
method.
Note: Prefab is named 2D Rectangle Selection Area.
Customise the appearance and behaviour of the selection rectangle to suit your game's needs.
Custom Textures
Custom Fill and Border Textures: Customise the textures used for the fill and border of the selection area. By default, a plain white texture is employed, which serves as a neutral base. If you use custom textures featuring distinct colors or transparent pixels, consider setting the fill and border colors to white. This ensures your textures appear without any unintended color tinting.
Color Settings
Fill and Border Colors: Define the colors for rendering the fill and border of your selection area. This allows for a high degree of visual customization, enabling the selection area to match or contrast with the game environment effectively.
Border Properties
Border Thickness: Specify the thickness of the border around the selection area. This border is rendered externally and does not influence the behavior or visibility of the selection components inside it.
The rectangle selection area supports various detection methods, which are crucial for determining whether units fall within the specified selection boundaries. Each method varies in how it accounts for unit positions and their boundaries:
ScreenPosition
Description: Transforms units' world positions to screen positions and checks if these positions are within the selection area. This method is effective for direct visual correspondence with the user's view.
WorldPosition
Description: Creates a frustum for the selection area at maximum distance and checks if units' world positions fall within it. This method is useful for selecting units based on their actual positions in the game world, regardless of the camera's perspective. This produces the same result as ScreenPosition, but different technique is used.
RendererBounds
Description: Utilizes Axis-Aligned Bounding Box (AABB) tests for renderer bounds. This method does not consider rotation, making it suitable when rotation does not significantly affect the selection relevance.
Consideration: Rotation is ignored in this method. If units significantly differ in dimensions along the X and Z axes, and rotation may affect the detection, Screen or World Position detection should be considered.
Optimisation: Renderer is retrieved using GameObject.GetComponentInChildren<Renderer>()
method, which can lead to two things; performance impact and selecting the wrong renderer if game object has more than one. Using RendererSelectionBounds component with specified renderer and CustomBounds detection type will optimise this detection process.
CustomBounds
Description: Similar to RendererBounds, this method creates a frustum for the selection area at maximum distance and performs AABB tests for custom selection bounds. Like RendererBounds, rotation is not considered.
Consideration: This method is ideal for custom-defined bounds that do not follow standard rendering bounds. It shares the same limitations regarding rotation as RendererBounds.
Requirement: This detection type requires for selectable units to have a component that implements ISelectableBounds. There are few available out of the box, you can find them here Selection Bounds.
When choosing a detection type, consider the geometric properties of the units and how they are likely to interact with the selection area. For units that vary greatly in dimensions along the X and Z axes and where rotation could alter the selection outcome, WorldPosition or ScreenPosition may provide more accurate results.