admin管理员组

文章数量:1516870

TouchScript中文

github英文:


The Journey of a Touch Point

This section describes how a touch pointer originated at user's finger gets to a gesture.

这个环节来解释,一个来自用户手指的touch pointer是如何到gesture动作的。

(理解这个环节非常重要!!!!!!!!!!!)

First, a touch pointer comes to an Input Source. It doesn't matter what touch-enabled device is used, it might be mouse or a fake pointer generating script. All input sources have CoordinatesRemapperproperty which may contain an instance of ICoordinatesRemapper. In this case all touch pointers go through it before getting to TouchManager.

首先,一个touch pointer来自一个输入源。无所谓是什么样的可触摸设备,可能是一个mouse pointer或者是一个fake pointer。所有的输入源都是有坐标重映射的属性,该属性包含ICoordinatesRemapper的实例。在这种情况下,所有的touch pointers都重映射然后到TouchManager。

Remappers are used when an input device isn't aligned to the screen correctly.
It might be necessary to rotate or scale data to match the screen.

为什么要重映射呢?因为输入设备的坐标系要和unity屏幕坐标对齐。

Since many pointer events can theoretically arrive between frames, TouchManager keeps them in buffers till the next Update. During the next Update all messages are processed and the following events are dispatched in the following order:

由于许多pointer events都在两帧之间来到,TouchManager把它们保存在缓冲区内知道下一帧。在下一帧,所有的消息都会被处理,接下来的事件就会按照如下顺序分发:

Before dispatching PointersPressed TouchManager goes through all instances of TouchLayer in the scene to determine if one of them wants to take pressed pointers (note: there might be several pointers pressed during a frame).

The most used layer type is StandardLayer. It checks if a ray originated from camera's position hits any collider or UI element in the scene. If it does, the system checks if there are any instances of HitTest attached to target object. They can intercept successful raycasts and modify them. For example Untouchable makes it impossible to touch an object.

Note: before version 9.0 there was a CameraLayer, which is now merged into StandardLayer.

Layer sets current target of a pointer which is accessible via Pointer.GetPressData() method.

在分发PointersPressed事件之前,TouchManager会遍历TouchLayer的所有实例,来决定它们中的任何一个想要接受这个pressed pointers。

最常用的layer类型是StandardLayer。它检查摄像机的射线是否hit到任何一个collider或者UI元素上。如果hit上了,系统会检查是否有HitTest的实例附载在该目标物体上。他们可以拦截射线并且更改射线。比如说Untouchable就是触摸一个物体变得不可能。

Layer设置了当前目标pointer,通过Pointer.GetPressData()设置的。

When Target is determined, touch pointer goes to GestureManager with PointersPressed event. GestureManager checks if any gesture on the target or in its transform hierarchy is interested in this pointer. This process is a bit tricky.

当决定了一个目标对象,touch pointer会通过PointersPressed事件到GestureManager。GestureManager检查目标对象上的任何动作是否对该pointer有兴趣。过程有点复杂。

For example we have an interface shown on the image above with nested boxes. When user touches box E the system looks for all the gestures on boxes from the root object to the Target which are able to receive touch input (in this case boxes EC and A). If there's no active gesture in the graph containing the Target, all gestures get the touch pointer until one of them changes its state to Recognized or Began.

So, let's assume that some gesture on box E got this touch point and started. It now owns this touch pointer and all other gestures in the graph which are not friendly to this gesture and returned true from CanBePreventedByGesture(gesture) will be forced to fail and reset.

例如,上面的图像中显示了一个带有嵌套框的接口。
当用户触摸E这个box,系统从根对象到目标对象查找所有在box上的能够接收到touch input的gesture(在这种情况下盒子E、C和A)。如果没有active的动作在包含目标的graph上,所有动作获取touch pointer,直到它们中的一个更改状态到Recognized或者Began。

假设box E上的一些gesture获得了这个touch point并且开始了。。
它现在拥有这个touch pointer和graph中的所有其他手势,这些手势对这个手势不友好,从canbetedbygesture(手势)返回true,将被迫失败和重置。

Now user touches box C which is a parent container of box E. The system once again grabs all gestures on yellow boxes but checks them against all the gestures on green boxes. In this case a gesture on box E is active and prevents all gestures starting from C and up from beginning.

To make gestures in hierarchy work together we need to add one to another's Friendly gestures property in inspector or via AddFriendlyGesture(gesture) method. If gestures are friendly they can share owned touch pointers.

When PointersUpdatedPointersReleased or PointersCancelled events occur, the process is much simpler since only gestures which own touch pointers from an event will be notified.

So, that's how a touch pointer goes all the way from an input device to gestures.

现在用户触摸box C,它是box E的父容器。系统再次抓取黄色盒子上的所有gesture,并将它们与绿色盒子上的所有gesture进行对比。
在本例中,box E上的一个gesture是active的,它阻止所有从C开始和从开始的gesture。

为了使gesture在层次结构中协同工作,我们需要在检查器中或通过AddFriendlyGesture(gesture)方法将一个手势添加到另一个的Friendly gesture属性中。
如果手势友好,它们可以共享自己的touch pointers。

当pointersupdate、pointersrelease或pointerscancated事件发生时,过程要简单得多,因为只有拥有来自事件的touch pointer的gesture才会得到通知。

这就是触摸指针从输入设备到手势的全部过程。

 

 

本文标签: TouchScript中文