Exemple #1
0
    public IEnumerator OnDragRoutine(PointerEventData eventData)
    {
        dragging = true;
        if (eventData.position.y > lowPos.y && eventData.position.y < highPos.y)
        {
            Vector3 deltaPos = new Vector3(ogPos.x, eventData.position.y, ogPos.z);
            transform.position = deltaPos;

            if (deltaPos.y > upperSibling.position.y && !upperIsDefault)
            {
                yield return(StartCoroutine(smoothMove(0.01f, ogPos, upperSibling)));

                scroll.swapObjects(gameObject, upperSibling.gameObject);
                transform.SetSiblingIndex(upperSibling.GetSiblingIndex());
                LayoutRebuilder.ForceRebuildLayoutImmediate(scrollContent.GetComponent <RectTransform>());
                updateState();
            }
            else if (deltaPos.y < lowerSibling.position.y && !lowerIsDefault)
            {
                yield return(StartCoroutine(smoothMove(0.01f, ogPos, lowerSibling)));

                scroll.swapObjects(gameObject, lowerSibling.gameObject);
                transform.SetSiblingIndex(lowerSibling.GetSiblingIndex());
                LayoutRebuilder.ForceRebuildLayoutImmediate(scrollContent.GetComponent <RectTransform>());
                updateState();
            }

            if (!scrolling)
            {
                if (deltaPos.y >= highPos.y - 100 && upPossible)
                {
                    StartCoroutine(scrollRoutine());
                }
                else if (deltaPos.y <= lowPos.y + 100 && downPossible)
                {
                    StartCoroutine(scrollRoutine(false));
                }
            }
        }

        dragging = false;
    }