Example #1
0
    //开始触摸
    private void OnTouchBegin(EventContext context)
    {
        Debug.Log("OnTouchBegin");
        if (touchID == -1)//第一次触摸
        {
            InputEvent inputEvent = (InputEvent)context.data;
            touchID = inputEvent.touchId;

            if (tweener != null)
            {
                tweener.Kill();//杀死上一个动画
                tweener = null;
            }


            Vector2 localPos = m_ui.GlobalToLocal(inputEvent.position);


            lastStagePos  = localPos;
            startStagePos = localPos;


            center.visible = true;
            thumb.visible  = true;
            center.SetXY(localPos.x, localPos.y);
            thumb.SetXY(localPos.x, localPos.y);
            context.CaptureTouch();
            onDown.Call(1);
            m_IsMoved = false;
        }
    }
Example #2
0
    public void TimerUpdate()
    {
        //Debug.Log("----------TimerUpdate111-:" + moveEventContext);
        if (moveEventContext != null)
        {
            //Debug.Log("----------TimerUpdate222-:"+ moveEventContext);
            //var context = moveEventContext;
            InputEvent inputEvent = moveEventContext;// (InputEvent)context.data;
            if (touchID != -1 && inputEvent.touchId == touchID)
            {
                //Vector2 localPos = GRoot.inst.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
                Vector2 localPos = m_ui.GlobalToLocal(inputEvent.position);

                var dir = (localPos - startStagePos);
                //点击到 取消施法
                if (Vector2.Distance(localPos, no.xy) < 40)
                {
                    no.scale             = new Vector2(1.5f, 1.5f);
                    no.asTextField.color = new Color(1, 0, 0);
                    isNo = true;
                    center.asImage.color = new Color(1, 0, 0);
                }
                else
                {
                    no.scale             = new Vector2(1.0f, 1.0f);
                    no.asTextField.color = new Color(1, 1, 1);
                    isNo = false;
                    center.asImage.color = new Color(1, 1, 1);
                }
                //点击到 施法自己
                if (showmy)
                {
                    if (Vector2.Distance(localPos, my.xy) < 40)
                    {
                        my.scale             = new Vector2(1.5f, 1.5f);
                        my.asTextField.color = new Color(0, 0, 1);
                        isMy = true;

                        center.asImage.color = new Color(0, 0, 1);
                    }
                    else
                    {
                        my.scale             = new Vector2(1.0f, 1.0f);
                        my.asTextField.color = new Color(1, 1, 1);
                        isMy = false;
                        center.asImage.color = new Color(1, 1, 1);
                    }
                }


                var len = Vector2.Distance(dir, new Vector2(0, 0));
                if (len > radius)
                {
                    //len = radius;
                }
                var dest = dir.normalized * len + startStagePos;


                thumb.SetXY(dest.x, dest.y);

                thumb.rotation = Vector2.SignedAngle(new Vector2(0, -1), dir);

                if (len >= m_MoveCallNeedDir)
                {
                    m_IsMoved = true;
                }

                if (m_IsMoved == false)
                {
                    //详情
                    if (IsShowInfo == false && Tool.GetTime() - TouchBeginTime >= 2)
                    {
                        isNo = true;
                        DoTouchEnd(dir, len / radius, isNo, isMy);

                        IsShowInfo = true;
                        GComponent info = Tool.CreateTouchShowInfo();

                        m_ui.asCom.AddChild(info);

                        var clientskill = ExcelManager.Instance.GetSkillManager().GetSkillByID(m_SkillDatas.TypeID);
                        if (clientskill != null)
                        {
                            if (clientskill.IconPath.Length > 0)
                            {
                                info.GetChild("icon").asLoader.url = clientskill.IconPath;
                            }
                            info.GetChild("name").asTextField.text = clientskill.Name;
                            info.GetChild("des").asTextField.text  = clientskill.Des;
                        }
                        info.SetXY(localPos.x - 100, localPos.y - 50);
                    }
                    //
                }

                if (IsShowInfo == true)
                {
                    GComponent info = Tool.CreateTouchShowInfo();
                    info.SetXY(localPos.x - 100, localPos.y - 50);
                    isNo = true;
                    return;
                    //no.scale = new Vector2(1.5f, 1.5f);
                    //no.asTextField.color = new Color(1, 0, 0);
                    //isNo = true;
                    //center.asImage.color = new Color(1, 0, 0);
                }

                if (m_IsMoved)
                {
                    //onMove.Call(dir);


                    if (len > radius)
                    {
                        startStagePos += dir.normalized * (len - radius);
                        center.SetXY(startStagePos.x, startStagePos.y);
                        DoTouchMove(dir, 1);
                    }
                    else
                    {
                        DoTouchMove(dir, len / radius);
                    }
                }
            }
        }
    }
Example #3
0
 /// <summary>
 /// 全局坐标转本地坐标
 /// </summary>
 /// <param name="go"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 public static Vector2 GlobalToLocal(GObject go, float x, float y)
 {
     return(go.GlobalToLocal(new Vector2(x, y)));
 }