void Update_Keyboard(ref Vector2 _dirState, ref PadButton _btnState, ref bool isMenuDown) { if (Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.Return)) { isMenuDown = true; } //left if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) //left { _dirState.x -= 1; //btns[KeyCode.A].IsDown = true; } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) //right { _dirState.x += 1; //btns[KeyCode.D].IsDown = true; } if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) //up { _dirState.y += 1; //btns[KeyCode.W].IsDown = true; } if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) //down { _dirState.y -= 1; //btns[KeyCode.S].IsDown = true; } if (_btnState != PadButton.None && _btnState != PadButton.Func) { return; } if (Input.GetKey(KeyCode.J)) // left { _btnState = PadButton.Func; //btns[KeyCode.J].IsDown = true; } if (Input.GetKey(KeyCode.K)) // down { _btnState = PadButton.Func_Down; //btns[KeyCode.K].IsDown = true; } if (Input.GetKey(KeyCode.I)) // up { _btnState = PadButton.Func_Up; //btns[KeyCode.I].IsDown = true; } if (Input.GetKey(KeyCode.L)) // right { _btnState = PadButton.Func_Forward; //btns[KeyCode.L].IsDown = true; } }
// Update is called once per frame void Update_TouchBtnFix(ref PadButton _btnState) { if (_btnState != PadButton.None && _btnState != PadButton.Func) { return; } for (int i = 0; i < Input.touchCount; i++) { if (Input.touches[i].phase == TouchPhase.Began || Input.touches[i].phase == TouchPhase.Moved || Input.touches[i].phase == TouchPhase.Stationary) { var pos = Input.touches[i].position; pos.y = Screen.height - pos.y; foreach (var bi in btnInfo) { Rect r = bi.dest; r.x += Screen.width; r.y += Screen.height; if (r.Contains(pos)) { _btnState = bi.padstate; } } } } #if UNITY_EDITOR //需要的时候得模拟一下 //if (Input.multiTouchEnabled == false) { Vector2 pos = Input.mousePosition; pos.y = Screen.height - pos.y; if (Input.GetMouseButton(0)) { foreach (var bi in btnInfo) { if (Input.GetMouseButton(0)) { Rect r = bi.dest; r.x += Screen.width; r.y += Screen.height; if (r.Contains(pos)) { _btnState = bi.padstate; } //bi.bdown = bi.dest.Contains(pos); } } } } #endif }
public List <PadButton> readButtons(byte[] readData) { BitArray buttonsBits = new BitArray(readData); List <PadButton> pressedButtons = new List <PadButton>(); int offset = ARROWS_BYTE * 8; for (int i = (int)PadButton.LEFT; i <= (int)PadButton.START; i++) { if (buttonsBits.Get(offset + i) == true) { PadButton pressedButton = (PadButton)i; pressedButtons.Add(pressedButton); } } return(pressedButtons); }
static bool MatchKey(char key, PadButton state) { switch (key) { case 'L': return(state == PadButton.Func_Forward); case 'I': return(state == PadButton.Func_Up); case 'K': return(state == PadButton.Func_Down); case 'J': return(state == PadButton.Func); default: return(false); } }
int GetSpriteIndex(PadButton btn) { if (btn == PadButton.Func) { return(8); } if (btn == PadButton.Func_Down) { return(9); } if (btn == PadButton.Func_Up) { return(10); } if (btn == PadButton.Func_Forward) { return(11); } return(-1); }
void Update_Joy(ref Vector2 _dirState, ref PadButton _btnState, ref bool isMenuDown) { float x = Input.GetAxisRaw("X axis"); float y = Input.GetAxisRaw("Y axis");// mark as Invert _dirState.x += x; _dirState.y += y; //if (x < -0.5f) //{ // _dirState.x -= 1; //} //else if (x > 0.5f) //{ // _dirState.x += 1; //} //if (y < -0.5f) //{ // _dirState.y -= 1; //} //else if (y > 0.5f) //{ // _dirState.y += 1; //} if (_btnState != PadButton.None && _btnState != PadButton.Func) { return; } //right if (Input.GetButton("joystick button 2")) // left { _btnState = PadButton.Func; } if (Input.GetButton("joystick button 0")) // down { _btnState = PadButton.Func_Down; } if (Input.GetButton("joystick button 3")) //up { _btnState = PadButton.Func_Up; } if (Input.GetButton("joystick button 1")) // right { _btnState = PadButton.Func_Forward; Debug.Log("joystick button 1"); } if (Input.GetButton("joystick button 6")) //up { //_btnState = PadButton.Func_Up; isMenuDown = true; Debug.Log("joystick button 6"); } if (Input.GetButton("joystick button 7")) // right { isMenuDown = true; //_btnState = PadButton.Func_Forward; Debug.Log("joystick button 7"); } }
void Update_TouchBtnDyn(ref PadButton _btnState) { if (_btnState != PadButton.None && _btnState != PadButton.Func) { return; } float dpi = Screen.dpi; if (dpi == 0) { dpi = this.defDPI; } RightTouch.TouchBeginTest(); for (int i = 0; i < Input.touchCount; i++) { var touch = Input.GetTouch(i); if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) { if ((Screen.height - touch.position.y) <= dpi * 0.5f) { //menu = true; } else if (touch.position.x >= Screen.width / 2) { RightTouch.TouchAdd(touch.position); } } } #if UNITY_EDITOR if (Input.GetMouseButton(0)) { if ((Screen.height - Input.mousePosition.y) < dpi * 0.5f) { //menu = true; } else if (Input.mousePosition.x >= Screen.width / 2) { RightTouch.TouchAdd(Input.mousePosition); } } #endif RightTouch.TouchEndTest(dpi); var dir = RightTouch.GetDir(); if (dir != null) { _btnState = PadButton.Func; if (dir.Value.y < -0.5f) { _btnState = PadButton.Func_Down; } else if (dir.Value.y > 0.5f) { _btnState = PadButton.Func_Up; } int chardir = (g_joy as JoyInput).charDir; if ((chardir == -1 && dir.Value.x < -0.5f) || (chardir == 1 && dir.Value.x > 0.5f)) { _btnState = PadButton.Func_Forward; } } }
public Command(Vector2 dir, PadButton state) { this.dir = dir; this.state = state; this.time = Time.realtimeSinceStartup; }
void Update() { _dirState = Vector2.zero; PadButton _btnState = PadButton.None; JoyInput joy = g_joy as JoyInput; bool menu = false; if (!clientmain.canInput) { return; } //在这里键盘输入 Update_Keyboard(ref _dirState, ref _btnState, ref menu); //在这里摇杆输入 Update_Joy(ref _dirState, ref _btnState, ref menu); if (joy.left == JoyMode.Touch_Fix) { Update_TouchPadFix(ref _dirState, ref menu); } else if (joy.left == JoyMode.Touch_Dynamic) { Update_TouchPadDyn(ref _dirState, ref menu); } if (joy.right == JoyMode.Touch_Fix) { Update_TouchBtnFix(ref _btnState); } else if (joy.right == JoyMode.Touch_Dynamic) { Update_TouchBtnDyn(ref _btnState); } joy.isMenuBtnDown = menu; Vector2 _dir = _dirState; if (_dir.x < -0.5f) { _dir.x = -1; } else if (_dir.x > 0.5f) { _dir.x = 1; } else { _dir.x = 0; } if (_dir.y < -0.5f) { _dir.y = -1; } else if (_dir.y > 0.5f) { _dir.y = 1; } else { _dir.y = 0; } Command cmd = new Command(_dir, _btnState); joy.curState = cmd; //Debug.Log("cmd:" + _dirState + " _btn" + _btnState); }
public static bool IsJustReleased(this Pad pad, PadButton button) { return(IsPadJustReleased((int)pad, (int)button)); }
public static bool IsPressed(this Pad pad, PadButton button) { return(IsPadPressed((int)pad, (int)button)); }
public KeyConfigItem(Key key = null, PadButton padButton = null) { Key = key; PadButton = padButton; }
public bool IsButtonUp(PadButton butt) => !this.buttons.HasFlag((Enum)butt);
public bool IsButtonDown(PadButton butt) => this.buttons.HasFlag((Enum)butt);