コード例 #1
0
    private void Update()
    {
        if (Input.GetKey("a"))
        {
            OnLeftPressed?.Invoke();
        }

        if (Input.GetKey("d"))
        {
            OnRightPressed?.Invoke();
        }
    }
コード例 #2
0
ファイル: InputManager.cs プロジェクト: Wclld/Tetris
    private void CheckInput()
    {
        if (Input.GetKeyDown(KeyCode.LeftArrow)) // checking for input of specific key
        {
            OnLeftPressed.Invoke(MoveSide.Left);
        }

        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            OnRightPressed.Invoke(MoveSide.Right);
        }

        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            OnUpPressed.Invoke();
        }

        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            OnDownPressed.Invoke();
        }
    }
コード例 #3
0
        /// <summary>
        /// Checks to see whether the attached base object's collider is pressed and if so triggers the appropriate event
        /// </summary>
        /// <param name="elapsedGameTime"></param>
        /// <param name="mousePosition"></param>
        public override void HandleInput(float elapsedGameTime, Vector2 mousePosition)
        {
            base.HandleInput(elapsedGameTime, mousePosition);

            DebugUtils.AssertNotNull(AttachedBaseObject.Collider);

            if (AttachedBaseObject.Collider.IsPressed)
            {
                Debug.Assert(OnLeftPressed != null && OnMiddlePressed != null && OnRightPressed != null);

                if (OnLeftPressed != null &&
                    InputManager.Instance.CheckInputEvent(InputManager.ScreenPressed, new object[] { MouseButton.kLeftButton }))
                {
                    OnLeftPressed.Invoke(AttachedBaseObject);
                }
                else if (OnMiddlePressed != null &&
                         InputManager.Instance.CheckInputEvent(InputManager.ScreenPressed, new object[] { MouseButton.kMiddleButton }))
                {
                    OnMiddlePressed.Invoke(AttachedBaseObject);
                }
                else if (OnRightPressed != null &&
                         InputManager.Instance.CheckInputEvent(InputManager.ScreenPressed, new object[] { MouseButton.kRightButton }))
                {
                    OnRightPressed.Invoke(AttachedBaseObject);
                }
            }
            else
            {
                if (PressedLastFrame)
                {
                    OnReleased.Invoke(AttachedBaseObject);
                }
            }

            PressedLastFrame = AttachedBaseObject.Collider.IsPressed;
        }
コード例 #4
0
        public void StartListerning()
        {
            while (true)
            {
                ConsoleKeyInfo key = Console.ReadKey(true);
                if (key.Key.Equals(ConsoleKey.LeftArrow))
                {
                    OnLeftPressed?.Invoke(this, new EventArgs());
                }

                if (key.Key.Equals(ConsoleKey.RightArrow))
                {
                    OnRightPressed?.Invoke(this, new EventArgs());
                }

                if (key.Key.Equals(ConsoleKey.Spacebar))
                {
                    OnSpacePressed?.Invoke(this, new EventArgs());
                }

                if (key.Key.Equals(ConsoleKey.R))
                {
                    OnKeyRPressed?.Invoke(this, new EventArgs());
                }

                if (key.Key.Equals(ConsoleKey.Q))
                {
                    OnKeyQPressed?.Invoke(this, new EventArgs());
                }

                if (key.Key.Equals(ConsoleKey.Escape))
                {
                    OnEscPressed?.Invoke(this, new EventArgs());
                }
            }
        }
コード例 #5
0
        private void NotifyLeftPressed()
        {
            OnLeftPressed?.Invoke();

            SayToLog("Left pressed.");
        }