示例#1
0
    private void Update()
    {
        // input test
        if (enableKeyboard)
        {
            controller.SetActionState(eControllerActions.Jump, Input.GetKeyDown(KeyCode.Space));
            controller.SetActionState(eControllerActions.Left, Input.GetKey(KeyCode.Q));
            controller.SetActionState(eControllerActions.Right, Input.GetKey(KeyCode.D));
            controller.SetActionState(eControllerActions.Down, Input.GetKey(KeyCode.S));
            controller.SetActionState(eControllerActions.Up, Input.GetKey(KeyCode.Z));
            if (Input.GetKeyDown(KeyCode.A))
            {
                Interact();
            }
            if (Input.GetKeyDown(KeyCode.T))
            {
                heldElement.Throw();
                heldElement = null;
            }
        }

        if (singleAction || continousAction)
        {
            if (continousAction)
            {
                continousActionActive = true;
            }

            ButtonPressedMessage m = new ButtonPressedMessage();
            m.ButtonId = InputTest;
            ReceiveMessage(m);

            if (singleAction)
            {
                singleAction = false;
                ButtonPressedMessage m2 = new ButtonPressedMessage();
                m2.ButtonId = InputTest;
                ReceiveMessage(m2);
            }
        }

        if (!continousAction && continousActionActive)
        {
            ButtonReleasedMessage m = new ButtonReleasedMessage();
            m.ButtonId = InputTest;
            ReceiveMessage(m);
        }
        // end test

        if (nearestInteraction == null)
        {
            RemoveInteraction(null);
        }

        PlayerController ctl = GetComponent <PlayerController>();

        if (ctl.CanClimb && !CarrySomething)
        {
            ShowIndicator(false);
        }
        else
        {
            HideIndicator(false);
        }

        UpdateNearestInteraction();
    }
示例#2
0
    public void ReceiveMessage(Message mess)
    {
        if (mess is ButtonPressedMessage)
        {
            ButtonPressedMessage m = (ButtonPressedMessage)mess;

            switch (m.ButtonId)
            {
            case Buttons.B:
                controller.SetActionState(eControllerActions.Jump, true);
                break;

            case Buttons.A:
                Interact();
                break;

            case Buttons.Joystick:
                controller.SetActionState(eControllerActions.Left, false);
                controller.SetActionState(eControllerActions.Right, false);
                controller.SetActionState(eControllerActions.Down, false);
                controller.SetActionState(eControllerActions.Up, false);
                controller.SetActionState(TranslateJoystickInput(m.Extra1, m.Extra2), true);
                break;

            case Buttons.DPadLeft:
                controller.SetActionState(eControllerActions.Left, true);
                break;

            case Buttons.DPadRight:
                controller.SetActionState(eControllerActions.Right, true);
                break;

            case Buttons.DPadDown:
                controller.SetActionState(eControllerActions.Down, true);
                break;

            case Buttons.DPadUp:
                controller.SetActionState(eControllerActions.Up, true);
                break;
            }
        }
        else if (mess is ButtonReleasedMessage)
        {
            ButtonReleasedMessage m = (ButtonReleasedMessage)mess;

            switch (m.ButtonId)
            {
            case Buttons.DPadLeft:
            case Buttons.DPadRight:
            case Buttons.DPadDown:
            case Buttons.DPadUp:
            case Buttons.Joystick:
                controller.SetActionState(eControllerActions.Left, false);
                controller.SetActionState(eControllerActions.Right, false);
                controller.SetActionState(eControllerActions.Down, false);
                controller.SetActionState(eControllerActions.Up, false);
                break;

            case Buttons.B:
                controller.SetActionState(eControllerActions.Jump, false);
                break;

            case Buttons.A:
                break;
            }
        }
        else if (mess is ItemThrowMessage)
        {
            if (heldElement != null)
            {
                heldElement.Throw();
                heldElement = null;
                Socket.SendMessage(new UpdateItemMessage(0, "", ""));
            }
        }
    }