Touchscreen Input
Overview

NeoFPS comes with a custom touchscreen setup for games targeting mobile devices. There are input manager and input system versions of the touch controls, along with replacement UI prefabs to demo them.
The touchscreen controls system works by attaching a "virtual input" device to the NeoFPS input manager. When the input handlers (such as for firearms or character movement) check for input each frame, they will also check the virtual input. In the case of the default input manager setup, this means asking the virtual input the FpsInputButton or FpsInputAxis values. In the case of the input system, this means asking the virtual input for a value corresponding with the relevant input action's GUID.
The touchscreen controller component checks for taps each frame. For any new touch inputs it detects all the controls under that point, and assigns a "touch processor" that stores those controls. Each frame until the touch is released the processor will work through the controls in priority order and ask them to handle the input. Each control can then consume the input or allow it to fall through to the control underneath it. This allows for behaviour such as in the demo HUD prefab, where the whole screen is a giant virtual trackball for aiming that falls through to a shoot button. Any other controls on top of that such as the movement or buttons consume their input so it never reaches those aim or shoot controls.
Monobehaviours
The touchscreen system utilises the following behaviours:
| Input Manager Behaviour | Input System Behaviour | Description |
|---|---|---|
| NeoFpsTouchScreenController | NeoFpsInputSystemTouchScreenController | The controller is the behaviour that actually detects touches and passes them on to the attached controls. |
| NeoFpsTouchButton | NeoFpsInputSystemTouchButton | The touch button emulates tapping or holding a key or gamepad button. |
| NeoFpsTouchInventoryButton | NeoFpsInputSystemTouchInventoryButton | The inventory touch button is meant to be added to the inventory HUD element's slot items. It gets the slot index from the item and uses that to detect which input button / action ID to use. |
| NeoFpsTouchVirtualAnalog | NeoFpsInputSystemTouchVirtualAnalog | The virtual analog emulates an analog stick on a gamepad. Pressing near the middle will only give slight results, while moving further from the center will give a stronger input value. |
| NeoFpsTouchVirtualTrackball | NeoFpsInputSystemTouchVirtualTrackball | The virtual trackball emulates mouse style input as you would see with a trackball or trackpad. This is usually used for look/aim input as it can allow for very fine and precise control, or very quick large movements. |
There is a demo UI prefab called HudAndMenuCanvas_Touch in the folder Assets/NeoFPS/Samples/SinglePlayer/Prefabs that is fully set up with a touch based control scheme for a mobile FPS (HudAndMenuCanvas_InputSystemTouch in Assets/InputSystem/Prefabs for the input system version).
Mobile Performance
The NeoFPS demo scenes target standalone platforms and are not optimised for mobile devices. The following suggestions are intended to help get the best performance you can:
- The NeoFPS demo scenes use 2 layers for environment physics: EnvironmentDetail for high detail, bullet blocking colliders, and EnvironmentRough for low detail character collisions. For mobile you should drop the high detail physics and just use the Default layer for your environment objects. This will also mean that decals no longer show up, so if you want to re-enable these then you can switch decals on for the default layer via the surface manager in the NeoFPS hub.
- The demo prefabs use post-processing attached to the character camera. This requires your lighting be set to Linear in the player settings, and on Android this means you must manually set the OpenGL API compatibility to disable OpenGL ES 2. Post processing can be very expensive on mobile, as can many rendering features, so it is advised to switch to the Universal Render Pipeline.
- The way you build your games can have a drastic impact on performance. For example, switching the scripting backend from Mono to IL2CPP in your project's player settings can have a big impact. It's worth experimenting with the different settings here and following Unity's best practice advice for mobile platforms.
- If you have a lot of physics objects in your scenes, or environments with more complex physics, then it can be worth dropping your physics framerate in your project settings Time settings, and changing Fixed Timestep. This is how long each fixed frame lasts, so a larger value is a lower frame rate. The default of 0.02 means 50fps, but 30fps would be very playable for many mobile games.
- Due to the physical size of mobile phone screens, you can often drop the render resolution to have a big positive impact on performance, without drastically affecting the visual quality of your game. For example, the switch handheld games console runs at 720p when not docked, while many phones have 1080p screens.