// Callback function when a stick is moved. protected virtual void StickMove(StickControl control) { Transform stick = GetInputTransform(FirstLetterToUpper(control.name), isStick: true); Vector2 pos = control.ReadValue() * 0.5f; stick.localPosition = new Vector3(pos.x, pos.y, -0.01f); }
protected override void FinishSetup() { base.FinishSetup(); Button0 = GetChildControl <ButtonControl>("button0"); Button1 = GetChildControl <ButtonControl>("button1"); Stick0 = GetChildControl <StickControl>("stick0"); }
// FinishSetup is where our device setup is finalized. Here we can look up // the controls that have been created. protected override void FinishSetup() { base.FinishSetup(); firstButton = GetChildControl <ButtonControl>("firstButton"); secondButton = GetChildControl <ButtonControl>("secondButton"); thirdButton = GetChildControl <ButtonControl>("thirdButton"); stick = GetChildControl <StickControl>("stick"); }
// Callback function when a stick is moved. protected virtual void StickMove(StickControl control) { Vector2 pos = control.ReadValue(); Transform stick = GetInputTransform(FirstLetterToUpper(control.name), isStick: true); if (stick != null) { stick.localPosition = new Vector3(pos.x * m_stickMaxMove, pos.y * m_stickMaxMove, stick.localPosition.z); } }
public static void AssertStickValues(StickControl stick, Vector2 stickValue, float up, float down, float left, float right) { Assert.That(stick.ReadUnprocessedValue(), Is.EqualTo(stickValue)); Assert.That(stick.up.ReadUnprocessedValue(), Is.EqualTo(up).Within(0.0001), "Incorrect 'up' value"); Assert.That(stick.down.ReadUnprocessedValue(), Is.EqualTo(down).Within(0.0001), "Incorrect 'down' value"); Assert.That(stick.left.ReadUnprocessedValue(), Is.EqualTo(left).Within(0.0001), "Incorrect 'left' value"); Assert.That(stick.right.ReadUnprocessedValue(), Is.EqualTo(right).Within(0.0001), "Incorrect 'right' value"); }
protected override void StickMove(StickControl control) { base.StickMove(control); Transform stick = GetInputTransform(FirstLetterToUpper(control.name), isStick: true); TextMesh textMesh = stick.Find("Value_Input_System").GetComponent <TextMesh>(); if (textMesh != null) { textMesh.text = control.ReadValue().ToString(); } }
protected override void StickMove(StickControl control) { base.StickMove(control); if (control.name == "leftStick") { m_leftStickText.text = control.ReadValue().ToString("F2"); } else if (control.name == "rightStick") { m_rightStickText.text = control.ReadValue().ToString("F2"); } }
protected override void StickMove(StickControl control) { Transform stick = GetInputTransform(FirstLetterToUpper(control.name), isStick: true); Vector2 pos = control.ReadValue(); if (stick != null) { stick.localPosition = new Vector3(pos.x * m_stickMaxMove, pos.y * m_stickMaxMove, stick.localPosition.z); } // update the text Transform positionText = stick.parent.Find("Pos"); if (positionText != null) { positionText.GetComponent <TextMesh>().text = pos.ToString("F2"); } }
protected override void FinishSetup() { base.FinishSetup(); fire = GetChildControl <ButtonControl>("fire"); look = GetChildControl <StickControl>("look"); }
protected override void FinishSetup(InputDeviceBuilder builder) { base.FinishSetup(builder); fire = builder.GetControl <ButtonControl>("fire"); look = builder.GetControl <StickControl>("look"); }
private void OnStickMove(StickControl control) { Debug.Log("Stick Moved"); }
// Update is called once per frame void FixedUpdate() { //Mouse Controls /* * if (Input.GetMouseButtonDown(0)) * { * targetPosition = Input.mousePosition; * targetPosition = Camera.main.ScreenToWorldPoint(new Vector3(targetPosition.x, targetPosition.y, 0.0f)); * } * this.transform.position = Vector2.MoveTowards(this.transform.position, targetPosition, speed * Time.deltaTime); */ bool wasMovementReleased = false; if (Gamepad.current != null) { StickControl leftStick = Gamepad.current.leftStick; wasMovementReleased = leftStick.right.wasReleasedThisFrame || leftStick.left.wasReleasedThisFrame || leftStick.up.wasReleasedThisFrame || leftStick.down.wasReleasedThisFrame; } wasMovementReleased = wasMovementReleased || Input.GetKeyUp("w") || Input.GetKeyUp("a") || Input.GetKeyUp("s") || Input.GetKeyUp("d") || Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKeyUp(KeyCode.DownArrow) || Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.RightArrow); float horizontal = Input.GetAxisRaw("Horizontal") != 0 ? Input.GetAxisRaw("Horizontal") : Gamepad.current != null?Gamepad.current.leftStick.ReadValue().x : 0; float vertical = Input.GetAxisRaw("Vertical") != 0 ? Input.GetAxisRaw("Vertical") : Gamepad.current != null?Gamepad.current.leftStick.ReadValue().y : 0; Animator anim = GetComponent <Animator>(); if (horizontal != 0 || vertical != 0) { anim.SetBool("isWalking", true); } else { anim.SetBool("isWalking", false); } if (wasMovementReleased && horizontal == 0 && vertical == 0) { Debug.Log("Was released movement " + rigidbody.velocity); rigidbody.AddForce(rigidbody.velocity * 5); } else { rigidbody.velocity = new Vector2(horizontal * moveSpeed, vertical * moveSpeed); } if (horizontal < 0) { direction = Direction.Left; } else if (horizontal > 0) { direction = Direction.Right; } else if (vertical < 0) { direction = Direction.Down; } else if (vertical > 0) { direction = Direction.Up; } //Digging with shovel bool xButtonPressed = Gamepad.current != null ? Gamepad.current.xButton.wasPressedThisFrame : false; if ((Input.GetKeyDown(KeyCode.X) || xButtonPressed) && shovelMovesCount > 0 && canDig) { Tilemap ground = GameObject.Find("Ground").GetComponent <Tilemap>(); Vector3Int tilePosition = ground.WorldToCell(new Vector3(transform.position.x, transform.position.y + 0.3f, transform.position.z)); //ground.SetTile(tilePosition); Vector3 newPosition = ground.CellToWorld(tilePosition); Transform d = Instantiate(diggingHole) as Transform; StartCoroutine(DigAnimation()); d.position = new Vector3(newPosition.x + 0.1875f + 0.3125f, newPosition.y - 0.1875f - 0.3125f, 0); //If collided with diggable ship part -> Dig it out! if (diggablePart != null) { diggablePart.DigOut(); } if (aim != null && aim.hasHiddenPart) { aim.hasHiddenPart = false; } if (OnPlayerUsedShovel != null) { OnPlayerUsedShovel(); } shovelMovesCount--; } bool aButtonPressed = Gamepad.current != null ? Gamepad.current.aButton.wasPressedThisFrame : false; //Hit with shovel if ((Input.GetKeyDown(KeyCode.C) || aButtonPressed) && shovelMovesCount > 0) { Transform shovelhitbox = null; if (direction == Direction.Left) { shovelhitbox = transform.Find("ShovelHitboxLeft"); } else if (direction == Direction.Right) { shovelhitbox = transform.Find("ShovelHitboxRight"); } else if (direction == Direction.Up) { shovelhitbox = transform.Find("ShovelHitboxUp"); } else if (direction == Direction.Down) { shovelhitbox = transform.Find("ShovelHitboxDown"); } shovelhitbox.gameObject.SetActive(true); OnPlayerUsedShovel(); StartCoroutine(DeactivateShovelHitbox(shovelhitbox.gameObject)); } /* if (Input.GetKeyDown(KeyCode.LeftArrow)) * { * rigidbody.velocity = new Vector2(-moveSpeed, 0); * * //TODO: Animation left * * } * * else if (Input.GetKeyDown(KeyCode.RightArrow)) * { * rigidbody.velocity = new Vector2(moveSpeed, 0); * * } * * else if (Input.GetKeyDown(KeyCode.UpArrow)) * { * rigidbody.velocity = new Vector2(0, moveSpeed); * * } * else if (Input.GetKeyDown(KeyCode.DownArrow)) * { * rigidbody.velocity = new Vector2(0, -moveSpeed); * * }*/ }