private float ReleaseTime; //tmp ? public SimpleButton(Vector2 position, Vector2 size, float reltime = 0.3f, CollisionType ctype = CollisionType.Rectangle, Texture2D textureoff = null, Texture2D textureon = null) { Position = position; Size = size; ReleasedTexture = textureoff; PressedTexture = textureon; // button area is set whatever collision type because it is also use for drawing if (ctype == CollisionType.Rectangle) { ButtonArea = new Rectangle((int)position.X, (int)position.Y, (int)Size.X, (int)size.Y); collisionType = CollisionType.Rectangle; } else { ButtonAreaCircle = new Circle(Size.X /2.0f, new Vector2(position.X, position.Y)); // a bit complicated this way ButtonArea = new Rectangle((int)position.X - (int)Size.X / 2, (int)position.Y - (int)Size.Y / 2, (int)Size.X, (int)size.Y); collisionType = CollisionType.Circle; } buttonState = buttonState.Released; currentTexture = ReleasedTexture; Enabled = true; EnableTint = false; tintColour = Color.White; pressedTime = 0; ReleaseTime = reltime; }
void InputBuffer() { if (Input.GetButtonDown("AOE")) { inputBuffer = buttonState.AOE; } if (Input.GetButtonDown("Special")) { inputBuffer = buttonState.Special; } if (Input.GetButtonDown("MovementAction")) { inputBuffer = buttonState.MovementAction; } if (Input.GetButtonDown("Left")) { inputBuffer = buttonState.Left; } if (Input.GetAxis("Heavy") > 0.1) { inputBuffer = buttonState.LeftHeavy; } if (Input.GetButtonDown("Right")) { inputBuffer = buttonState.Right; } if (Input.GetAxis("Heavy") < -0.1) { inputBuffer = buttonState.RightHeavy; } }
private void mouseDown(object sender, MouseEventArgs e) { Button button1 = (Button)sender; if (button1.Equals(up)) { button = buttonState.Up; } else if (button1.Equals(right)) { button = buttonState.Right; } else if (button1.Equals(down)) { button = buttonState.Down; } else if (button1.Equals(left)) { button = buttonState.Left; } buttonHoldtimer.Enabled = true; buttonHoldtimer.Start(); }
public void OnPointerUp(PointerEventData eventData) { if (state == buttonState.BEINGPRESSED) { state = buttonState.ACTIVATED; } }
// Update is called once per frame void Update () { buttonPos = transform.position.z; if ( buttonPos <= -0.09 ) { state = buttonState.ON; } else { state = buttonState.OFF; } }
// Update is called once per frame void Update() { switch (state) { case buttonState.DEACTIVATED: pressTime = 0.0f; break; //If a plan was loaded, we activate the button case buttonState.ACTIVATED: if (launchButtonGO.GetComponent <Image>().color.a < 0.5f) { launchButtonGO.GetComponent <Image>().color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); launchButtonGO.transform.GetChild(0).GetComponent <Text>().color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); //UnityEngine.Debug.Log("Activated"); } fillButton.sizeDelta = new Vector2(0.0f, 0.0f); pressTime = 0.0f; break; //If the button is being pressed, it has to wait for 5 seconds for security reasons, and then we send a takeoff case buttonState.BEINGPRESSED: pressTime += Time.deltaTime; fillButton.sizeDelta = new Vector2((pressTime * buttonWidth) / 5.0f, 0.0f); if (pressTime >= 5.0f) { clientUnity.client.SendCommand((byte)Modules.PLAN_EXECUTOR_MODULE, (byte)PlanExecutorCommandType.PLAN_EXEC_START); state = buttonState.FIVE_SEC_PRESSED; } break; case buttonState.FIVE_SEC_PRESSED: //UnityEngine.Debug.Log("5 sec pressed"); // A take off here will be necessary. The fc didn't work so we can't do it right now recordingPanel.SetActive(true); topCam.gameObject.GetComponent <PostRenderFront>().enabled = true; warningRecStart.SetActive(false); break; default: break; } }
//update public void update(GameTime gametime) { if (Input.EdgeDetectKeyDown(Keys.Right)) { this.buttonstate ++; } if (Input.EdgeDetectKeyDown(Keys.Left)) { this.buttonstate--; } if (this.buttonstate > buttonState.Quit) { buttonstate = buttonState.Start; } if (this.buttonstate < buttonState.Start) { buttonstate = buttonState.Quit; } if (Input.EdgeDetectKeyDown(Keys.Enter) && this.buttonstate == buttonState.Start ) { this.game.GameState = new PlayScene(game); } if (Input.EdgeDetectKeyDown(Keys.Enter) && this.buttonstate == buttonState.Load ) { this.game.GameState = new LoadScene(game); } if (Input.EdgeDetectKeyDown(Keys.Enter) && this.buttonstate == buttonState.Scores ) { this.game.GameState = new ScoreScene(game); } if (Input.EdgeDetectKeyDown(Keys.Enter) && this.buttonstate == buttonState.Help) { this.game.GameState = new HelpScene(game); } if (Input.EdgeDetectKeyDown(Keys.Enter) && this.buttonstate == buttonState.Editor) { this.game.GameState = new LevelEditorScene(game); } if (Input.EdgeDetectKeyDown(Keys.Enter) && this.buttonstate == buttonState.Quit) { this.game.GameState = new QuitScene(game); } if (Input.MouseRectangle().Intersects(this.start.Rectangle)) { this.buttonstate = buttonState.Start; if (Input.MouseEdgeDetectPressLeft() && this.buttonstate == buttonState.Start) { this.game.GameState = new PlayScene(this.game); } } else if (Input.MouseRectangle().Intersects(this.load.Rectangle)) { this.buttonstate = buttonState.Load; if (Input.MouseEdgeDetectPressLeft() && this.buttonstate == buttonState.Load) { this.game.GameState = new LoadScene(this.game); } } else if (Input.MouseRectangle().Intersects(this.help.Rectangle)) { this.buttonstate = buttonState.Help; if (Input.MouseEdgeDetectPressLeft() && this.buttonstate == buttonState.Help) { this.game.GameState = new HelpScene(this.game); } } else if (Input.MouseRectangle().Intersects(this.scores.Rectangle)) { this.buttonstate = buttonState.Scores; if (Input.MouseEdgeDetectPressLeft() && this.buttonstate == buttonState.Scores) { this.game.GameState = new ScoreScene(this.game); } } else if (Input.MouseRectangle().Intersects(this.editor.Rectangle)) { this.buttonstate = buttonState.Editor; if (Input.MouseEdgeDetectPressLeft() && this.buttonstate == buttonState.Editor) { this.game.GameState = new LevelEditorScene(this.game); } } else if (Input.MouseRectangle().Intersects(this.quit.Rectangle)) { this.buttonstate = buttonState.Quit; if (Input.MouseEdgeDetectPressLeft() && this.buttonstate == buttonState.Quit) { this.game.GameState = new QuitScene(this.game); } } }
// Update is called once per frame void Update() { moveDir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDir = transform.TransformDirection(moveDir); moveDir = Vector3.ClampMagnitude(moveDir, 1); playerVelocity.y = 0f; if (currentState == playerState.idle | currentState == playerState.walking) { inputBuffer = buttonState.none; } else { InputBuffer(); } if (currentState == playerState.shielding) { stamina.UseStamina(10 * Time.deltaTime, 120); if (stamina.GetStamina() == 0) { currentState = playerState.idle; } } if (delayMovement < 1 && (currentState != playerState.shielding | Input.GetButtonUp("Left"))) { if (moveDir.magnitude > 0.05f && IsGrounded()) { currentState = playerState.walking; anim.SetBool("Moving", true); } else { currentState = playerState.idle; anim.SetBool("Moving", false); } anim.SetBool("Action", false); } else if (delayDM > 0) { delayDM -= 60 * Time.deltaTime; delayDM = Mathf.Max(delayDM, 0); } else { delayMovement -= 60 * Time.deltaTime; } if (IsGrounded()) { playerVelocity -= Vector3.ClampMagnitude(playerVelocity, playerAccel * 0.75f); if ((currentState == playerState.firstAtk) && (inputBuffer == buttonState.Right) && delayMovement > 0) { if (delayMovement < 90 && stamina.GetStamina() >= 20) { anim.SetBool("Moving", false); anim.SetBool("Action", true); anim.SetInteger("ActionIndex", 10); currentState = playerState.secondAtk; delayMovement += 70; delayLook += 68; stamina.UseStamina(20, 120); } else { inputBuffer = buttonState.none; } } if (currentState == playerState.idle | currentState == playerState.walking | currentState == playerState.running | delayDM > 0) { if (currentState == playerState.walking | currentState == playerState.running | delayDM > 0) { playerVelocity += (playerAccel * moveDir); if (currentState != playerState.running) { playerVelocity = Vector3.ClampMagnitude(playerVelocity, playerMaxSpeed); } else { playerVelocity = playerVelocity + (transform.forward * 0.6f); playerVelocity = Vector3.ClampMagnitude(playerVelocity, playerMaxSpeed * 1.5f); } } if (Input.GetAxis("Heavy") > 0.1 && stamina.GetStamina() >= 30) { anim.SetBool("Moving", false); anim.SetBool("Action", true); anim.SetInteger("ActionIndex", 2); currentState = playerState.maxAtk; delayMovement = 80; delayLook = 70; delayDM = 30; delayDL = 60; stamina.UseStamina(30, 120); } if (Input.GetAxis("Heavy") < -0.1 && stamina.GetStamina() >= 15) { anim.SetBool("Moving", false); anim.SetBool("Action", true); anim.SetInteger("ActionIndex", 4); currentState = playerState.maxAtk; delayMovement = 80; delayLook = 70; delayDM = 30; delayDL = 60; stamina.UseStamina(15, 120); } if (Input.GetButtonDown("MovementAction") && stamina.GetStamina() >= 15) { anim.SetBool("Moving", false); anim.SetBool("Action", true); anim.SetInteger("ActionIndex", 5); currentState = playerState.running; delayMovement = 55; delayDM = 5; stamina.UseStamina(15, 120); } if (Input.GetButtonDown("Right") && stamina.GetStamina() >= 25) { if (currentState != playerState.firstAtk) { anim.SetBool("Moving", false); anim.SetBool("Action", true); anim.SetInteger("ActionIndex", 3); currentState = playerState.firstAtk; delayMovement = 144; delayLook = 75; delayDM = 5; delayDL = 75; stamina.UseStamina(25, 120); } } if (Input.GetButtonDown("AOE") && stamina.GetStamina() >= 35) { anim.SetBool("Moving", false); anim.SetBool("Action", true); anim.SetInteger("ActionIndex", 7); currentState = playerState.spin; spinTime = 420; delayMovement = 165; delayLook = 240; delayDM = 15; delayDL = 180; stamina.UseStamina(35, 120); } if (Input.GetButtonDown("Special") && stamina.GetStamina() >= 20) { anim.SetBool("Moving", false); anim.SetBool("Action", true); anim.SetInteger("ActionIndex", 6); currentState = playerState.maxAtk; delayMovement = 80; delayLook = 70; delayDM = 30; delayDL = 60; stamina.UseStamina(20, 120); } if (Input.GetButtonDown("Left") && stamina.GetStamina() >= 10) { anim.SetBool("Moving", false); anim.SetBool("Action", true); anim.SetInteger("ActionIndex", 1); currentState = playerState.shielding; stamina.UseStamina(10, 120); } } } if (spinTime > 0) { spinTime -= 60 * Time.deltaTime; playerVelocity = playerVelocity * 0.95f; } playerVelocity.y = rb.velocity.y; rb.velocity = (playerVelocity); gravity.y = gravityStrength; rb.AddForce(gravity); var cy = Input.GetAxis("CamHorizontal") * Time.deltaTime * cameraSpeed; if (delayLook < 1 | delayDL > 0) { delayDL -= 60 * Time.deltaTime; delayDL = Mathf.Max(delayDL, 0); v3Rotate.y += cy; } else { delayLook -= 60 * Time.deltaTime; } transform.localEulerAngles = v3Rotate; }
public virtual void Update(GameTime gameTime, bool click) { // NEED TO BE dupe inside update code of the child class to work (method is overriden !!) if (Enabled == false) return; // tint on hovering: // if mouse coord inside control area => change tint if (click == true) { if (collisionType == CollisionType.Rectangle) { Rectangle mouseclick = new Rectangle(Mouse.GetState().X - 2, Mouse.GetState().Y - 2, 4, 4); System.Diagnostics.Debug.Print(string.Format("SB upd mc={0}", mouseclick)); if (mouseclick.Intersects(ButtonArea)) { buttonState = buttonState.Pressed; pressedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; System.Diagnostics.Debug.Print(string.Format("SB upd click pt={0}", pressedTime)); } } else { Circle mouseclick = new Circle(2.5f, new Vector2(Mouse.GetState().X, Mouse.GetState().Y)); System.Diagnostics.Debug.Print(string.Format("SBcc upd mc={0}", mouseclick)); //if (mouseclick.Intersects(ButtonAreaCircle)) if (ButtonAreaCircle.Intersects(mouseclick)) { buttonState = buttonState.Pressed; pressedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; System.Diagnostics.Debug.Print(string.Format("SBcc upd click pt={0}", pressedTime)); } } } if (pressedTime >= ReleaseTime) { buttonState = buttonState.Released; pressedTime = 0; System.Diagnostics.Debug.Print(string.Format("SB upd rel pt={0}", pressedTime)); } if (buttonState == buttonState.Released) { currentTexture = ReleasedTexture; } else { currentTexture = PressedTexture; pressedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; System.Diagnostics.Debug.Print(string.Format("SB upd click pressed={0}", pressedTime)); } }
public void addButton(string button, buttonState state) { buttons.Add(button); states.Add(state); }