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
    //开始触摸
    private void OnTouchBegin(EventContext evenContext)
    {
        if (touchID == -1)//第一次触摸
        {
            InputEvent inputEvent = (InputEvent)evenContext.data;
            touchID = inputEvent.touchId;
            if (tweener != null)
            {
                tweener.Kill();//终止上一个动效
                tweener = null;
            }
            Vector2 localPos = GRoot.inst.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
            float   posX     = localPos.x;
            float   posY     = localPos.y;
            joystickButton.selected = true;

            lastStageX  = posX;
            lastStageY  = posY;
            startStageX = posX;
            startStageY = posY;

            joystickCenter.visible = true;
            joystickCenter.SetXY(posX - joystickCenter.width / 2, posY - joystickCenter.height / 2);
            joystickButton.SetXY(posX - joystickButton.width / 2, posY - joystickButton.height / 2);

            evenContext.CaptureTouch();
        }
    }
Example #3
0
        private void OnTouchBegin(EventContext context)
        {
            if (m_touchId == -1)//First touch
            {
                InputEvent inputEvt = (InputEvent)context.data;
                m_touchId = inputEvt.touchId;

                m_controller.selectedIndex = 0;

                if (m_tweener != null)
                {
                    m_tweener.Kill();
                    m_tweener = null;
                }

                Vector2 pt = GRoot.inst.GlobalToLocal(new Vector2(inputEvt.x, inputEvt.y));
                float   bx = pt.x;
                float   by = pt.y;
                m_button.selected = true;

                if (bx < 0)
                {
                    bx = 0;
                }
                else if (bx > m_touchArea.width)
                {
                    bx = m_touchArea.width;
                }

                if (by > GRoot.inst.height)
                {
                    by = GRoot.inst.height;
                }
                else if (by < m_touchArea.y)
                {
                    by = m_touchArea.y;
                }

                m_lastStageX  = bx;
                m_lastStageY  = by;
                m_startStageX = bx;
                m_startStageY = by;

                m_center.visible = true;
                m_center.SetXY(bx - m_center.width / 2, by - m_center.height / 2);
                m_button.SetXY(bx - m_button.width / 2, by - m_button.height / 2);

                float deltaX  = bx - m_InitX;
                float deltaY  = by - m_InitY;
                float degrees = Mathf.Atan2(deltaY, deltaX) * 180 / Mathf.PI;
                //_thumb.rotation = degrees + 90;

                context.CaptureTouch();
            }
        }
Example #4
0
    private void OnTouchBegin(EventContext context)
    {
        if (touchId == -1)        //First touch
        {
            Debug.Log(1);
            InputEvent evt = (InputEvent)context.data;
            touchId = evt.touchId;

            if (_tweener != null)
            {
                _tweener.Kill();
                _tweener = null;
            }

            Vector2 pt = GRoot.inst.GlobalToLocal(new Vector2(evt.x, evt.y));
            float   bx = pt.x;
            float   by = pt.y;
            _button.selected = true;

            if (bx < 0)
            {
                bx = 0;
            }
            else if (bx > _touchArea.width)
            {
                bx = _touchArea.width;
            }

            if (by > GRoot.inst.height)
            {
                by = GRoot.inst.height;
            }
            else if (by < _touchArea.y)
            {
                by = _touchArea.y;
            }

            _lastStageX  = bx;
            _lastStageY  = by;
            _startStageX = bx;
            _startStageY = by;

            _center.visible = true;
            _center.SetXY(bx - _center.width / 2, by - _center.height / 2);
            _button.SetXY(bx - _button.width / 2, by - _button.height / 2);

            float deltaX  = bx - _InitX;
            float deltaY  = by - _InitY;
            float degrees = Mathf.Atan2(deltaY, deltaX) * 180 / Mathf.PI;
            _thumb.rotation = degrees + 90;

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

            if (tweener != null)
            {
                tweener.Kill();//杀死上一个动画
                tweener = null;
            }
            //将世界坐标转化为FGUI坐标
            Vector2 localPos = GRoot.inst.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
            float   posX     = localPos.x;
            float   posY     = localPos.y;
            //注意此处为单选按钮,需要设置单选属性 选中设为true
            joystickButton.selected = true;

            lastStageX  = posX;
            lastStageY  = posY;
            startStageX = posX;
            startStageY = posY;
            //设置新的摇杆按钮与中心位置
            center.visible = true;
            center.SetXY(posX - center.width / 2, posY - center.height / 2);
            joystickButton.SetXY(posX - joystickButton.width / 2, posY - joystickButton.height / 2);

            float deltaX = posX - initX;
            float deltay = posY - initY;
            //计算旋转角度
            float degrees = Mathf.Atan2(deltay, deltaX) * 180 / Mathf.PI;
            thumb.rotation = degrees + 90;
            //上下文获取触摸状态
            context.CaptureTouch();
        }
    }
Example #6
0
    //开始触摸
    private void OnTouchBegin(EventContext context)
    {
        Debug.Log("OnTouchBegin");
        if (touchID == -1)//第一次触摸
        {
            InputEvent inputEvent = (InputEvent)context.data;
            moveEventContext = (InputEvent)context.data;
            touchID          = inputEvent.touchId;

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

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


            lastStagePos   = localPos;
            startStagePos  = localPos;
            TouchBeginTime = Tool.GetTime();

            no.SetXY(localPos.x + nopos.x, localPos.y + nopos.y);
            my.SetXY(localPos.x + mypos.x, localPos.y + mypos.y);
            no.visible = true;
            if (showmy)
            {
                my.visible = true;
            }
            //private GObject no;showmy
            //public Vector2 nopos = new Vector2(120, -200);


            center.visible = true;
            thumb.visible  = true;
            center.SetXY(localPos.x, localPos.y);
            thumb.SetXY(localPos.x, localPos.y);
            context.CaptureTouch();
            //onDown.Call(1);
            DoTouchDown(localPos);
            m_IsMoved = false;
        }
    }
Example #7
0
 public void Result(Vector3 startPos, Vector3 endPos, float t)
 {
     if (t > 1)
     {
         t = 1;
         if (callBack != null)
         {
             callBack();
             callBack = null;
         }
         flag = false;
         return;
     }
     posCache = (1 - t) * (1 - t) * startPos + 2 * t * (1 - t) * center + t * t * endPos;
     owner.SetXY(posCache.x, posCache.y);
     if (roFlag == true)
     {
         ro();
     }
 }
Example #8
0
    private void OnTouchEnd(EventContext context)
    {
        InputEvent inputEvt = (InputEvent)context.data;

        if (touchId != -1 && inputEvt.touchId == touchId)
        {
            touchId         = -1;
            _thumb.rotation = _thumb.rotation + 180;
            //_center.visible = false;
            _tweener = _joystick_button.TweenMove(new Vector2(_InitX - _joystick_button.width / 2, _InitY - _joystick_button.height / 2), 0.3f).OnComplete(() =>
            {
                _tweener        = null;
                _thumb.visible  = true;
                _thumb.rotation = 0;
                //_center.visible = true;
                _joystick_button.visible = false;
                _center.SetXY(_InitX - _center.width / 2, _InitY - _center.height / 2);
            }
                                                                                                                                                           );

            this.onEnd.Call();
        }
    }
Example #9
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 #10
0
 private void SetCenterPosXY(GObject obj, Vector2 pos)
 {
     obj.SetXY(pos.x - obj.width / 2, pos.y - obj.height / 2);
 }