예제 #1
0
    public void Progress(float timeStep)
    {
        Touch touch         = default(Touch);
        bool  touchingRight = false;
        bool  touchingLeft  = false;

        if (gameController != null)
        {
            if (challengeStage != null)
            {
                if (controlsEnabled)
                {
                    if (loadVirtualKeypad)
                    {
                        /*halmeida - there's a bug which causes the non-triggering of the OnPointerUp event callback.
                         * When the OnPointerUp is not triggered, the character keeps moving locked to a direction, even
                         * though no touch is happening at the movement half of the screen. It seems to happen when the
                         * movement and aiming touches are alternated fast. Causing it on purpose seems harder than it
                         * happening in the game. It happens a lot when playing normally on the phone. To correct this,
                         * we need to always check if there is a touch still happening to keep the movement or the
                         * aiming.*/
                        if (Input.GetMouseButton(0))
                        {
                            if (Input.mousePosition.x < halfCanvasScreenWidth)
                            {
                                touchingLeft = true;
                            }
                            else
                            {
                                touchingRight = true;
                            }
                        }
                        for (int i = 0; i < Input.touchCount; i++)
                        {
                            touch = Input.GetTouch(i);
                            if (touch.position.x < halfCanvasScreenWidth)
                            {
                                touchingLeft = true;
                            }
                            else
                            {
                                touchingRight = true;
                            }
                        }
                        if (!touchingLeft)
                        {
                            ReleaseLeftStick();
                            ProvideInputDirection(true);
                        }
                        if (!touchingRight)
                        {
                            ReleaseRightStick();
                            ProvideInputDirection(false);
                        }
                    }
                    else
                    {
                        if (Input.GetKeyDown(KeyCode.W))
                        {
                            challengeStage.ReactToUpKey(-1, true, true);
                        }
                        if (Input.GetKeyUp(KeyCode.W))
                        {
                            challengeStage.ReactToUpKey(-1, true, false);
                        }
                        if (Input.GetKeyDown(KeyCode.A))
                        {
                            challengeStage.ReactToLeftKey(-1, true, true);
                        }
                        if (Input.GetKeyUp(KeyCode.A))
                        {
                            challengeStage.ReactToLeftKey(-1, true, false);
                        }
                        if (Input.GetKeyDown(KeyCode.S))
                        {
                            challengeStage.ReactToDownKey(-1, true, true);
                        }
                        if (Input.GetKeyUp(KeyCode.S))
                        {
                            challengeStage.ReactToDownKey(-1, true, false);
                        }
                        if (Input.GetKeyDown(KeyCode.D))
                        {
                            challengeStage.ReactToRightKey(-1, true, true);
                        }
                        if (Input.GetKeyUp(KeyCode.D))
                        {
                            challengeStage.ReactToRightKey(-1, true, false);
                        }
                        if (Input.GetKeyDown(KeyCode.UpArrow))
                        {
                            challengeStage.ReactToUpKey(-1, false, true);
                        }
                        if (Input.GetKeyUp(KeyCode.UpArrow))
                        {
                            challengeStage.ReactToUpKey(-1, false, false);
                        }
                        if (Input.GetKeyDown(KeyCode.LeftArrow))
                        {
                            challengeStage.ReactToLeftKey(-1, false, true);
                        }
                        if (Input.GetKeyUp(KeyCode.LeftArrow))
                        {
                            challengeStage.ReactToLeftKey(-1, false, false);
                        }
                        if (Input.GetKeyDown(KeyCode.DownArrow))
                        {
                            challengeStage.ReactToDownKey(-1, false, true);
                        }
                        if (Input.GetKeyUp(KeyCode.DownArrow))
                        {
                            challengeStage.ReactToDownKey(-1, false, false);
                        }
                        if (Input.GetKeyDown(KeyCode.RightArrow))
                        {
                            challengeStage.ReactToRightKey(-1, false, true);
                        }
                        if (Input.GetKeyUp(KeyCode.RightArrow))
                        {
                            challengeStage.ReactToRightKey(-1, false, false);
                        }
                        if (Input.GetKeyDown(KeyCode.Space))
                        {
                            OnPressSpace(null);
                        }
                        if (Input.GetKeyDown(KeyCode.Return))
                        {
                            OnPressReturn();
                        }
                        if (Input.GetKeyDown(KeyCode.Escape))
                        {
                            OnPressEscape();
                        }
                    }
                }
                else
                {
                    if (!loadVirtualKeypad)
                    {
                        if (Input.GetKeyDown(KeyCode.Return))
                        {
                            OnPressReturn();
                        }
                        if (Input.GetKeyDown(KeyCode.Escape))
                        {
                            OnPressEscape();
                        }
                    }
                }
            }
            else
            {
                if (challengeEditor != null)
                {
                    if (Input.GetKeyDown(KeyCode.Return))
                    {
                        challengeEditor.ReactToReturnKeyDown();
                    }
                    if (Input.GetKeyDown(KeyCode.Escape))
                    {
                        challengeEditor.ReactToEscapeKeyDown();
                    }
                    if (Input.GetKeyDown(KeyCode.Space))
                    {
                        challengeEditor.ReactToSpaceKey(true);
                    }
                    if (Input.GetKeyUp(KeyCode.Space))
                    {
                        challengeEditor.ReactToSpaceKey(false);
                    }
                    if (Input.GetKeyDown(KeyCode.F))
                    {
                        challengeEditor.ReactToFarCameraKey(true);
                    }
                    if (Input.GetKeyUp(KeyCode.F))
                    {
                        challengeEditor.ReactToFarCameraKey(false);
                    }
                    if (Input.GetKeyDown(KeyCode.S))
                    {
                        challengeEditor.ReactToSaveKey();
                    }
                    if (Input.GetKeyDown(KeyCode.L))
                    {
                        challengeEditor.ReactToLoadKey();
                    }
                }
                if (challengeCanvas != null)
                {
                    if (Input.GetKeyDown(KeyCode.LeftArrow))
                    {
                        challengeCanvas.ReactToLeftKey(true);
                    }
                    if (Input.GetKeyUp(KeyCode.LeftArrow))
                    {
                        challengeCanvas.ReactToLeftKey(false);
                    }
                    if (Input.GetKeyDown(KeyCode.RightArrow))
                    {
                        challengeCanvas.ReactToRightKey(true);
                    }
                    if (Input.GetKeyUp(KeyCode.RightArrow))
                    {
                        challengeCanvas.ReactToRightKey(false);
                    }
                    if (Input.GetKeyDown(KeyCode.UpArrow))
                    {
                        challengeCanvas.ReactToUpKey(true);
                    }
                    if (Input.GetKeyUp(KeyCode.UpArrow))
                    {
                        challengeCanvas.ReactToUpKey(false);
                    }
                    if (Input.GetKeyDown(KeyCode.DownArrow))
                    {
                        challengeCanvas.ReactToDownKey(true);
                    }
                    if (Input.GetKeyUp(KeyCode.DownArrow))
                    {
                        challengeCanvas.ReactToDownKey(false);
                    }
                }
            }
        }
    }