示例#1
0
    private void ResetJoystick()
    {
        m_widget_joystick.alpha = 0.5f;
        m_widget_joystick.gameObject.transform.localPosition        = m_trans_joystickPos.localPosition;
        m_sprite_joystickThumb.transform.localPosition              = Vector3.zero;
        m_sprite_joystickBg.transform.localPosition                 = Vector3.zero;
        m_sprite_joystickThumb.GetComponent <BoxCollider>().enabled = false;

        Client.IControllerSystem controllerSys = Client.ClientGlobal.Instance().GetControllerSystem();
        if (controllerSys != null)
        {
            Client.IController ctrl = controllerSys.GetActiveCtrl();
            if (ctrl != null)
            {
                ctrl.OnMessage(Engine.MessageCode.MessageCode_JoystickEnd);
            }
        }
        Engine.Utility.EventEngine.Instance().DispatchEvent((int)(int)Client.GameEventID.JOYSTICK_UNPRESS, null);
        if (MainPlayerHelper.GetMainPlayer() != null)
        {
            ISkillPart part = MainPlayerHelper.GetMainPlayer().GetPart(EntityPart.Skill) as ISkillPart;
            if (part != null)
            {
                int st = part.GetCurSkillState();
                if (st == (int)SkillState.None || st == (int)SkillState.Prepare)
                {
                    stForbiddenJoystick info = new stForbiddenJoystick();
                    info.playerID  = MainPlayerHelper.GetPlayerUID();
                    info.bFobidden = false;
                    EventEngine.Instance().DispatchEvent((int)GameEventID.SKILL_FORBIDDENJOYSTICK, info);
                }
            }
        }
    }
示例#2
0
    private void OnThumbDrag(GameObject obj, Vector2 delta)
    {
        if (m_bIgnore)
        {
            return;
        }


        if (MainPlayerHelper.GetMainPlayer().IsDead())
        {
            return;
        }

        Vector2 touchPos = UICamera.currentTouch.pos;

        float fDis = Vector2.Distance(m_LastJoystickBgScreenPos, touchPos);

        if (m_bJoystickStable)
        {
            Vector2 touchDelta2 = touchPos - m_LastJoystickBgScreenPos;
            m_sprite_joystickThumb.transform.position = UICamera.currentCamera.ScreenToWorldPoint(new Vector3(touchPos.x, touchPos.y, 0));
            if (fDis < m_fMaxDis)
            {
                Vector2 pos = m_LastJoystickBgScreenPos + touchDelta2;
                Vector3 pp  = UICamera.currentCamera.ScreenToWorldPoint(new Vector3(pos.x, pos.y, 0));
                m_sprite_joystickThumb.transform.position = new Vector3(pp.x, pp.y, 0);
            }
            else
            {
                Vector2 dt  = touchDelta2.normalized;
                Vector2 pos = m_LastJoystickBgScreenPos + dt * m_fMaxDis;
                Vector3 pp  = UICamera.currentCamera.ScreenToWorldPoint(new Vector3(pos.x, pos.y, 0));
                m_sprite_joystickThumb.transform.position = new Vector3(pp.x, pp.y, 0);
            }
        }
        else
        {
            m_sprite_joystickThumb.transform.position = UICamera.currentCamera.ScreenToWorldPoint(new Vector3(touchPos.x, touchPos.y, 0));
            if (fDis > m_fMaxDis)
            {
                Vector2 dir = (new Vector2(touchPos.x, touchPos.y) - m_LastJoystickBgScreenPos).normalized;

                Vector2 pos = dir * (fDis - m_fMaxDis);

                m_LastJoystickBgScreenPos += pos;

                m_sprite_joystickBg.transform.position = UICamera.currentCamera.ScreenToWorldPoint(new Vector3(m_LastJoystickBgScreenPos.x, m_LastJoystickBgScreenPos.y, 0));
            }
        }

        m_LastTouchPos = touchPos;
        //if (m_bSkillLongPress)
        //{
        //    return;
        //}

        if (fDis < 10)
        {
            return;
        }
        Vector2 touchDelta = touchPos - m_LastJoystickBgScreenPos;

        // 根据 touchDelta 计算角度 垂直向上
        float fAngle = Vector2.Angle(Vector2.up, touchDelta);

        if (touchDelta.x < 0)
        {
            fAngle = -fAngle;
        }
        fAngle += CameraFollow.Instance.YAngle;
        Client.IControllerSystem controllerSys = Client.ClientGlobal.Instance().GetControllerSystem();
        if (controllerSys != null)
        {
            Client.IController ctrl = controllerSys.GetActiveCtrl();
            if (ctrl != null)
            {
                ctrl.OnMessage(Engine.MessageCode.MessageCode_JoystickChanging, (object)fAngle);
                if (m_bSkillLongPress)
                {
                    //点击摇杆 解除长按
                    Controller.CmdManager.Instance().Clear();
                    stSkillLongPress longPress = new stSkillLongPress();
                    longPress.bLongPress = false;
                    EventEngine.Instance().DispatchEvent((int)GameEventID.SKLL_LONGPRESS, longPress);
                }
            }
        }
    }