예제 #1
0
    public void OnTouch(TouchPoint touch)
    {
        int fingerID = touch.GetID();

        EventBase.Type gesture  = touch.GetGesture();
        Ray            touchRay = touch.GetRay();

        // Check if the ray from the main camera touch intersects with a collider or rigidbody
        // and determine if the ray intersects this object
        RaycastHit rayCast;

        if (Physics.Raycast(touchRay.origin, touchRay.direction, out rayCast) && rayCast.transform.gameObject == gameObject)
        {
            isTouched = true;
        }
        else
        {
            isTouched = false;
        }

        switch (gesture)
        {
        case (EventBase.Type.Down):
            // Add finger to list
            if (isTouched)
            {
                if (touchlist.Contains(fingerID))
                {
                    Debug.Log("Warning: Touch down detected for existing touch - should not happen");
                }
                touchlist[fingerID] = touch;
                OnTouchDown(touch);
            }
            break;

        case (EventBase.Type.Move):
            if (isTouched)
            {
                touchlist[fingerID] = touch;
                OnTouchMove(touch);
            }
            else if (touchlist.Contains(fingerID))
            {
                touchlist.Remove(fingerID);
                OnTouchUp(touch);
            }
            break;

        case (EventBase.Type.Up):
            if (touchlist.Contains(fingerID))
            {
                touchlist.Remove(fingerID);
                OnTouchUp(touch);
            }
            isTouched = false;
            break;
        }
    }