コード例 #1
0
    /// <summary>
    /// 执行导航
    /// </summary>
    /// <param name="clickKey"></param>
    private void DoNavigation(E_ClickKey clickKey)
    {
        switch (clickKey)
        {
        case E_ClickKey.Up:
            if (UpSelectedObj)
            {
                UIController.instance.CurrentSelectedObj = UpSelectedObj;
            }
            break;

        case E_ClickKey.Down:
            if (DownSelectedObj)
            {
                UIController.instance.CurrentSelectedObj = DownSelectedObj;
            }
            break;

        case E_ClickKey.Left:
            if (LeftSelectedObj)
            {
                UIController.instance.CurrentSelectedObj = LeftSelectedObj;
            }
            break;

        case E_ClickKey.Right:
            if (RightSelectedObj)
            {
                UIController.instance.CurrentSelectedObj = RightSelectedObj;
            }
            break;
        }
    }
コード例 #2
0
    private void OnKeyDown(E_ClickKey clickKey)
    {
        //焦点出了列表
        if (!_currentSelectedItemBase || _currentSelectedItemBase.gameObject != UIController.instance.CurrentSelectedObj)
        {
            return;
        }

        //如果正在移动,return!!!
        if (_isMoving)
        {
            return;
        }
        //1、检查是否是执行导航操作
        if (CheckNavigation(clickKey))
        {
            DoNavigation(clickKey);
            return;
        }
        //2、检查是否可以移动
        if (CheckMove(clickKey))
        {
            //移动界面
            DoPageTransMove(clickKey);
        }
    }
コード例 #3
0
    /// <summary>
    /// 检查是否执行导航
    /// </summary>
    /// <param name="clickKey"></param>
    /// <returns></returns>
    private bool CheckNavigation(E_ClickKey clickKey)
    {
        if (_isMoving)
        {
            return(false);
        }
        int firstPage = 0;

        if (clickKey == E_ClickKey.Up)
        {
            if (Direction == E_Direct.Vertical && UpSelectedObj && _currentPageData.Page == firstPage && CheckIsTheFirstItemOfTheList(_currentSelectedItemBase))
            {
                return(true);
            }

            if (Direction == E_Direct.Horizontal && UpSelectedObj)
            {
                return(true);
            }
        }
        else if (clickKey == E_ClickKey.Down)
        {
            if (DownSelectedObj && Direction == E_Direct.Vertical && _currentPageData.Page == MaxPage && CheckIsTheLastItemOfTheList(_currentSelectedItemBase))
            {
                return(true);
            }

            if (DownSelectedObj && Direction == E_Direct.Horizontal)
            {
                return(true);
            }
        }
        else if (clickKey == E_ClickKey.Left)
        {
            if (LeftSelectedObj && Direction == E_Direct.Horizontal && _currentPageData.Page == firstPage && CheckIsTheFirstItemOfTheList(_currentSelectedItemBase))
            {
                return(true);
            }

            if (LeftSelectedObj && Direction == E_Direct.Vertical)
            {
                return(true);
            }
        }
        else if (clickKey == E_ClickKey.Right)
        {
            if (RightSelectedObj && Direction == E_Direct.Horizontal && _currentPageData.Page == MaxPage && CheckIsTheLastItemOfTheList(_currentSelectedItemBase))
            {
                return(true);
            }

            if (RightSelectedObj && Direction == E_Direct.Vertical)
            {
                return(true);
            }
        }
        return(false);
    }
コード例 #4
0
    /// <summary>
    /// 检查按下按键后,列表是否可以移动
    /// </summary>
    /// <param name="clickKey"></param>
    /// <returns></returns>
    private bool CheckMove(E_ClickKey clickKey)
    {
        //        Debug.Log("clickKey = " + clickKey);
        if (_isMoving)
        {
            return(false);
        }

        //1、是否到达底部
        CheckBottom(clickKey);

        //2、移动方向是否正确
        //点击上键或者左键
        if ((clickKey == E_ClickKey.Up || clickKey == E_ClickKey.Down) && Direction == E_Direct.Horizontal)
        {
            //如果方向不对,则不能移动
            return(false);
        }
        //点击下键或者右键
        if ((clickKey == E_ClickKey.Left || clickKey == E_ClickKey.Right) && Direction == E_Direct.Vertical)
        {
            return(false);
        }

        //3、是否满足当页可翻页条件
        if (clickKey == E_ClickKey.Up || clickKey == E_ClickKey.Left)
        {
            //1、如果当前的page已经是最上的一页,则不能移动
            if (_currentPageData.Page == 0)
            {
                return(false);
            }
            //2、如果选中的item不是page下的第一个item,则不能移动
            if (!CheckIsTheFirstItemOfThePage(_currentSelectedItemBase))
            {
                return(false);
            }
        }
        else if (clickKey == E_ClickKey.Down || clickKey == E_ClickKey.Right)
        {
            bool isLastItem = CheckIsTheLastItemOfThePage(_currentSelectedItemBase);
            //1、如果当前的page已经是最上的一页,则不能移动
            if (_currentPageData.Page == MaxPage)
            {
                return(false);
            }
            //2、如果选中的item不是page下的最后一个item,则不能移动
            if (!isLastItem)
            {
                return(false);
            }
        }

        return(true);
    }
コード例 #5
0
 private void LoadNewPageData(E_ClickKey clickKey)
 {
     //逆序翻页
     if (clickKey == E_ClickKey.Up || clickKey == E_ClickKey.Left)
     {
         SetCurrentPageData(false);
     }
     //顺序翻页
     else if (clickKey == E_ClickKey.Down || clickKey == E_ClickKey.Right)
     {
         SetCurrentPageData(true);
     }
 }
コード例 #6
0
 private void CheckBottom(E_ClickKey clickKey)
 {
     if (clickKey == E_ClickKey.Down || clickKey == E_ClickKey.Right)
     {
         bool isLastItem  = CheckIsTheLastItemOfThePage(_currentSelectedItemBase);
         int  currentPage = _currentPageData.Page;
         if (currentPage == MaxPage && isLastItem)
         {
             Debug.Log("到达底部!");
             if (HandleBottom != null)
             {
                 HandleBottom();
             }
         }
     }
 }
コード例 #7
0
    /// <summary>
    /// 执行翻页动画
    /// </summary>
    /// <param name="clickKey"></param>
    private void DoPageTransMove(E_ClickKey clickKey)
    {
        //加载新界面数据
        LoadNewPageData(clickKey);

        Transform currentPageItem  = GetTheOtherPageTrans(_currentPageData.Trans);
        Transform theOtherPageItem = _currentPageData.Trans;

        Vector3 theOtherStartPos  = default(Vector3);
        Vector3 theOtherTargetPos = CenterPosition;

        Vector3 curStartPos  = CenterPosition;
        Vector3 curTargetPos = default(Vector3);

        Vector2 pageSize = PageTrans.GetComponent <RectTransform>().sizeDelta;

        switch (clickKey)
        {
        case E_ClickKey.Up:
            theOtherStartPos = new Vector3(0f, pageSize.y);
            curTargetPos     = new Vector3(0f, -pageSize.y);
            break;

        case E_ClickKey.Down:
            theOtherStartPos = new Vector3(0f, -pageSize.y);
            curTargetPos     = new Vector3(0f, pageSize.y);
            break;

        case E_ClickKey.Left:
            theOtherStartPos = new Vector3(-pageSize.x, 0f);
            curTargetPos     = new Vector3(pageSize.x, 0f);
            break;

        case E_ClickKey.Right:
            theOtherStartPos = new Vector3(pageSize.x, 0f);
            curTargetPos     = new Vector3(-pageSize.x, 0f);
            break;
        }

        currentPageItem.localPosition  = curStartPos;
        theOtherPageItem.localPosition = theOtherStartPos;

        _isMoving = true;
        if (HandleMove != null)
        {
            HandleMove();
        }
        EnablePageItemBtn(currentPageItem, false);
        //        Debug.Log(currentPageItem.localPosition + "  " + curTargetPos);
        //        Debug.Log(theOtherPageItem.localPosition + "  " + theOtherTargetPos);
        DoTweenHelper.DoLocalMove(currentPageItem, curTargetPos, 0.5f, EaseType, () =>
        {
            EnablePageItemBtn(currentPageItem, true);
        });
        DoTweenHelper.DoLocalMove(theOtherPageItem, theOtherTargetPos, 0.5f, EaseType, () =>
        {
            _isMoving = false;
            if (HandleMoveComplete != null)
            {
                HandleMoveComplete();
            }
            if (clickKey == E_ClickKey.Up || clickKey == E_ClickKey.Left)
            {
                for (int i = theOtherPageItem.childCount - 1; i >= 0; i--)
                {
                    var item = theOtherPageItem.GetChild(i).gameObject;
                    if (item.activeSelf)
                    {
                        UIController.instance.CurrentSelectedObj = item;
                        break;
                    }
                }
            }
            else if (clickKey == E_ClickKey.Down || clickKey == E_ClickKey.Right)
            {
                UIController.instance.CurrentSelectedObj = theOtherPageItem.GetChild(0).gameObject;
            }
        });
    }