Example #1
0
    void Update()
    {
        if (Input.touchCount > 0)
        {
            touchPoint   = Input.GetTouch(0);
            getTouchType = TouchEvent.tEvent(touchPoint, ref pressTime);
            switch (getTouchType)
            {
                #region drop
            case touchType.drop:
                MenuTitle.text = "drop";
                if (iconMoveT < 1 && iconMoveT > 0)
                {
                    hotBoxIconMove = true;    //允许插值;
                }

                if (SelectionIcon != null)
                {
                    SelectionIcon.rectTransform.localScale = oneScale;
                }

                hotBoxTagPosition = hotboxTarget.rectTransform.anchoredPosition = screenScale.V2Multi(touchPoint.position - Halfscreen);

                HotBoxDistanceList.Sort
                (
                    (HotBoxIconData i1, HotBoxIconData i2) =>
                {
                    return(Vector2.Distance(i1.position, hotBoxTagPosition).CompareTo(Vector2.Distance(i2.position, hotBoxTagPosition)));
                }
                );                                                                                                      //根据每个图标距离手指位置排序
                SelectionIcon = NowHotBoxIconList.Find((Image i) => { return(i.name == HotBoxDistanceList[0].name); }); //找出排序后在列表上第一个的对象

                if (SelectionIcon != null)
                {
                    SelectionIcon.rectTransform.localScale = oneFiveScale;         //放大图标
                }

                break;

                #endregion
                #region longpress
            case touchType.longpress:
                MenuTitle.text = "longpress";
                isHotMenuClose = false;     //设置热盒菜单为未关闭状态
                if (HotBoxDistanceList.Count > 0)
                {
                    HotBoxDistanceList.Clear();
                }

                for (int i = 0; i < NowHotBoxIconList.Count; i++)       //激活全部菜单图标
                {
                    NowHotBoxIconList[i].gameObject.SetActive(true);
                }

                hotBoxTagPosition = hotBoxCenterPosition = screenScale.V2Multi(touchPoint.rawPosition - Halfscreen); //设置中心点位置
                hotboxCenter.rectTransform.anchoredPosition = hotBoxCenterPosition;                                  //将中心点摆到对应位置

                if (hotBoxCenterPosition.x > 0)                                                                      //判断左右
                {
                    isRight = true;
                }
                else
                {
                    isRight = false;
                }

                setNowHotBoxList(ProgramData.instance.NowPage, hotBoxTagPosition, isRight); //设置当前页面的热盒图标位置

                for (int i = 0; i < NowHotBoxIconList.Count; i++)                           //把当前每一个图标的名字与位置数据存入列表用于比较
                {
                    HotBoxDistanceList.Add(new HotBoxIconData(NowHotBoxIconList[i].name, NowHotBoxIconTargetPositionList[i]));
                }

                hotBoxIconMove = true; //允许插值;
                isOut          = true; //设置为向外运动

                break;
                #endregion

                #region move
            case touchType.move:
                MenuTitle.text = "Move";
                //if (dropAction != null)
                //{
                //    dropAction();
                //}

                break;
                #endregion

                #region relase
            case touchType.relase:
                MenuTitle.text = "Relase";
                break;

            case touchType.touchend:
                MenuTitle.text = "touchEnd";
                hotboxTarget.rectTransform.anchoredPosition = notUseIconPosition;
                hotboxCenter.rectTransform.anchoredPosition = notUseIconPosition;

                if (SelectionIcon != null)
                {
                    if (SelectionIcon == Icon_Back)
                    {
                        MenuTitle.text = "back";
                    }
                    else
                    {
                        pageType pt = pageType.HotToday;
                        if (SelectionIcon == Icon_HotToday)
                        {
                            pt = pageType.HotToday;
                        }
                        else if (SelectionIcon == Icon_TheNew)
                        {
                            pt = pageType.TheNew;
                        }
                        else if (SelectionIcon == Icon_HotNew)
                        {
                            pt = pageType.HotNew;
                        }
                        else if (SelectionIcon == Icon_WeekList)
                        {
                            pt = pageType.WeekList;
                        }
                        else if (SelectionIcon == Icon_Seach)
                        {
                            pt = pageType.Seach;
                        }
                        ProgramData.instance.NowPage = pt;
                        MenuTitle.text = pt.ToString();
                    }
                }


                hotBoxIconMove = true;  //允许插值;
                isOut          = false; //设置图标状态为收回
                if (HotBoxDistanceList.Count > 0)
                {
                    HotBoxDistanceList.Clear();
                }
                break;
                #endregion
            }
        }
        if (hotBoxIconMove)
        {                                        //当允许被插值的时候则插值
            lerpToPosition(hotBoxTagPosition, ref iconMoveT, isOut);
        }

        //if (iconMoveT <= 0 && isHotMenuClose == false && SelectionIcon != null)//当菜单图标全部被收起同时热盒菜单处于打开状态同时有选中对象的时候
        //{
        //    SelectionIcon.rectTransform.localScale = oneScale;
        //    SelectionIcon.rectTransform.anchoredPosition = notUseIconPosition;
        //    SelectionIcon = null;
        //    isHotMenuClose = true;
        //}
    }