Adding Input

Revisado con versión: 2017.2

-

Dificultad: Intermedio

Introduction

In previous sections we focused on setting up the game camera and the UI. Now we will need to make it possible for users to move the camera and interact with the user interface using both keyboard/mouse and touch input systems.

Configuring desktop and mobile control schemes

It is likely that some stages will be too large for a single screen, and players will want to pan the camera to view other parts of those stages. The Template comes with components that make this possible using both keyboard and mouse controls, and mobile touch controls.

The premade template GameCamera Prefab has components that enable multiple different input schemes. They are discussed below.

Understanding the InputController component

The InputController component determines which input system is active. It also fires off events made on input received in any given frame. The GameCamera object has this component attached to it. We will go through its fields below:

Drag Threshold Mouse

This will determine how many pixels must be dragged before the camera pans when using mouse controls.

Drag Threshold Touch

This will determine how many pixels must be dragged before the camera pans when using touch controls.

Tap Time

TapTime sets the maximum time for input to be registered as a tap.

Hold Time

HoldTime sets the minimum time for input to be registered as a hold.

Mouse Wheel Sensitivity

This sets how fast the camera will zoom when the mouse wheel scrolls.

Track Mouse Buttons

This determines how many mouse buttons to track.

Flick Threshold

This defines how far the mouse or touch input needs to move to register a "flick" when panning the camera.

Understanding the TowerDefenseKeyboardMouseInput component

The TowerDefenseKeyboardMouseInput component provides functionality for panning the camera using the mouse and keyboard.

Near Zoom Pan Speed Modifier

This field controls the keyboard pan speed difference between being fully zoomed in versus fully zoomed out.

Screen Pan Threshold

ScreenPanThreshold sets the distance the mouse must be from the screen edge before the camera starts to pan.

Mouse Edge Pan Speed

MouseEdgePanSpeed defines how fast the camera pans when scrolling at the edge of the screen.

Mouse Rmb Pan Speed

MouseRMBPanSpeed defines how fast the camera pans when moving the mouse with the right mouse button held.

Understanding the TowerDefenseTouchInput component

The TowerDefenseTouchInput component provides functionality for moving the camera using mobile touch input and interacting with the UI for the mobile version of the Template.

Near Zoom Pan Speed Modifier

This field controls the keyboard pan speed difference between being fully zoomed in versus fully zoomed out.

Pan Area Screen Percentage

This defines how much of the area around the middle of the screen can be used to pan. When the user is dragging a tower within this area of the screen, the camera will pan.

Pan Speed

This defines how fast the camera moves while panning using touch input.

Flick Decay Factor

How long it takes for the camera to stop moving after a flick.

Confirmation Buttons

This contains a reference to the UI prefab that we want to show players when they have dragged a tower visualizer to a valid placement location.

Invalid Buttons

This contains a reference to the UI prefab that we want to show players when they have dragged a tower visualizer to an invalid placement location.

Tutoriales relacionados