Esempio n. 1
0
    public void OnBeginDrag(PointerEventData eventData)
    {
        _currentDraggedTile = (DraggedTile)Instantiate(DraggedTilePrefab);

        // we want to position the tile in absolute fashion not in relation to someone's pivot
        var canvasRect = GetComponentInParent <Canvas>()
                         .GetComponent <RectTransform>();

        _currentDraggedTile.transform.SetParent(canvasRect);
        _currentDraggedTile.Type = Type;

        // translate a screen point to world posiiton in the context of parent of the tile that we are moving
        Vector2 localPoint;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, eventData.position, Camera.main, out localPoint);
        _targetPositionForTile = localPoint;
        _currentDraggedTile.transform.localPosition = localPoint;

        // disable the image that we are currently dragging
        _image.enabled  = false;
        _isOverDropsite = false;
    }
Esempio n. 2
0
 public void OnEndDrag(PointerEventData eventData)
 {
     _image.enabled = true;
     _currentDraggedTile.Drop();
     _currentDraggedTile = null;
 }