Exemplo n.º 1
0
    /// <summary>
    /// Handles the end of an Input.
    /// </summary>
    /// <param name="fingerID">ID of current Input.</param>
    /// <param name="position">Position of current Input.</param>
    private void HandleTouchEnded(int fingerID, Vector2 position)
    {
        bool hitUI      = false;
        bool interacted = false;

        //Hit an UI Element (contains Canvas Renderer)?
        hitUI = CheckForUI(position);

        if (hitUI)
        {
            //Send TouchEnded Event with information that UI was hit
            if (OnTouchEnded != null)
            {
                OnTouchEnded(hitUI);
            }
            //Cancel Input Handle because UI was hit.
            return;
        }

        //Send Raycast, get GameObjects
        foreach (RaycastHit hit in CastWorldRay(position, Color.yellow))
        {
            //Get ITouchable, if true trigger touch on gameObject
            ITouchable touchObject = hit.collider.gameObject.GetComponent <ITouchable>();

            if (touchObject != null && inputFocus.Count > 0)
            {
                if (GetTouchFocus(fingerID).myTouchable == touchObject)
                {
                    touchObject.InputEnd();
                    interacted = true;
                }
            }

            //NOTE: Stop, because only one object shall be hit!
            if (interacted)
            {
                break;
            }
        }

        //Send OnTouch Event with information that no UI was hit.
        if (OnTouchEnded != null && !interacted)
        {
            OnTouchEnded(hitUI);
        }
    }