Ejemplo n.º 1
0
    public void TouchEnd(STouch touch)
    {
        if (Joystick.FingerID == touch.fingerId)
        {
            if (Joystick.On)
            {
                Joystick.FingerID  = -1;
                Joystick.Direction = Vector3.zero;
                Joystick.Force     = 0;
            }
            GuiManager.Instance.JoystickUp();
            //Debug.Log("Joystick releaed");
            return;
        }

        for (int i = 0; i < Buttons.Length; i++)
        {
            if (Buttons[i].On && touch.fingerId == Buttons[i].FingerId)
            {
                Buttons[i].Status    = E_ButtonStatus.UpFirst;
                Buttons[i].FingerId  = -1;
                Buttons[i].PressTime = -1;

                GuiManager.Instance.ButtonUp((E_ButtonsName)i);
                return;
            }
        }
    }
Ejemplo n.º 2
0
 public void bluetoothAxisUpdate(STouch touch)
 {
     if (Joystick.On && Joystick.FingerID == -1)
     {
         Joystick.FingerID = touch.fingerId;
     }
 }
Ejemplo n.º 3
0
    bool FingerIdInUse(STouch touch)
    {
        if (Joystick.FingerID == touch.fingerId)
        {
            return(true);
        }

        for (int i = 0; i < Buttons.Length; i++)
        {
            if (Buttons[i].On && touch.fingerId == Buttons[i].FingerId)
            {
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 4
0
 public bool IsInsideButton(STouch touch)
 {
     if (useRadius)
     {
         if ((touch.position - Center).magnitude < 0.07f * Screen.width)
         {
             return(true);
         }
     }
     else
     {
         if (touch.position.x > Left && touch.position.x < Left + Width &&
             touch.position.y > Bottom && touch.position.y < Bottom + Height)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 5
0
    public void Update()
    {
        if (IsOn == false)
        {
            return;
        }
        STouch touch = new STouch();

        if (touch.isTouchPlatForm == false)
        {
            if (Input.GetMouseButtonDown(0) == false)
            {
                return;
            }
            touch.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            touch.phase    = TouchPhase.Began;
        }
        else
        {
            if (Input.touchCount == 0)
            {
                return;
            }

            Touch t = Input.GetTouch(0);
            touch.position      = t.position;
            touch.phase         = t.phase;
            touch.deltaPosition = t.deltaPosition;
        }

        if (State == E_State.IngameMenu)
        {
            if (touch.phase == TouchPhase.Began)
            {
                if (touch.position.x > GuiInGameMenu.CScreenLeft && touch.position.x < GuiInGameMenu.CScreenLeft + GuiInGameMenu.CScreenWidth &&
                    touch.position.y > GuiInGameMenu.CScreenBottom && touch.position.y < GuiInGameMenu.CScreenBottom + GuiInGameMenu.CScreenHeight)
                {// CONTROLS
                    GuiManager.Instance.PlayWarningSound();
                    //GuiManager.Instance.PlayButtonSound();
                    ShowControls();

                    if (JoystickUIManager.instance.isNew == false)
                    {
                        JoystickUIManager.instance.Show();
                    }
                }
                else if (touch.position.x > GuiInGameMenu.RScreenLeft && touch.position.x < GuiInGameMenu.RScreenLeft + GuiInGameMenu.RScreenWidth &&
                         touch.position.y > GuiInGameMenu.RScreenBottom && touch.position.y < GuiInGameMenu.RScreenBottom + GuiInGameMenu.RScreenHeight)
                {
                    GuiManager.Instance.PlayButtonSound();
                    Resume();
                }
                else if (touch.position.x > GuiInGameMenu.QScreenLeft && touch.position.x < GuiInGameMenu.QScreenLeft + GuiInGameMenu.QScreenWidth &&
                         touch.position.y > GuiInGameMenu.QScreenBottom && touch.position.y < GuiInGameMenu.QScreenBottom + GuiInGameMenu.QScreenHeight)
                {
                    GuiManager.Instance.PlayButtonSound();
                    //Quit();
                    GuiManager.StartCoroutine(ApplicationQuit());
                }
            }
        }
        else
        {
            if (touch.phase == TouchPhase.Began)
            {
                if (touch.position.x > GuiInGameMenu.COKScreenLeft && touch.position.x < GuiInGameMenu.COKScreenLeft + GuiInGameMenu.COKScreenWidth &&
                    touch.position.y > GuiInGameMenu.COKScreenBottom - GuiInGameMenu.COKScreenHeight && touch.position.y < GuiInGameMenu.COKScreenBottom + GuiInGameMenu.COKScreenHeight * 2)
                {// SAVE
                    GuiManager.Instance.PlayButtonSound();
                    HideControls(true);
                    if (JoystickUIManager.instance.isNew == false)
                    {
                        JoystickUIManager.instance.Hide();
                    }
                }
                else if (touch.position.x > GuiInGameMenu.CCScreenLeft && touch.position.x < GuiInGameMenu.CCScreenLeft + GuiInGameMenu.CCScreenWidth &&
                         touch.position.y > GuiInGameMenu.CCScreenBottom - GuiInGameMenu.CCScreenHeight && touch.position.y < GuiInGameMenu.CCScreenBottom + GuiInGameMenu.CCScreenHeight * 2)
                {//CANCEL
                    GuiManager.Instance.PlayButtonSound();
                    HideControls(false);
                    if (JoystickUIManager.instance.isNew == false)
                    {
                        JoystickUIManager.instance.Hide();
                    }
                }
                else if (touch.position.x > GuiInGameMenu.CRScreenLeft && touch.position.x < GuiInGameMenu.CRScreenLeft + GuiInGameMenu.CRScreenWidth &&
                         touch.position.y > GuiInGameMenu.CRScreenBottom - GuiInGameMenu.CRScreenHeight && touch.position.y < GuiInGameMenu.CRScreenBottom + GuiInGameMenu.CRScreenHeight * 2)
                {//RESET
                    GuiManager.Instance.PlayButtonSound();
                    ResetControls();
                }
                else if ((GuiButtonY.Instance.Center + Game.Instance.ControlsButtonOffset - touch.position).magnitude < 200)
                {
                    ButtonSelected   = true;
                    JoystickSelected = false;
                }
                else if ((GuiJoystick.Instance.Center + Game.Instance.ControlsButtonOffset - touch.position).magnitude < 100)
                {
                    ButtonSelected   = false;
                    JoystickSelected = true;
                }
            }
            else if (touch.phase == TouchPhase.Moved)
            {
                if (ButtonSelected)
                {
                    Game.Instance.ControlsButtonOffset += touch.deltaPosition;
                }
                else if (JoystickSelected)
                {
                    Game.Instance.ControlsJoystickOffset += touch.deltaPosition;
                }

                GuiManager.Instance.UpdateControlsForCustomize();
            }
            else if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
            {
                ButtonSelected   = false;
                JoystickSelected = false;
            }
        }
    }
Ejemplo n.º 6
0
    public void TouchUpdate(STouch touch)
    {
        if (Joystick.On && Joystick.FingerID == -1)
        {
            Vector2 dir  = touch.position - Joystick.Center;
            float   dist = dir.magnitude;
            // //Debug.Log("testing TouchBegin on Joystick : " + dist);
            if (dist < Joystick.Radius * 1.5f)
            {
                Joystick.FingerID = touch.fingerId;
                GuiManager.Instance.JoystickDown();

                if (dist > Joystick.DeadZone)
                {
                    Joystick.Direction.x = dir.y;
                    Joystick.Direction.z = -dir.x;
                    Joystick.Direction.Normalize();

                    _Temp.eulerAngles  = new Vector3(0, MainCameraTransfom.eulerAngles.y, 0);
                    Joystick.Direction = _Temp.TransformDirection(Joystick.Direction);

                    Joystick.Force = (dist - Joystick.DeadZone) / (Joystick.Radius - Joystick.DeadZone);

                    dir.Normalize();
                    dir *= Joystick.Force;
                    GuiManager.Instance.JoystickUpdate(dir);
                }
                else
                {
                    Joystick.Direction = Vector3.zero;
                    Joystick.Force     = 0;

                    GuiManager.Instance.JoystickUpdate(Vector2.zero);
                }

                //Debug.Log("Joystick aquired");


                return;
            }
        }

        if (Joystick.On && Joystick.FingerID == touch.fingerId)
        {
            Vector2 dir  = touch.position - Joystick.Center;
            float   dist = dir.magnitude;
            //Debug.Log("joystick updated");
            Joystick.FingerID = touch.fingerId;

            if (dist > Joystick.Radius)
            {
                dir.Normalize();
                dir *= Joystick.Radius;
            }
            GuiManager.Instance.JoystickUpdate(dir);


            if (dist > Joystick.DeadZone)
            {
                Joystick.Direction.x = dir.x;
                Joystick.Direction.z = dir.y;
                Joystick.Direction.Normalize();

                _Temp.transform.eulerAngles = new Vector3(0, MainCameraTransfom.eulerAngles.y, 0);
                Joystick.Direction          = _Temp.transform.TransformDirection(Joystick.Direction);
                Joystick.Force = (dist - Joystick.DeadZone) / (Joystick.Radius - Joystick.DeadZone);
                if (Joystick.Force > 1)
                {
                    Joystick.Force = 1;
                }
                return;
            }
            Joystick.Direction = Vector3.zero;
            Joystick.Force     = 0;
            return;
        }
    }
Ejemplo n.º 7
0
    public void TouchBegin(STouch touch)
    {
        //Debug.Log("testing TouchBegin : " + touch.position);

        if (FingerIdInUse(touch))
        {
            return;
        }

        if (Joystick.On && Joystick.FingerID == -1)
        {
            Vector2 dir  = touch.position - Joystick.Center;
            float   dist = dir.magnitude;
            // //Debug.Log("testing TouchBegin on Joystick : " + dist);
            if (dist < Joystick.Radius * 1.5f)
            {
                Joystick.FingerID = touch.fingerId;

                GuiManager.Instance.JoystickDown();

                if (dist > Joystick.DeadZone)
                {
                    Joystick.Direction.x = dir.y;
                    Joystick.Direction.z = -dir.x;
                    Joystick.Direction.Normalize();

                    _Temp.eulerAngles  = new Vector3(0, MainCameraTransfom.eulerAngles.y, 0);
                    Joystick.Direction = _Temp.TransformDirection(Joystick.Direction);

                    Joystick.Force = (dist - Joystick.DeadZone) / (Joystick.Radius - Joystick.DeadZone);

                    dir.Normalize();
                    dir *= Joystick.Force;
                    GuiManager.Instance.JoystickUpdate(dir);
                }
                else
                {
                    Joystick.Direction = Vector3.zero;
                    Joystick.Force     = 0;

                    GuiManager.Instance.JoystickUpdate(Vector2.zero);
                }

                //Debug.Log("Joystick aquired");


                return;
            }
        }

        for (int i = 0; i < Buttons.Length; i++)
        {
            ////Debug.Log("testing TouchBegin on button (" + i + " ) : " + (touch.position - Buttons[i].Center).magnitude);

            if (Game.Instance.GameType == E_GameType.Survival && i >= (int)E_ButtonsName.ShopHealth)
            {
                break;
            }

            if (Buttons[i].On && Buttons[i].FingerId == -1 && Buttons[i].IsInsideButton(touch))
            {
                Buttons[i].FingerId  = touch.fingerId;
                Buttons[i].Status    = E_ButtonStatus.DownFirst;
                Buttons[i].PressTime = Time.timeSinceLevelLoad;

                GuiManager.Instance.ButtonDown((E_ButtonsName)i);

                return;
            }
        }
    }
Ejemplo n.º 8
0
    public void Update()
    {
        //add this check to delete Mission on construct
        if (Buttons == null)
        {
            return;
        }
        for (int i = 0; i < Buttons.Length; i++)
        {
            if (Buttons[i].Status == E_ButtonStatus.UpFirst)
            {
                Buttons[i].Status = E_ButtonStatus.Up;
            }
            else if (Buttons[i].Status == E_ButtonStatus.DownFirst)
            {
                Buttons[i].Status = E_ButtonStatus.Down;
            }

            if (i < (int)E_ButtonsName.Shop && Buttons[i].PressTime != -1 && Time.timeSinceLevelLoad - Buttons[i].PressTime > 0.1f)
            {
                Buttons[i].Status    = E_ButtonStatus.UpFirst;
                Buttons[i].FingerId  = -1;
                Buttons[i].PressTime = -1;
                GuiManager.Instance.ButtonUp((E_ButtonsName)i);
            }
        }

        STouch touch = new STouch();

//		if(touch.isTouchPlatForm==false||
//			JoystickUIManager.instance.Model=="Joystick"){
        if (JoystickUIManager.instance.Model != "Normal")
        {
            //Debug.Log ("joystick model="+JoystickUIManager.instance.Model);
            //响应键盘----------------------------------------------------------------------------------------------
            //android|ios 触摸框架,并且一开始model=="",会走另外下面的逻辑,
            //无关于这里 JoystickUIManager.instance.Model=="Touch"

            if (this.isBackClick() == true)
            {
                if (GuiManager.Instance.isIngameMenuControlsOn == true)
                {
                    GuiManager.Instance.PlayButtonSound();
                    GuiManager.Instance.HideIngameMenuControls();
                }
                else
                {
                    if (GuiManager.Instance.isIngameMenuOn == true)
                    {
                        GuiManager.Instance.PlayButtonSound();
                        GuiManager.Instance.HideIngameMenu();
                    }
                    else
                    {
                        GuiManager.Instance.PlayWarningSound();
                        GuiManager.Instance.ShowIngameMenu();
                    }
                }
                return;
            }
//			if (Input.touchCount>0){
//				Debug.Log ("PlayerControls handl touch tick return");
//				return;
//			}
            if (Input.anyKeyDown)              //手点击也会any key down
            {
                Debug.Log("touchplatform false");
            }

            //Debug.Log ("joystick tick");
            SDirection direction = m_touchmgr.buttonParseCombo();

            KeyCode codeA = JoystickUIManager.instance.parse(KeyCode.A);
            KeyCode codeD = JoystickUIManager.instance.parse(KeyCode.D);
            KeyCode codeW = JoystickUIManager.instance.parse(KeyCode.W);
            KeyCode codeS = JoystickUIManager.instance.parse(KeyCode.S);
            m_touchmgr.Update(codeA, codeW, codeD, codeS);             //have to be validate, not handle by current version
            if (Input.GetKeyDown(codeA))
            {
                touch.Direction = SDirection.left;
                TouchBegin(touch);
            }
            else if (Input.GetKeyDown(codeD))
            {
                touch.Direction = SDirection.right;
                TouchBegin(touch);
            }
            else if (Input.GetKeyDown(codeW))
            {
                touch.Direction = SDirection.top;
                TouchBegin(touch);
            }
            else if (Input.GetKeyDown(codeS))
            {
                touch.Direction = SDirection.bottom;
                TouchBegin(touch);
            }

            KeyCode codeJ = JoystickUIManager.instance.parse(KeyCode.J);
            KeyCode codeK = JoystickUIManager.instance.parse(KeyCode.K);
            KeyCode codeL = JoystickUIManager.instance.parse(KeyCode.L);
            if (Input.GetKeyDown(codeJ))
            {
                //Debug.Log("get key down j");
                STouch t2 = new STouch();
                t2.fingerId = 2;
                t2.phase    = TouchPhase.Ended;

                t2.position = Buttons [(int)E_ButtonsName.Roll].Center;
                TouchBegin(t2);
            }
            else if (Input.GetKeyDown(codeK))
            {
                STouch t2 = new STouch();
                t2.fingerId = 2;
                t2.phase    = TouchPhase.Began;
                //t2.position = new Vector2(1039,151);
                t2.position = Buttons [(int)E_ButtonsName.AttackO].Center;
                TouchBegin(t2);
            }
            else if (Input.GetKeyDown(codeL))
            {
                STouch t2 = new STouch();
                t2.fingerId = 2;
                t2.phase    = TouchPhase.Began;
                //t2.position = new Vector2(1137,231);
                t2.position = Buttons [(int)E_ButtonsName.AttackX].Center;
                TouchBegin(t2);
            }

//			if(Input.GetKey(KeyCode.A)){
//				touch.Direction = SDirection.left;
//				TouchUpdate(touch);
//			}else if(Input.GetKey(KeyCode.W)){
//				touch.Direction = SDirection.top;
//				TouchUpdate(touch);
//			}else if (Input.GetKey(KeyCode.D)){
//				touch.Direction=SDirection.right;
//				TouchUpdate(touch);
//			}else if(Input.GetKey(KeyCode.S)){
//				touch.Direction=SDirection.bottom;
//				TouchUpdate(touch);
//			}
            if (Input.GetKey(codeA) || Input.GetKey(codeW) || Input.GetKey(codeD) || Input.GetKey(codeS))
            {
                touch.center    = Joystick.Center;
                touch.Direction = direction;
                TouchUpdate(touch);
            }

            if (Input.GetKeyUp(codeA))
            {
                touch.Direction = SDirection.left;
                TouchEnd(touch);
            }
            else if (Input.GetKeyUp(codeW))
            {
                touch.Direction = SDirection.top;
                TouchEnd(touch);
            }
            else if (Input.GetKeyUp(codeD))
            {
                touch.Direction = SDirection.right;
                TouchEnd(touch);
            }
            else if (Input.GetKeyUp(codeS))
            {
                touch.Direction = SDirection.bottom;
                TouchEnd(touch);
            }


            //响应遥感方向键
            float horizontal = Input.GetAxis("Horizontal");
            float vertical   = Input.GetAxis("Vertical");
            if (horizontal != 0 || vertical != 0)
            {
                Debug.Log("bluetooth h=" + horizontal + "|v=" + vertical);

                touch.position = new Vector2(Joystick.Center.x + horizontal * 50, Joystick.Center.y + vertical * 50);
                touch.fingerId = 1;
                if (isBluetoothBegan = false)
                {
                    isBluetoothBegan = true;
                    touch.phase      = TouchPhase.Began;
                    TouchBegin(touch);
                }
                else
                {
                    touch.phase = TouchPhase.Moved;
                    TouchUpdate(touch);
                }
                //if(Input.get
            }
            else
            {
                isBluetoothBegan = false;
                if (Joystick.On == true && Joystick.FingerID == 1)
                {
                    Debug.Log("PlayerControls testing axis off touchend...");
                    touch.position = Joystick.Center;
                    touch.fingerId = 1;
                    touch.phase    = TouchPhase.Ended;
                    TouchEnd(touch);
                }
            }
        }        //end of JoystickUIManager.instance.Model != "Touch"
                 //} else {

        //Input设置问题Mouse和Touch的响应会互相冲突
        //所以不能并行
        //具体原因没深究
        if (touch.isTouchPlatForm == false)
        {
            //响应Mouse------------------------------------------------------------------------------
            if (Input.GetMouseButtonDown(0))
            {
                //Debug.Log(string.Format("GetMouseButtonDown getkeya{0}",Input.GetKey(KeyCode.A)));
                //Debug.Log(string.Format("x|y {0}|{1}",Input.mousePosition.x,Input.mousePosition.y));
                STouch t2 = new STouch();
                t2.fingerId = 2;
                t2.phase    = TouchPhase.Began;
                t2.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                TouchBegin(t2);
            }
            else if (Input.GetMouseButtonUp(0))
            {
                STouch t2 = new STouch();
                t2.fingerId = 2;
                t2.phase    = TouchPhase.Ended;
                t2.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                TouchEnd(t2);
            }
        }
        else
        {
            //响应touch--------------------------------------------------------------------------------------------------

            //测试用---------------------------------------------
            if (Input.touchCount == 0)
            {
                return;
            }

            Debug.Log("touchplatform true");
            for (int i = 0; i < Input.touchCount; i++)
            {
                Touch t = Input.GetTouch(i);
                touch.phase    = t.phase;
                touch.position = t.position;
                touch.fingerId = t.fingerId;
                if (touch.phase == TouchPhase.Began)
                {
                    TouchBegin(touch);
                }
                else if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary)
                {
                    TouchUpdate(touch);
                }
                else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
                {
                    TouchEnd(touch);
                }
            }
            //}
        }
    }
Ejemplo n.º 9
0
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < gameObject.transform.childCount; i++)
        {
            Transform      t      = gameObject.transform.GetChild(i);
            JoystickButton script = t.GetComponent <JoystickButton> ();
            if (script != null)
            {
                script.keyHandler += OnCustomerKeySelected;
            }

            JoystickRadio radio = t.GetComponent <JoystickRadio> ();
            if (radio != null)
            {
                radio.keyHandler += OnRadioSelected;
            }
        }
        _instance = this;
        Hide();
        //20160609 hide or show function is for customrize only
        //the code convert function is on a different channel(parse function)


        Button btn = gameObject.GetComponentInChildren <Button>();

        EventTriggerListener.Get(btn.gameObject).onUp = onPointerUp;

        //depends on joystick is connected to current ios
        STouch touch = new STouch();

        if (touch.isTouchPlatForm == false)
        {
            for (int i = 0; i < gameObject.transform.childCount; i++)
            {
                Transform     t     = gameObject.transform.GetChild(i);
                JoystickRadio radio = t.GetComponent <JoystickRadio> ();
                if (radio != null && radio.keySrc == "JS")
                {
                    //print ("manager js select");
                    radio.isPressed = true;
                }
            }
        }
        else
        {
            for (int i = 0; i < gameObject.transform.childCount; i++)
            {
                Transform     t     = gameObject.transform.GetChild(i);
                JoystickRadio radio = t.GetComponent <JoystickRadio> ();
                if (radio != null && radio.keySrc == "NOR")
                {
                    //print ("manager nor select");
                    //radio.selected ();//这里select不能
                    radio.isPressed = true;
                }
            }
        }
        this.initByPlayerPrefs();
        this.initKeycodeMapping();
        Debug.Log("jsm start event");
        StartCoroutine(CheckForControllers());

        //如果判断到蓝牙手柄,上下左右,将不可被修改
        if (Input.GetJoystickNames().Length > 0)
        {
            for (int i = 0; i < gameObject.transform.childCount; i++)
            {
                Transform      t      = gameObject.transform.GetChild(i);
                JoystickButton script = t.GetComponent <JoystickButton> ();
                if (script != null)
                {
                    if (script.keySrc == "A" || script.keySrc == "W" || script.keySrc == "D" || script.keySrc == "S")
                    {
                        script.enabled = false;
                    }
                    if (script.keySrc == "A")
                    {
                        script.Text      = "<";
                        script.keyDefine = "<xnfleft";
                    }
                    else if (script.keySrc == "W")
                    {
                        script.Text      = "^";
                        script.keyDefine = "^xnfup";
                    }
                    else if (script.keySrc == "D")
                    {
                        script.Text      = ">";
                        script.keyDefine = ">xnfright";
                    }
                    else if (script.keySrc == "S")
                    {
                        script.Text   = ",";
                        script.keySrc = ",xnfdown";
                    }
                    ;
                }
            }
        }
    }