示例#1
0
    /// <summary>
    ///   1 水平左   2  水平右  4,竖直上  3,竖直下
    /// </summary>
    /// <param name="pos"></param>
    /// <returns></returns>
    private byte RejugdeDirect(Vector2 pos, ScollerItemBase tmpCellOne)
    {
        if (Direct == ScollerDirect.Horizontal)
        {
            if (curScolerPos.x < pos.x)
            {
                if (pos.x - curScolerPos.x >= tmpCellOne.GetCellWidth())
                {
                    curScolerPos = pos;
                    return(0);
                }
                curScolerPos = pos;

                return(2);
            }
            else
            {
                if (curScolerPos.x - pos.x >= tmpCellOne.GetCellWidth())
                {
                    curScolerPos = pos;
                    return(0);
                }


                curScolerPos = pos;
                return(1);
            }
        }
        else if (Direct == ScollerDirect.Vertical)
        {
            if (curScolerPos.y <= pos.y)
            {
                if (pos.y - curScolerPos.y >= tmpCellOne.GetCellHeight())
                {
                    curScolerPos = pos;
                    return(0);
                }


                curScolerPos = pos;
                return(3);
            }
            else
            {
                if (curScolerPos.y - pos.y >= tmpCellOne.GetCellHeight())
                {
                    curScolerPos = pos;
                    return(0);
                }



                curScolerPos = pos;
                return(4);
            }
        }

        return(0);
    }
示例#2
0
    public virtual void ExChangeCell(ScollerItemBase toItem, byte direct)
    {
        //向右
        if (direct == 1)
        {
            cellNumber = (sbyte)(toItem.cellNumber - 1);

            cellIndex = toItem.cellIndex - 1;

            float tmpX = toItem.GetTargetPosition().x - GetCellWidth();  //Mathf.Abs(toItem.GetTargetPosition().x) - Mathf.Abs(cellWidth);
            cellTransform.localPosition = new Vector3(tmpX, toItem.GetTargetPosition().y, toItem.GetTargetPosition().z);
        }// 向左
        else if (direct == 2)
        {
            cellNumber = (sbyte)(toItem.cellNumber + 1);



            float tmpX = Mathf.Abs(toItem.GetTargetPosition().x) + Mathf.Abs(toItem.GetCellWidth());
            cellTransform.localPosition = new Vector3(tmpX, toItem.GetTargetPosition().y, toItem.GetTargetPosition().z);

            cellIndex = toItem.cellIndex + 1;
        }
        // 向下拖
        else if (direct == 3)
        {
            cellNumber = (sbyte)(toItem.cellNumber - 1);
            cellIndex  = toItem.cellIndex - 1;


            float tmpY = GetCellHeight(); // Mathf.Abs(toItem.GetTargetPosition().y) - Mathf.Abs(cellHeight);
            cellTransform.localPosition = new Vector3(toItem.GetTargetPosition().x, toItem.GetTargetPosition().y + tmpY, toItem.GetTargetPosition().z);
        }
        // 向上拖
        else if (direct == 4)
        {
            cellNumber = (sbyte)(toItem.cellNumber + 1);

            cellIndex = toItem.cellIndex + 1;

            float tmpY = Mathf.Abs(toItem.GetTargetPosition().y) + Mathf.Abs(toItem.GetCellHeight());
            cellTransform.localPosition = new Vector3(toItem.GetTargetPosition().x, -tmpY, toItem.GetTargetPosition().z);
        }


        targetPos = cellTransform.localPosition;
    }
示例#3
0
    //
    public void FollowFront(ScollerItemBase frontItem)
    {
        Vector3 frontPos = frontItem.GetTargetPosition();



        if (direct == ScollerDirect.Horizontal)
        {
            frontPos.x += frontItem.GetCellWidth();
        }
        else
        {
            frontPos.y -= frontItem.GetCellHeight();
        }

        targetPos = cellTransform.localPosition = frontPos;
    }
示例#4
0
    private void UpdateContent()
    {
        ScollerItemBase tmpItem = FindCell(cellCount - 1);

        // Debug.Log(" last tmpItem.cellIndex== " + tmpItem.cellIndex);

        if (Direct == ScollerDirect.Horizontal)
        {
            float tmpWidth = Mathf.Abs(tmpItem.cellTransform.localPosition.x) + tmpItem.GetCellWidth();

            content.sizeDelta = new Vector2(tmpWidth, content.sizeDelta.y);
        }
        else
        {
            float tmpHeigth = Mathf.Abs(tmpItem.cellTransform.localPosition.y) + tmpItem.GetCellHeight();

            content.sizeDelta = new Vector2(content.sizeDelta.x, tmpHeigth);
        }
    }
示例#5
0
    public void CaculateMovePosition(ScollerItemBase frontItem)
    {
        Vector3 frontPos = frontItem.GetTargetPosition();



        if (direct == ScollerDirect.Horizontal)
        {
            frontPos.x += frontItem.GetCellWidth();
        }
        else
        {
            frontPos.y -= frontItem.GetCellHeight();
        }

        isPlaying = true;


        //UnityEngine.Debug.Log("CaculateMovePosition  isPlaying" + cellIndex);
        animalState = 2;

        targetPos = frontPos;
    }
示例#6
0
    private void ScolerValueChange(Vector2 pos)
    {
        if (!IsPlayingAnimal)
        {
            return;
        }

        RefushCellCount();
        Vector3 contPos = content.InverseTransformPoint(conner);


        ScollerItemBase tmpItem = FindCell(1);

        byte tmpDirect = RejugdeDirect(contPos, tmpItem);



        if (tmpDirect == 0)
        {
            return;
        }



        switch (tmpDirect)
        {
        //    1  水平右
        case 1:
        {
            float tmpFloat = Mathf.Abs(contPos.x - tmpItem.GetTargetPosition().x);


            ScollerItemBase iterm0 = FindCell(0);

            if (tmpFloat >= iterm0.GetCellWidth() * 0.5f && contPos.x < tmpItem.GetTargetPosition().x)
            {
                ExchangeCell(cellCount - 1, 0, tmpDirect);
            }


            // UpdateContent();
        }
        break;

        //2 水平左
        case 2:
        {
            float tmpFloat = Mathf.Abs(tmpItem.GetTargetPosition().x - contPos.x);


            if (tmpFloat >= tmpItem.GetCellWidth() * 0.5f && contPos.x > tmpItem.GetTargetPosition().x)
            {
                ExchangeCell(0, cellCount - 1, tmpDirect);
            }

            //  UpdateContent();
        }
        break;

        // 4,向上拖
        case 4:
        {
            float tmpFloat = Mathf.Abs(tmpItem.GetTargetPosition().y - contPos.y);


            if ((tmpFloat >= tmpItem.GetCellHeight() * 0.5f) && (tmpItem.GetTargetPosition().y > contPos.y))
            {
                ExchangeCell(0, cellCount - 1, tmpDirect);
            }

            //    UpdateContent();
        }
        break;

        //3,向下拖
        case 3:
        {
            float tmpFloat = Mathf.Abs(contPos.y - tmpItem.GetTargetPosition().y);



            ScollerItemBase iterm0 = FindCell(0);
            if (tmpFloat >= iterm0.GetCellHeight() * 0.8f && tmpItem.GetTargetPosition().y < contPos.y)
            {
                ExchangeCell(cellCount - 1, 0, tmpDirect);
            }


            //    UpdateContent();
        }
        break;
        }
    }