public void OnPointerUp(PointerEventData eventData) { inputVector = Vector2.zero; handle.anchoredPosition = Vector2.zero; this.currentDPadState = DPadState.ON_KEY_UP; this.isPressingUI = false; }
public void Update() { // If not connected, nothing to update if (!Connected) { return; } // If same packet, nothing to update State state = Controller.GetState(); if (lastPacket == state.PacketNumber) { return; } lastPacket = state.PacketNumber; var gamepadState = state.Gamepad; // Shoulders LeftShoulder = (gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0; RightShoulder = (gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0; // Triggers LeftTrigger = gamepadState.LeftTrigger / (float)byte.MaxValue; RightTrigger = gamepadState.RightTrigger / (float)byte.MaxValue; // Buttons Start = (gamepadState.Buttons & GamepadButtonFlags.Start) != 0; Back = (gamepadState.Buttons & GamepadButtonFlags.Back) != 0; A = (gamepadState.Buttons & GamepadButtonFlags.A) != 0; B = (gamepadState.Buttons & GamepadButtonFlags.B) != 0; X = (gamepadState.Buttons & GamepadButtonFlags.X) != 0; Y = (gamepadState.Buttons & GamepadButtonFlags.Y) != 0; // D-Pad DPad = new DPadState((gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0); LeftStickX = gamepadState.LeftThumbX; LeftStickY = gamepadState.LeftThumbY; RightStickX = gamepadState.RightThumbX; RightStickY = gamepadState.RightThumbY; // Thumbsticks LeftStick = new ThumbstickState( Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, SlimDX.XInput.Gamepad.GamepadLeftThumbDeadZone), (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0); RightStick = new ThumbstickState( Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, SlimDX.XInput.Gamepad.GamepadRightThumbDeadZone), (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0); int GuideFlag = (1 << 10); Guide = (((int)gamepadState.Buttons) & GuideFlag) != 0; }
void Start() { joystickPosition = RectTransformUtility.WorldToScreenPoint(cam, background.position); dPadDirections = new List <Vector2>(); float diagonalMag = 1f / Mathf.Sqrt(2); dPadDirections.Clear(); Vector2 up = Vector2.up; Vector2 down = Vector2.down; Vector2 left = Vector2.left; Vector2 right = Vector2.right; Vector2 topLeft = new Vector2(-diagonalMag, diagonalMag).normalized; Vector2 topRight = new Vector2(diagonalMag, diagonalMag).normalized; Vector2 bottomLeft = new Vector2(-diagonalMag, -diagonalMag).normalized; Vector2 bottomRight = new Vector2(diagonalMag, -diagonalMag).normalized; dPadDirections.Add(up); dPadDirections.Add(down); dPadDirections.Add(left); dPadDirections.Add(right); dPadDirections.Add(topLeft); dPadDirections.Add(topRight); dPadDirections.Add(bottomLeft); dPadDirections.Add(bottomRight); this.currentDPadState = DPadState.NEUTRAL; }
private void UpdateDpadState(DPadDir dir, bool pressed) { DPadState currentState = _dpadState[(int)dir]; DPadState newState = currentState; switch (currentState) { case DPadState.None: if (pressed) { newState = DPadState.Down; } break; case DPadState.Down: newState = pressed ? DPadState.Held : DPadState.Up; break; case DPadState.Held: if (!pressed) { newState = DPadState.Up; } break; case DPadState.Up: newState = pressed ? DPadState.Down : DPadState.None; break; } _dpadState[(int)dir] = newState; }
/// <summary> /// Write a <see cref="DPadState"/> to the ROM. /// </summary> /// <remarks>Assumes <see cref="Patcher"/> file has been inserted.</remarks> /// <param name="state">D-Pad state</param> private void WriteDPadState(DPadState state) { // Write DPad state byte. var addr = this["DPAD_STATE"]; ReadWriteUtils.WriteToROM((int)addr, (byte)state); }
public void OnDrag(PointerEventData eventData) { Vector2 direction = eventData.position - joystickPosition; inputVector = (direction.magnitude > background.sizeDelta.x / 2f) ? direction.normalized : direction / (background.sizeDelta.x / 2f); this.UpdateHandle(); this.currentDPadState = DPadState.ON_KEY; this.isPressingUI = true; }
void LateUpdate() { if (this.currentDPadState == DPadState.ON_KEY_DOWN) { this.currentDPadState = DPadState.ON_KEY; } else if (this.currentDPadState == DPadState.ON_KEY_UP) { this.currentDPadState = DPadState.NEUTRAL; } }
public void Update() { // If not connected, nothing to update if (!Connected) { return; } var state = Controller.GetState(); // If same packet, nothing to update if (lastPacket == state.PacketNumber) { return; } lastPacket = state.PacketNumber; var gamepadState = state.Gamepad; // Shoulders LeftShoulder = (gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0; RightShoulder = (gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0; // Triggers LeftTrigger = gamepadState.LeftTrigger / (float)byte.MaxValue; RightTrigger = gamepadState.RightTrigger / (float)byte.MaxValue; // Buttons Start = (gamepadState.Buttons & GamepadButtonFlags.Start) != 0; Back = (gamepadState.Buttons & GamepadButtonFlags.Back) != 0; A = (gamepadState.Buttons & GamepadButtonFlags.A) != 0; B = (gamepadState.Buttons & GamepadButtonFlags.B) != 0; X = (gamepadState.Buttons & GamepadButtonFlags.X) != 0; Y = (gamepadState.Buttons & GamepadButtonFlags.Y) != 0; // D-Pad DPad = new DPadState( (gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0); // Thumbsticks LeftStick = new ThumbstickState( //Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.GamepadLeftThumbDeadZone), new Vector2(gamepadState.LeftThumbX, gamepadState.LeftThumbY), (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0); RightStick = new ThumbstickState( //Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.GamepadRightThumbDeadZone), new Vector2(gamepadState.RightThumbX, gamepadState.RightThumbY), (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0); }
public void Update() { // If not connected, nothing to update if (!Connected) return; // If same packet, nothing to update State state = Controller.GetState(); if (lastPacket == state.PacketNumber) return; lastPacket = state.PacketNumber; var gamepadState = state.Gamepad; // Shoulders LeftShoulder = (gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0; RightShoulder = (gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0; // Triggers LeftTrigger = gamepadState.LeftTrigger / (float)byte.MaxValue; RightTrigger = gamepadState.RightTrigger / (float)byte.MaxValue; // Buttons Start = (gamepadState.Buttons & GamepadButtonFlags.Start) != 0; Back = (gamepadState.Buttons & GamepadButtonFlags.Back) != 0; A = (gamepadState.Buttons & GamepadButtonFlags.A) != 0; B = (gamepadState.Buttons & GamepadButtonFlags.B) != 0; X = (gamepadState.Buttons & GamepadButtonFlags.X) != 0; Y = (gamepadState.Buttons & GamepadButtonFlags.Y) != 0; // D-Pad DPad = new DPadState((gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0); // Thumbsticks LeftStick = new ThumbstickState( Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.GamepadLeftThumbDeadZone), (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0); RightStick = new ThumbstickState( Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.GamepadRightThumbDeadZone), (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0); }
/// <summary> /// Requests a reading from the controller and updates its data properties with the gathered values. /// </summary> /// <returns>An awaitable Task</returns> /// <remarks> /// Note that when #AutoUpdateWhenPropertyRead is `true` (which it is, by default), this method is implicitly /// called when any sensor data property is read from --- there's no need to call this method unless you set /// AutoUpdateWhenPropertyRead to `false`. /// /// Unless otherwise noted, this method updates all sensor data simultaneously, which can often lead to more efficient /// bus usage (as well as reducing USB chattiness). /// </remarks> public virtual async Task UpdateAsync() { var result = await dev.SendReceiveAsync(new byte[] { 0x00 }).ConfigureAwait(false); var values = new BitArray(result); ((DigitalInPeripheralPin)A.Input).DigitalValue = values[7]; ((DigitalInPeripheralPin)B.Input).DigitalValue = values[6]; ((DigitalInPeripheralPin)Select.Input).DigitalValue = values[5]; ((DigitalInPeripheralPin)Start.Input).DigitalValue = values[4]; var oldState = dpad; if (!values[3]) { dpad = DPadState.Up; } else if (!values[2]) { dpad = DPadState.Down; } else if (!values[1]) { dpad = DPadState.Left; } else if (!values[0]) { dpad = DPadState.Right; } else { dpad = DPadState.None; } if (oldState != dpad) { RaiseDPadChanged(); } PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DPad))); }
void Update() { #if UNITY_EDITOR Vector2 newInputVector = Vector2.zero; if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.A)) { this.currentDPadState = DPadState.ON_KEY_DOWN; } else if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.A)) { this.currentDPadState = DPadState.ON_KEY_UP; } if (Input.GetKey(KeyCode.W)) { newInputVector.y += 1; } if (Input.GetKey(KeyCode.S)) { newInputVector.y += -1; } if (Input.GetKey(KeyCode.D)) { newInputVector.x += 1; } if (Input.GetKey(KeyCode.A)) { newInputVector.x -= 1; } if (!this.isPressingUI) { this.inputVector = newInputVector; this.UpdateHandle(); } #endif joystickState.direction = GetDPadDirection(); joystickState.state = this.currentDPadState; }
public async Task UpdateAsync() { await dev.WriteByteAsync(0x00).ConfigureAwait(false); var response = await dev.ReadDataAsync(6).ConfigureAwait(false); var lx = (response[0] & 0x3F) - 32; var ly = (response[1] & 0x3F) - 32; var rx = (response[2] >> 7) | ((response[1] & 0xC0) >> 5) | (((response[0] & 0xC0) >> 3) - 16); var ry = (response[2] & 0x1F) - 16; leftStick.X = lx > 0 ? lx / 31f : lx / 32f; leftStick.Y = ly > 0 ? ly / 31f : ly / 32f; rightStick.X = rx > 0 ? rx / 15f : rx / 16f; rightStick.Y = ry > 0 ? ry / 15f : ry / 16f; var lt = ((response[2] & 0x60) >> 2) | (response[3] >> 5); var rt = response[3] & 0x1F; leftTriggerForce = lt / 31f; rightTriggerForce = rt / 31f; var array = new BitArray(response.Skip(4).Take(2).ToArray()); ((DigitalInPeripheralPin)R.Input).DigitalValue = !array[1]; ((DigitalInPeripheralPin)Plus.Input).DigitalValue = !array[2]; ((DigitalInPeripheralPin)Home.Input).DigitalValue = !array[3]; ((DigitalInPeripheralPin)Minus.Input).DigitalValue = !array[4]; ((DigitalInPeripheralPin)L.Input).DigitalValue = !array[5]; // D-Pad stuff var temp = dPad; if (!array[6]) { dPad = DPadState.Down; } else if (!array[7]) { dPad = DPadState.Right; } else if (!array[8]) { dPad = DPadState.Up; } else if (!array[9]) { dPad = DPadState.Left; } else { dPad = DPadState.None; } if (temp != dPad) { DPadStateChanged?.Invoke(this, new DPadStateEventArgs { NewValue = dPad }); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DPad))); } ((DigitalInPeripheralPin)ZR.Input).DigitalValue = !array[10]; ((DigitalInPeripheralPin)X.Input).DigitalValue = !array[11]; ((DigitalInPeripheralPin)A.Input).DigitalValue = !array[12]; ((DigitalInPeripheralPin)Y.Input).DigitalValue = !array[13]; ((DigitalInPeripheralPin)B.Input).DigitalValue = !array[14]; ((DigitalInPeripheralPin)ZL.Input).DigitalValue = !array[15]; }
public void Update() { // If not connected, nothing to update if (!Connected) return; // If same packet, nothing to update State state = Controller.GetState(); if (lastPacket == state.PacketNumber) return; lastPacket = state.PacketNumber; var gamepadState = state.Gamepad; // Shoulders LeftShoulder = (gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0; RightShoulder = (gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0; // Triggers LeftTrigger = gamepadState.LeftTrigger / (double)byte.MaxValue; RightTrigger = gamepadState.RightTrigger / (double)byte.MaxValue; // Buttons Start = (gamepadState.Buttons & GamepadButtonFlags.Start) != 0; Back = (gamepadState.Buttons & GamepadButtonFlags.Back) != 0; A = (gamepadState.Buttons & GamepadButtonFlags.A) != 0; B = (gamepadState.Buttons & GamepadButtonFlags.B) != 0; X = (gamepadState.Buttons & GamepadButtonFlags.X) != 0; Y = (gamepadState.Buttons & GamepadButtonFlags.Y) != 0; // D-Pad DPad = new DPadState((gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0); LeftX = gamepadState.LeftThumbX/ (double)short.MaxValue; LeftY = gamepadState.LeftThumbY / (double)short.MaxValue; RightX = gamepadState.RightThumbX / (double)short.MaxValue; RightX = gamepadState.RightThumbY / (double)short.MaxValue; }
public DPadConfig(DPad pad, DPadState state) { this.Pad = pad; this.State = state; }
public DPadConfig(DPad pad, DPadState state, DPadDisplay display) { this.Pad = pad; this.State = state; this.Display = display; }
public void Update(float dt) { ThumbstickState old_l = LeftStick; ThumbstickState old_r = RightStick; // If not connected, nothing to update if (!Connected) return; if (_vibrationTime > _elapsed) { _elapsed += dt; } else { _elapsed = 0; _vibrationTime = 0; Vibrate(0, 0); } // If same packet, nothing to update State state = Controller.GetState(); if (lastPacket == state.PacketNumber) return; lastPacket = state.PacketNumber; var gamepadState = state.Gamepad; // Shoulders LeftShoulder = (gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0; RightShoulder = (gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0; // Triggers LeftTrigger = gamepadState.LeftTrigger / (float)byte.MaxValue; RightTrigger = gamepadState.RightTrigger / (float)byte.MaxValue; // Buttons Start = (gamepadState.Buttons & GamepadButtonFlags.Start) != 0; Back = (gamepadState.Buttons & GamepadButtonFlags.Back) != 0; A = (gamepadState.Buttons & GamepadButtonFlags.A) != 0; B = (gamepadState.Buttons & GamepadButtonFlags.B) != 0; X = (gamepadState.Buttons & GamepadButtonFlags.X) != 0; Y = (gamepadState.Buttons & GamepadButtonFlags.Y) != 0; // D-Pad DPad = new DPadState((gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0); // Thumbsticks LeftStick = new ThumbstickState( Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.LeftThumbDeadZone), (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0); RightStick = new ThumbstickState( Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.RightThumbDeadZone), (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0); foreach (var flag in Enum.GetValues(typeof(GamepadButtonFlags))) { if (OnButtonUp != null) if ((old_state.Buttons & (GamepadButtonFlags)flag) != 0 && (gamepadState.Buttons & (GamepadButtonFlags)flag) == 0) OnButtonUp(this, (GamepadButtonFlags)((GamepadButtonFlags)flag)); if (OnButtonPress != null) { if ((old_state.Buttons & (GamepadButtonFlags)flag) == 0 && (gamepadState.Buttons & (GamepadButtonFlags)flag) != 0) OnButtonPress(this, (GamepadButtonFlags)((GamepadButtonFlags)flag)); } if (OnButtonDown != null) if ((gamepadState.Buttons & (GamepadButtonFlags)flag) != 0) OnButtonDown(this, (GamepadButtonFlags)gamepadState.Buttons); } if (OnLeftTrigger != null) if (gamepadState.LeftTrigger != old_state.LeftTrigger) OnLeftTrigger(this, new TriggerState(LeftTrigger, LeftTrigger - (old_state.LeftTrigger / (float)byte.MaxValue))); if (OnRightTrigger != null) if (gamepadState.RightTrigger != old_state.RightTrigger) OnRightTrigger(this, new TriggerState(RightTrigger, RightTrigger - (old_state.RightTrigger / (float)byte.MaxValue))); if (OnLeftStick != null) if (LeftStick.Position != old_l.Position || LeftStick.Clicked != old_l.Clicked) OnLeftStick(this, LeftStick, LeftStick.Position - old_l.Position); if (OnRightStick != null) if (RightStick.Position != old_r.Position || RightStick.Clicked != old_r.Clicked) OnRightStick(this, RightStick, RightStick.Position - old_r.Position); old_state = gamepadState; }
public void OnPointerDown(PointerEventData eventData) { OnDrag(eventData); this.currentDPadState = DPadState.ON_KEY_DOWN; this.isPressingUI = true; }