コード例 #1
0
    IEnumerator ScrollFunc()
    {
        while (isPointerEntered)
        {
            while (isPointerEntered && Input.GetMouseButtonDown(0) == false)
            {
                yield return(null);
            }

            TableViewCell cell               = null;
            var           delta              = Vector2.zero;
            var           downPosition       = Input.mousePosition;
            var           originalTableViewY = positionY;
            var           results            = new List <RaycastResult>();
            raycaster.Raycast(new PointerEventData(EventSystem.current)
            {
                position = Input.mousePosition
            }, results);

            if (results.Count == 0)
            {
                continue;
            }

            var tr = results[0].gameObject.transform;
            while (tr.parent != null)
            {
                cell = tr.GetComponent <TableViewCell>();
                if (cell != null)
                {
                    break;
                }
                tr = tr.parent;
            }

            if (cell == null)
            {
                continue;
            }

            while (isPointerEntered && Input.GetMouseButton(0))
            {
                delta = Input.mousePosition - downPosition;

                if (delta.y < -10)
                {
                    cell.rt.pivot = new Vector2(cell.rt.pivot.x, 1);
                }
                else if (delta.y > 10)
                {
                    cell.rt.pivot = new Vector2(cell.rt.pivot.x, 0);
                }

                if (delta.y > 150)
                {
                    if (ScrollDown())
                    {
                        //yield return new WaitForSeconds(1.0f / 60 * 11);
                        cell.ScaleTo(5, Vector3.one, Easing.SineOut);
                        break;
                    }
                    else
                    {
                        break;
                    }
                }
                else if (delta.y < -150)
                {
                    if (ScrollUp())
                    {
                        //yield return new WaitForSeconds(1.0f / 60 * 11);
                        cell.ScaleTo(5, Vector3.one, Easing.SineOut);
                        break;
                    }
                    else
                    {
                        break;
                    }
                }

                if (delta.y > 0 && cell.index != 0)
                {
                    GetCell(cell.index - 1).transform.localScale = new Vector3(1, 1 - Mathf.Clamp(Mathf.Abs(delta.y / 1000), 0, 0.3f), 1);
                }
                cell.transform.localScale = new Vector3(1, 1 + Mathf.Clamp(Mathf.Abs(delta.y / 1000), 0, 0.3f), 1);

                yield return(null);
            }

            if (Mathf.Abs(delta.magnitude) <= 10)
            {
                cell.gameObject.SendMessage("OnClickCell", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                if (cell.index != 0)
                {
                    GetCell(cell.index - 1).ScaleTo(5, Vector3.one, Easing.SineOut);
                }
                if (cell.rt.pivot.y == 1)
                {
                    yield return(cell.ScaleTo(25, Vector3.one, Easing.SineOut));
                }
                else
                {
                    yield return(cell.ScaleTo(5, Vector3.one, Easing.SineOut));
                }

                while (isPointerEntered && Input.GetMouseButton(0))
                {
                    yield return(null);
                }
            }
        }
    }