/// <summary> /// 取最后2个按钮,如果互斥,才再取前一个比较 /// </summary> /// <returns>The parse combo.</returns> /// <param name="code">Code.</param> public SDirection buttonParseCombo() { //Debug.Log(buttonStatus.Count+"xCount"); int[] ints = bubbleSort(null); //int[] convertInts = new int[4]; // for (int i=0; i<ints.Length; i++) { // convertInts[i]=ints[i]; // } // for (int i = 0; i < 4-ints.Length; i++) { // convertInts[i+ints.cou]=new SButton(0,TouchPhase.Ended); // } String strs = ""; String keys = ""; string times = ""; foreach (int i in ints) { strs += i + "|"; KeyCode code = (KeyCode)buttonIndex[i]; keys += Enum.GetName(typeof(KeyCode), code); SButton btn = buttonStatus[code] as SButton; times += btn.beginTime + "|"; } //Debug.Log (strs + ","+keys+","+times); SDirection direct = SDirection.none; //val second button if (ints.Length > 0) { int iLastButton = ints.Length - 1; KeyCode code = (KeyCode)buttonIndex[ints[iLastButton]]; SButton btn = buttonStatus[code] as SButton; if (btn.beginTime > 0 && ints.Length > 1) { KeyCode code2 = (KeyCode)buttonIndex[ints[ints.Length - 2]]; SButton btnSec = buttonStatus[code2] as SButton; if (btnSec.beginTime == 0) { direct = (SDirection)joystickDirection[(int)code]; } else { KeyCode codeOp = (KeyCode)oppositiveSide[code]; if (codeOp == code2) { if (ints.Length > 2) { KeyCode code3 = (KeyCode)buttonIndex[ints[ints.Length - 3]]; SButton btnTrd = buttonStatus[code3] as SButton; if (btnTrd.beginTime == 0) { direct = (SDirection)joystickDirection[(int)code]; } else { direct = (SDirection)joystickDirection[(int)code + (int)code3]; } } else { direct = (SDirection)joystickDirection[(int)code2]; } } else { direct = (SDirection)joystickDirection[(int)code + (int)code2]; } } } else { direct = (SDirection)joystickDirection[(int)code]; } } //Debug.Log ("direct:"+Enum.GetName(typeof(SDirection),direct)); return(direct); // bool bol = true; // if(code == KeyCode.S){ // foreach(DictionaryEntry entry in buttonStatus){ // KeyCode key = (KeyCode)entry.Key; // if(key==KeyCode.W){ // SButton btnS = buttonStatus[KeyCode.S] as SButton; // SButton button = entry.Value as SButton; // if(btnS.beginTime > button.beginTime){ // bol = false; // } // // bol= true; // } // //assume onlys have a and d key. // bol= true; // } // }else if(code == KeyCode.A){ // foreach(DictionaryEntry entry in buttonStatus){ // KeyCode key = (KeyCode)entry.Key; // if(key==KeyCode.D){ // SButton btnA = buttonStatus[KeyCode.A] as SButton; // SButton button = entry.Value as SButton; // if(btnA.beginTime>button.beginTime){ // bol= false; // } // bol= true; // } // } // //assue that only have w or s keycode // bol= true; // } // // if(bol==true){ // if(code==KeyCode.S){ // // } // return SDirection.bottom; // }else{ // return SDirection.none; // } }
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); } } //} } }