Beispiel #1
0
    void Update()
    {
        LeftStickX = -Input.GetAxis("Horizontal"); // left is +1, right is -1
        LeftStickY = -Input.GetAxis("Vertical");   // up is +1, down is -1

        // GetKey = active while held; GetKeyDown = active during the frame in which the button is pressed.
        // See http://wiki.unity3d.com/index.php?title=Xbox360Controller for button mappings (diagram here http://wiki.unity3d.com/index.php/File:X360Controller2.png)
        aButton         = Input.GetKey(KeyCode.Joystick1Button0);
        bButtonDown     = Input.GetKeyDown(KeyCode.Joystick1Button1);
        xButtonDown     = Input.GetKeyDown(KeyCode.Joystick1Button2);
        yButtonDown     = Input.GetKeyDown(KeyCode.Joystick1Button3);
        LeftBumperDown  = Input.GetKeyDown(KeyCode.Joystick1Button4);
        RightBumperDown = Input.GetKeyDown(KeyCode.Joystick1Button5);

        // right trigger is represented by range -1 to 0, left trigger by range 0 to 1
        Triggers = -Input.GetAxis("Triggers");


        // Movement
        Vector3 Forward = _Camera.transform.TransformDirection(Vector3.forward);
        Vector3 Left    = _Camera.transform.TransformDirection(Vector3.left);
        Vector3 Up      = _Camera.transform.TransformDirection(Vector3.up);

        speed = (aButton) ? moveSpeed * 1.7f : moveSpeed;
        if (LeftStickY != 0.0f)
        {
            transform.Translate(LeftStickY * Forward * speed * Time.deltaTime);
        }
        if (LeftStickX != 0.0f)
        {
            transform.Translate(LeftStickX * Left * speed * Time.deltaTime);
        }
        if (Triggers != 0.0f)
        {
            transform.Translate(Triggers * Up * speed * Time.deltaTime);
        }

        if (!movementOnly)
        {
            // Change neighbour counting range (i.e. highlight precision)
            if (RightBumperDown)
            {
                NBodyPlotter.DoubleNeighbourRadius();
            }
            if (LeftBumperDown)
            {
                NBodyPlotter.HalfNeighbourRadius();
            }

            // Cycle Data files
            if (bButtonDown)
            {
                CyclePlots.PreviousParticleData();
            }
            if (xButtonDown)
            {
                CyclePlots.NextParticleData();
            }
        }
    }
    // Update() is called once per frame
    void Update()
    {
        // Input.GetKeyDown() is true if the key gets pressed within that frame
        EscapeDown = Input.GetKeyDown(KeyCode.Escape);

        BackSpaceDown = Input.GetKeyDown(KeyCode.Backspace);
        EnterKeyDown  = Input.GetKeyDown(KeyCode.Return);

        F1KeyDown = Input.GetKeyDown(KeyCode.F1);

        UpArrowDown   = Input.GetKeyDown(KeyCode.UpArrow);
        DownArrowDown = Input.GetKeyDown(KeyCode.DownArrow);

        LeftArrowDown  = Input.GetKeyDown(KeyCode.LeftArrow);
        RightArrowDown = Input.GetKeyDown(KeyCode.RightArrow);


        // Quit Application
        if (EscapeDown)
        {
            Application.Quit();
        }

        // Enable or Disable user controller viewing
        if (BackSpaceDown)
        {
            MouseAndControllerLook.enabled = false;
        }
        if (EnterKeyDown)
        {
            MouseAndControllerLook.enabled = true;
        }

        // Enable/disable all inputs except movement from the controller
        if (F1KeyDown)
        {
            ControllerInput.movementOnly = !ControllerInput.movementOnly;
        }

        // Change neighbour counting range (i.e. highlight precision)
        if (UpArrowDown)
        {
            NBodyPlotter.DoubleNeighbourRadius();
        }
        if (DownArrowDown)
        {
            NBodyPlotter.HalfNeighbourRadius();
        }

        // Cycle Data files
        if (LeftArrowDown)
        {
            CyclePlots.PreviousParticleData();
        }
        if (RightArrowDown)
        {
            CyclePlots.NextParticleData();
        }
    }