private static void CheckButtonState(MouseState previousState, MouseState currentState) { if (previousState.LeftButton == ButtonState.Released && currentState.LeftButton == ButtonState.Pressed) { PressedMouseKey = MouseKeys.Left; PressedMouseKeyState = MouseKeyState.Clicked; } else if (previousState.LeftButton == ButtonState.Pressed && currentState.LeftButton == ButtonState.Pressed) { PressedMouseKey = MouseKeys.Left; PressedMouseKeyState = MouseKeyState.Held; } else if (previousState.LeftButton == ButtonState.Pressed && currentState.LeftButton == ButtonState.Released) { PressedMouseKey = MouseKeys.Left; PressedMouseKeyState = MouseKeyState.Released; } else if (previousState.RightButton == ButtonState.Released && currentState.RightButton == ButtonState.Pressed) { PressedMouseKey = MouseKeys.Right; PressedMouseKeyState = MouseKeyState.Clicked; } else if (previousState.RightButton == ButtonState.Pressed && currentState.RightButton == ButtonState.Pressed) { PressedMouseKey = MouseKeys.Right; PressedMouseKeyState = MouseKeyState.Held; } else if (previousState.RightButton == ButtonState.Pressed && currentState.RightButton == ButtonState.Released) { PressedMouseKey = MouseKeys.Right; PressedMouseKeyState = MouseKeyState.Released; } else if (previousState.MiddleButton == ButtonState.Released && currentState.MiddleButton == ButtonState.Pressed) { PressedMouseKey = MouseKeys.Middle; PressedMouseKeyState = MouseKeyState.Clicked; } else if (previousState.MiddleButton == ButtonState.Pressed && currentState.MiddleButton == ButtonState.Pressed) { PressedMouseKey = MouseKeys.Middle; PressedMouseKeyState = MouseKeyState.Held; } else if (previousState.MiddleButton == ButtonState.Pressed && currentState.MiddleButton == ButtonState.Released) { PressedMouseKey = MouseKeys.Middle; PressedMouseKeyState = MouseKeyState.Released; } else { PressedMouseKey = MouseKeys.None; PressedMouseKeyState = MouseKeyState.None; } }
protected override void OnUpdate() { foreach (InputEntity entity in GetEntities <InputEntity>()) { string horizontalAxisName = entity.inputMovement.horizontalAxisName; string verticalAxisName = entity.inputMovement.verticalAxisName; float holdTime = entity.inputMouse.holdTime; float startHold = entity.inputMouse.startHold; float horizontal = Input.GetAxis(horizontalAxisName); float vertical = Input.GetAxis(verticalAxisName); bool use1ButtonDown = Input.GetKey(KeyCode.Alpha1); bool use2ButtonDown = Input.GetKey(KeyCode.Alpha2); float3 mousePosition = Input.mousePosition; mousePosition = Camera.main.ScreenToWorldPoint(mousePosition); mousePosition.z = 0; bool leftDown = Input.GetMouseButton(0); bool rightDown = Input.GetMouseButton(1); MouseKeyState leftState = leftDown ? MouseKeyState.Down : MouseKeyState.Up; MouseKeyState rightState = rightDown ? MouseKeyState.Down : MouseKeyState.Up; if (leftDown && startHold <= 0) { startHold = Time.realtimeSinceStartup; } if (leftDown && startHold >= 0) { holdTime = Time.realtimeSinceStartup - startHold; } if (!leftDown) { holdTime = -1; startHold = -1; } entity.inputMovement.horizontal = horizontal; entity.inputMovement.vertical = vertical; entity.inputMouse.mousePosition = mousePosition; entity.inputMouse.leftState = leftState; entity.inputMouse.rightState = rightState; entity.inputMouse.holdTime = holdTime; entity.inputMouse.startHold = startHold; entity.inputUseComponent.use1ButtonDown = use1ButtonDown; entity.inputUseComponent.use2ButtonDown = use2ButtonDown; } }
protected override void OnUpdate() { float3 mousePos = float3.zero; foreach (Input entity in GetEntities <Input>()) { mousePos = entity.inputMouseComponent.mousePosition; MouseKeyState rightState = entity.inputMouseComponent.rightState; MouseKeyState leftState = entity.inputMouseComponent.leftState; bool rangedPress = leftState == MouseKeyState.Down; bool meleePress = rightState == MouseKeyState.Down; entity.inputAttackComponent.rangedPress = rangedPress; entity.inputAttackComponent.meleePress = meleePress; } foreach (Player entity in GetEntities <Player>()) { entity.rangedAttackComponent.endPoint = mousePos; } }