Mobile Controls Module
Provides touch controls for mobile devices.
Features
- Support for main camera touch controls:
- Panning: One finger touch, drag and drop to pan.
- Zoom: Two finger touches that move closer or further away from each other to trigger a zoom in or out.
- Rotation: Two finger touches that move in a circular motion to trigger a positive or negative rotation.
- Local player faction building placement:
- Touch support for dragging and dropping building placement instances with special UI elements that allow for placement rotation, completion and cancellation.
- Support for advanced building placement (segmentation/wall placement and grid placement).
- Example Basic UI components.
Demo
Requirements
- RTS Engine 2023.0.0 or higher
Installation
Get it from the Mobile Controls Module and import it into your project.
Guide
Configure Map Scene
1. Configure New Map Scene
Go ahead and create a new scene, we'll refer to it as tutorial_map_mobile, and save it somewhere in your project.
To import the RTS Engine mobile related components into the scene, click on the RTS Engine top bar dropdown menu and navigate on Modules -> Mobile Controls -> Configure New Map Scene.
1.2 Configure Existing Map Scene
Save your existing map scene scene in a different scene file first as a backup. Then click on the RTS Engine top bar dropdown menu and navigate to Modules -> Mobile Controls -> Confgiure Existing Map Scene. This will remove the manager components that do not work in mobile and replace them with their corresponding mobile manager components.
1.3 Configure Map Scene with Advanced Building Placement Module
If your scene is using the Advanced Building Placement module, then you want to use the appropriate component that handles advanced building placement features with mobile controls. Download the package from here. It contains one script under the name AdvancedLocalMobileFactionPlacementHandler that you can find in the following project tab path: RTS Engine -> Modules -> Mobile Controls -> Scripts -> BuildingExtension. Now in your current map scene (assuming it has been configured as a new or existing map scene), find the Local Mobile Faction Placement Handler in the hierarchy path: GameManager -> Modules -> Mobile -> BuildingExtension_mobile, remove it and replace it with the advanced building placement one.
2. Mobile Controls Components
In this section, we will go through the components that allow for mobile controls. These components are present in your map scene if you have configured your new or existing map scene by following the steps in the previous section.
2.1 Building Placement
When a building placement is launched, the placement manager will find the closest visible position in the current player's screen space to put the building in and if there is none, it will search through the map until it finds one and then shifts the camera to it.
The player can move the building they are placing by dragging and dropping its model object. The mobile controls provides an example UI panel that handles completing or cancelling the placement as well as rotating the building to place in both directions. The former four capabilities are provided via a demo component that you can find in the hierarchy path: GameManager -> Modules -> Mobile -> BasicUI_mobile -> Demo -> UI under the name of MobileDemoUIHandler. This script has the following fields for building placement:
The Placement Panel is the panel that appears when an active building placement is occuring while the rest are control buttons for the placement. The Place Button and Stop Button are fed the proper actions through this component while the buttons responsible for the building's rotation have the direct rotation methods assigned in their button click event triggers.
Plese note that this is just an example for how the UI placement can be implemented and you are not required to use as you can easily build your own solution here using the RTS Engine API.
There are two ways to handle the building placement for the local player.
- Through the Local Mobile Faction Placement Handler component which is the default placement handler. Find it in the hierarchy path: GameManager -> Modules -> Mobile -> BuildingExtension_mobile.
- Reserve Placement Resources: Reserve resources that will be used to place the placement buildings so that the player faction does not consume them before the placement is completed.
- Can Rotate: Enable to allow for rotating buildings while placing them.
- Rotation Speed: How fast does the building rotate when the player.
- Double Tap On Building Complete Placement: Allow double tapping on a building placement instance to place it?
- Double Tap Outside Building Stop Placement: Allow double tapping outside of a building placement instance to place it?
- Through the Advanced Local Mobile Faction Placement Handler if your scene is using the Advanced Building Placement module which is a hybrid component that includes the same fields from the advanced building placement manager and the former mobile placement manager component.
2.2 Selection
Instead of using the Mouse Selector, the mobile controls use the Touch Selector component. You can find it in the hierarchy path: GameManager -> Modules -> Mobile -> Selection_mobile. While both components have the same inspector fields, the touch selector works a little bit differently.
- If no entities are selected:
- If you select any entity it will be selected.
- If one or more entities are selected:
- If the selected entities are local player faction entities then another click on another entity will trigger a direct action on that clicked entity.
- If the selected entities are not local player faction entities, then another click on another entity will just switch selection to the clicked entity.
2.3 Camera Controllers
There are three aspects to the main camera controller:
- Panning: One finger touch, drag and drop to pan.
- Zoom: Two finger touches that move closer or further away from each other to trigger a zoom in or out.
- Rotation: Two finger touches that move in a circular motion to trigger a positive or negative rotation.
While the Main Camera Controller remains the same, new control handlers are added to handle mobile platforms.
You can find those mobile control handlers in the following hierarchy path: GameManager -> Modules -> Mobile -> Cameras_mobile. While they do share most of their fields with the keyboard based camera control handlers, some fields are different.
Here we will expore the mobile specific fields for these control handlers so please refer to the camera controller documentation for the rest of the fields:
- Main Camera Mobile Panning Handler: The Min Drag Distance fields determines the minimum distance between the touch start position and the dragged touch position to trigger panning.
- Main Camera Mobile Zoom Handler: The Sensitivity field determines the zooming sensitivity, the higher the value, the faster zooming is. While the Min Drag Distance field defines the minimum distance to move between the two touch positions to trigger a zoom.
- Main Camera Mobile Rotation Handler: The Sensitivity field defines the rotation sensitivity, the higher the faster the rotation is. While the Min Angle field defines theminimum absolute value of the angle between the two touch positions to trigger a rotation.
2.4 Basic UI (Mobile)
This module requires the Basic UI module as it extends it to implement it mobile friendly UI panels and controls. You can find the UI components and the UI panels under the hierarchy path: GameManager -> Modules -> BasicUI_mobile.
Changelog
v2023.0.0
Release Date: 05/10/2023
Requirements
RTS Engine 2023.0.0 or higher
Changes
Initial Release
v2023.0.1
Release Date 06/27/2023
Requirements
RTS Engine 2023.0.1 or higher
Changes
ADD zoom to middle option which can be enabled to zoom the camera towards the position between the two touch positions required to zoom.
v2023.0.2
Release Date 09/25/2023
Requirements
RTS Engine 2023.0.2 or higher
Changes
UPDATE UI elements in the mobile controls demo game so that they work with different mobile and tablet screen sizes and aspect ratios.