将TUIO触摸输入转换为UNITY触摸

时间:2018-03-07 15:15:16

标签: unity3d touch unityscript

以下功能是什么样的,而不是使用UNITY触摸的TUIO触摸?

/// Fingers touch.
/// </summary>
private void FingerTouch ()
{
    var beganTouches = from Tuio.Touch t in TuioTrackingComponent.Touches.Values
        where t.Status == TouchStatus.Began
            select t;

    // Raycast and attached springs to the hit objects
    foreach (Tuio.Touch t in beganTouches) {    
        if (Physics.Raycast (Camera.main.ScreenPointToRay (new Vector3 (t.TouchPoint.x, t.TouchPoint.y, 0f)), out hit)) {
            if (hit.collider != null && hit.transform.gameObject.CompareTag ("FishCollider")) {
                touchedFishes.Add (t.TouchId, hit.transform.parent.gameObject);
                isHolding = true;
            }
        }
        MoveFish (t);
    }
}

1 个答案:

答案 0 :(得分:1)

非常相似。看看documentation

foreach (Touch touch in Input.touches)
{
    if (touch.phase == TouchPhase.Began)
    {
        if (Physics.Raycast(Camera.main.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0f)), out hit))
        {
            if (hit.collider != null && hit.transform.gameObject.CompareTag("FishCollider"))
            {
                touchedFishes.Add(touch.fingerId, hit.transform.parent.gameObject);
                isHolding = true;
            }
        }
        MoveFish(touch);
    }
}