Exemple #1
0
    /// <summary>
    /// Handle touch on object
    /// </summary>
    /// <param name="position"></param>
    /// <param name="fingerId"></param>
    private void BeginTouch(Vector3 position, int fingerId)
    {
        var worldPosition = Camera.main.ScreenToWorldPoint(position);
        var hitInfo       = Physics2D.Raycast(worldPosition, Vector2.zero);

        if (hitInfo)
        {
            var touchable = hitInfo.transform.GetComponent <ITouchable>();
            if (touchable != null)
            {
                touchable.OnTouch();
            }

            if (_dragObject == null)
            {
                var dragable = hitInfo.transform.GetComponent <IDragable>();
                if (dragable != null)
                {
                    _dragObject = dragable;
                    _touchId    = fingerId;
                    _dragObject.OnDrag(worldPosition);
                }
            }
        }
    }
Exemple #2
0
    /// <summary>
    /// Handle drag on object
    /// </summary>
    /// <param name="position"></param>
    private void Drag(Vector3 position)
    {
        if (_dragObject == null)
        {
            return;
        }

        var worldPosition = Camera.main.ScreenToWorldPoint(position);

        _dragObject.OnDrag(worldPosition);
    }