TouchScreenMenuBase
A class in Root.Township, the global namespace.
Base for an in-world touch screen that the local player's fingertips press: maps child buttons to screen rectangles, presses and releases them, and reports swipes. Client side; call Setup with true for the local player.
- Listed in Global namespace: T to X
- Inherits or implements
MonoBehaviour - Derived types
TouchScreenMenu,TouchScreenKeyboard - Nested types
TouchInput
Constructors
| Member | What it is |
|---|---|
TouchScreenMenuBase() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
protected Vector2 dimensions | Size of the screen area. |
protected readonly Dictionary<KeyCode, ILabeledTouchScreenButton> instantiatedSuggestionKeys | Extra labelled keys by key code, also mapped as buttons. |
22 private and internal fields
| Member | What it is |
|---|---|
private ITouchScreenButton activeButtonPress | With multi-touch off, the one button now pressed. |
private bool alwaysShowButtons | If true, the buttons stay visible; else they only show while a finger is close. |
private Rect baseRect | Screen area that covers every mapped button, in local space. |
private readonly List<ITouchScreenButton> buttonPressCache | Reused list of buttons to press this frame. |
private GameObject buttonsParent | Object holding the buttons; turned on and off to show them. |
private Transform canvasTransform | Transform used to measure finger distance; set to the buttons parent. |
private bool isEnabled | Set each frame when a finger is close, to show the buttons. |
private bool isMultiTouch | Whether several buttons can be pressed at once. |
private bool isSetupLocal | Set once Setup has run for the local player with fingertips. |
private static Logger logger | NLog logger for this class. |
private float minDistanceToRenderSquared | Squared distance a fingertip must be within for touches to count and buttons to show. |
private PositionEvent onScreenReleasedEffects | Effects played at a button's position when it is released. |
private PositionEvent onScreenTouchEffects | Effects played at the fingertip when the screen is touched. |
private bool setupOnStart | Serialized option. Not read in this class. |
private HashSet<ITouchScreenButton> toRelease | Buttons to check for release this frame. |
private HashSet<ITouchScreenButton> touched | Buttons pressed this frame, so they aren't released. |
private float touchHaptic | Haptic strength sent to the hand on a touch. |
private TouchScreenMenuBase.TouchInput[] touchInputs | Touch trackers for the right and left fingertips. |
private float touchReleaseThreshold | Distance from the screen a finger must pull back to end a touch. |
private float touchThreshold | Distance from the screen within which a finger starts a touch. |
private bool triggerEffectsOnButtonTouchOnly | If true, touch and release effects only play when a button is hit. |
private Coroutine updateTouch | Running touch update coroutine, or null. |
Properties
| Member | What it is |
|---|---|
virtual List<ITouchScreenButton> InstantiatedButtons { get; set; } | Buttons on the screen. Filled from the buttons parent if empty when mapping. |
protected Dictionary<ITouchScreenButton, Rect> ButtonMap { get; } | Each button's rectangle in the screen's local space. |
protected Transform ButtonsParent { get; } | Parent of the buttons; shown only while a finger is close unless always shown. |
protected virtual bool IsScreenFree { get; } | Whether touches are processed. True by default. |
protected virtual Vector2 Offset { get; set; } | Offset for subclasses. |
protected float TouchReleaseThreshold { get; } | Distance from the screen at which a touch ends. |
protected float TouchThreshold { get; } | Distance from the screen at which a touch starts. |
Events
| Member | What it is |
|---|---|
event Action<Vector2> SwipeExecuted | Raised with the swipe vector when a touch that hit no button ends. |
Methods
| Member | What it is |
|---|---|
void MapButtons() | Rebuilds the button rectangles and the screen bounds from the button positions and sizes. |
void Setup(bool isLocal) | For the local player, maps buttons and starts tracking both fingertips; hides the buttons unless always shown. |
protected void DisableButtons() | Hides the buttons. |
protected void EnableButtons() | Shows the buttons if a finger is close. |
protected virtual void OnDrawGizmos() | Draws the screen area and touch depth. |
protected virtual void PostTouchCalculation() | Hook run after each frame's presses and releases. |
protected virtual void PreTouchCalculation() | Hook run before each frame's presses; clears the touched and release lists. |
protected virtual void SetupForLocal() | Hook run at the end of local setup. |
protected virtual void UpdateTouchWithButtons(TouchScreenMenuBase.TouchInput touch) | Hook run for each finger after its press is processed. |
10 private and internal methods
| Member | What it is |
|---|---|
private bool IsButtonValid(KeyValuePair<ITouchScreenButton, Rect> buttonPair, TouchScreenMenuBase.TouchInput touch) | True if the button is enabled, active, allowed under the multi-touch rule and contains the touch. |
private bool IsFirstPressInBounds(TouchScreenMenuBase.TouchInput touch) | True if the touch just started and is inside the screen's button area. |
private void MapKey(Matrix4x4 matrix, ITouchScreenButton button, ref Vector2 min, ref Vector2 max) | Works out a button's rectangle on the screen and grows the overall bounds to fit it. |
private void OnDisable() | Stops the touch update coroutine. |
private void OnEnable() | Restarts the touch update coroutine if the screen was set up for the local player. |
private void ProcessButtonPress(TouchScreenMenuBase.TouchInput touch) | On a new touch inside the screen, presses every button under the finger and plays the haptic and touch effects. |
private void UpdateButtonPresses() | Updates each free hand's finger touch, presses buttons, raises swipes and notes if a finger is close. |
private void UpdateButtonReleases() | Releases pressed buttons no finger is still touching and plays the release effects. |
private IEnumerator UpdateTouch() (iterator) | Coroutine run at the end of each frame: handles presses and releases and shows or hides the buttons. |
private bool ValidateMultiTouch(ITouchScreenButton button) | With multi-touch off, only the button already being pressed counts. |
Used in
Members of other types that take, return or hold a TouchScreenMenuBase: