Skip to content
Valentin Simonov edited this page Jul 30, 2017 · 9 revisions

When touches are created by Input Sources the library needs to find out if these touches actually hit anything in the scene. TouchScript does this using a sorted list of layers, i.e. objects extending TouchLayer class.

A target of a touch is a Transform in the scene.

Every layer from top to bottom is asked whether a new touch hits anything in this layer. If it does, this target is assigned to the touch and the loop stops. Layers also get notified of all touch-related events (began, moved, ended, cancelled) and can route this events to other subsystems. This is how ScaleformLayer used to work.

Working with layers

Right now TouchScript has the following layers:

  • StandardLayer which unifies raycasting into 3d, 2d and UI objects,
  • FullscreenLayer which when attached to a camera represents a fullscreen plane parallel to camera's display plane.

You can create layers manually in the Editor and change their ordering using TouchManager component or using ILayerManager.ChangeLayerIndex(int at, int to) method from your scripts.

Order and instantiation logic

Sometimes it's important to understand how layers you create manually or from a script register themselves with the system. When a scene starts events happen in this order:

  • (OnEnable) Everything defined (and manually sorted) on TouchManager component is registered in correct order.
  • (EndOfFrame) All layers try to register themselves. Nothing happens if they were already registered in appropriate order by TouchManager. Order here is undefined.
  • (NextFrame) If after this there are no layers in the scene, a StandardLayer is created and assigned to Camera.main.

Implementing your own layer

If you want to implement your own layer you can use StandardLayer as example.