Beispiel #1
0
    public void OnEndDrag(PointerEventData eventData)
    {
        if (!CanDrag)
        {
            return;
        }

        var results = new List <RaycastResult>();

        EventSystem.current.RaycastAll(eventData, results);

        DropArea dropArea = null;

        foreach (var result in results)
        {
            dropArea = result.gameObject.GetComponent <DropArea>();

            if (dropArea != null)
            {
                break;
            }
        }

        if (dropArea != null)
        {
            if (dropArea.Accepts(this))
            {
                SetIndex(dropArea.name);
                if (dropArea.GetComponentInChildren <SetItemIcon>() != null)
                {
                    GameObject temp = dropArea.GetComponentInChildren <SetItemIcon>().gameObject;
                    temp.transform.SetParent(parentToRenturnTo);
                    temp.transform.SetSiblingIndex(this.positionIndex);
                    equipmentPanel.UnEquipItem(temp.GetComponent <SetItemIcon>().GetItem, index);
                }
                dropArea.Drop(this);
                OnEndDragHandler?.Invoke(eventData, true);
                transform.SetParent(dropArea.transform);
                equipmentPanel.EquipItem(item, index, positionIndex);

                return;
            }
        }
        if (eventData.position.x > halfScreen && startingPosition < halfScreen)
        {
            equipmentPanel.UnEquipItem(item, index);

            this.transform.SetParent(inventoryPosition);
            rectTransform.anchoredPosition = StartPosition;
            OnEndDragHandler?.Invoke(eventData, false);
            return;
        }

        this.transform.SetParent(parentToRenturnTo);
        rectTransform.anchoredPosition = StartPosition;
        //transform.SetSiblingIndex(positionIndex);
        //equipmentPanel.UnEquipItem(item, index);
        OnEndDragHandler?.Invoke(eventData, false);
    }
Beispiel #2
0
    public void Remove()
    {
        if (onDrag != null)
        {
            onDrag.RemoveAllListeners();
            onDrag = null;
        }

        if (onBeginDrag != null)
        {
            onBeginDrag.RemoveAllListeners();
            onBeginDrag = null;
        }
        if (onEndDrag != null)
        {
            onEndDrag.RemoveAllListeners();
            onEndDrag = null;
        }
    }
    public void OnEndDrag(PointerEventData eventData)
    {
        mineblock.isAbleToAction = true;


        if (!CanDrag)
        {
            return;
        }

        var results = new List <RaycastResult>();

        EventSystem.current.RaycastAll(eventData, results);

        DropArea dropArea = null;

        foreach (var result in results)
        {
            dropArea = result.gameObject.GetComponent <DropArea>();

            if (dropArea != null)
            {
                break;
            }
        }

        if (dropArea != null && dropArea.transform.childCount < 1)
        {
            if (dropArea.Accepts(this))
            {
                dropArea.Drop(this);
                OnEndDragHandler?.Invoke(eventData, true);
                transform.parent = dropArea.transform;
                return;
            }
        }

        rectTransform.anchoredPosition = StartPosition;
        OnEndDragHandler?.Invoke(eventData, false);
    }
    public void OnEndDrag(PointerEventData eventData)
    {
        if (!CanDrag)
        {
            return;
        }

        var results = new List <RaycastResult>();

        EventSystem.current.RaycastAll(eventData, results);

        DropArea slot = null;

        foreach (var result in results)
        {
            slot = result.gameObject.GetComponent <DropArea>();

            if (slot != null)
            {
                break;
            }
        }

        if (slot != null)
        {
            if (slot.Accepts(this))
            {
                slot.Drop(this);
                OnEndDragHandler?.Invoke(eventData, true);
                return;
            }
        }
        _rectTransfrom.transform.SetParent(currentParent); // revert back to old parent
        _rectTransfrom.anchoredPosition = _startPos;



        OnEndDragHandler?.Invoke(eventData, false);
    }
Beispiel #5
0
    public void OnEndDrag(PointerEventData eventData)
    {
        if (!canDrag)
        {
            return;
        }

        canvasGroup.alpha          = 1f;
        canvasGroup.blocksRaycasts = true;

        OnEndDragHandler?.Invoke(eventData, false);
        leftBeingHeld = false;

        var results = new List <RaycastResult>();

        EventSystem.current.RaycastAll(eventData, results);
        CandiArea dropArea = null;

        foreach (var result in results)
        {
            dropArea = result.gameObject.GetComponent <CandiArea>();
            if (dropArea != null)
            {
                break;
            }
        }

        if (dropArea != null && dropArea.Accepts(this))
        {
            int TransformX = (int)rigidbody2D.rotation;
            if (TransformX < 0)
            {
                TransformX = (TransformX - 45) / 90 * 90;
            }
            else
            {
                TransformX = (TransformX + 45) / 90 * 90;
            }

            transform.SetPositionAndRotation(transform.position, Quaternion.Euler(0, 0, TransformX));

            if (Mathf.Abs(TransformX) / 90 % 2 == 1)
            {
                horizontalState = false;
            }
            else
            {
                horizontalState = true;
            }

            int lastTotalCandi = GuideLine.totalCandi;
            dropArea.Drop(this);
            OnEndDragHandler?.Invoke(eventData, true);

            if (lastTotalCandi != GuideLine.totalCandi)
            {
                rigidbody2D.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Static;
                canDrag = false;
                StartCoroutine(CandiPlaced());
                return;
            }
        }
        rigidbody2D.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
        rigidbody2D.gravityScale = 150f;
    }