Esempio n. 1
0
    void MovePlane()
    {
        if (useKeyboard)
        {
            float rotate = 0;
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                rotate = -1;
            }
            if (Input.GetKey(KeyCode.RightArrow))
            {
                rotate = 1;
            }

            transform.Rotate(Vector3.up * rotate * rotateSpeed);
            inputY = Input.GetKey(KeyCode.UpArrow) ? 1 : 0;
        }
        else
        {
            transform.Rotate(Vector3.up * InputPlus.GetData(controllerID, ControllerVarEnum.ThumbLeft_x) * rotateSpeed);
            inputY = Mathf.Clamp(InputPlus.GetData(controllerID, ControllerVarEnum.ShoulderBottom_right), 0, 1);
        }

        Vector3 moveDir          = new Vector3(0, 0, inputY);//.normalized;
        Vector3 targetMoveAmount = moveDir * (movementSpeed + boostModifier + movementModifier);

        moveAmount = Vector3.SmoothDamp(moveAmount, targetMoveAmount, ref smoothMoveVelocity, .15f);
    }
Esempio n. 2
0
 void checkStart()
 {
     if (InputPlus.GetData(controllerNum + 1, ControllerVarEnum.Interface_right) > 0)
     {
         ui.toggleStart();
     }
 }
Esempio n. 3
0
    public bool GetUp()
    {
        bool result = false;

        switch (Type)
        {
        case InputType.GamePad:
            bool temp = InputPlus.GetData(con, GamePadInput) != 0f || InputPlus.GetData(con, GamePadInputNegative) != 0f;
            if (!temp && previous_state_up)
            {
                result = true;
            }
            else
            {
                result = false;
            }
            previous_state_up = temp;
            break;

        case InputType.Buttons:
            result = Input.GetKeyUp(PositiveButton) || Input.GetKeyUp(NegativeButton);
            break;

        case InputType.MouseMovement:
            result = false;
            break;
        }
        return(result);
    }
Esempio n. 4
0
    }    //ListenForLearnRequest

    void ListenForDisplayMode()
    {
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            InputPlus.ToggleDataView();
        }
    }    //ListenForLearnRequest
Esempio n. 5
0
 void checkGarage()
 {
     if (inGarage && dpadCounter > 15)
     {
         float dpadX = InputPlus.GetData(controllerNum + 1, ControllerVarEnum.dpad_right) - InputPlus.GetData(controllerNum + 1, ControllerVarEnum.dpad_left);
         if (dpadX < 0)
         {
             //Debug.Log("left pushed");
             whichCar -= 1;
             if (whichCar < 0)
             {
                 whichCar = world.cars.Length - 1;
             }
             initCar();
             dpadCounter = 0;
         }
         else if (dpadX > 0)
         {
             whichCar += 1;
             if (whichCar >= world.cars.Length)
             {
                 whichCar = 0;
             }
             initCar();
             dpadCounter = 0;
         }
         //Debug.Log("dpadx = " + dpadX);
     }
     else
     {
         // Debug.Log("inGarage false");
     }
 }
Esempio n. 6
0
 public void update()
 {
     if (showing)
     {
         float inp      = -InputPlus.GetData(ui.controllerNum + 1, ControllerVarEnum.dpad_down) + InputPlus.GetData(ui.controllerNum + 1, ControllerVarEnum.dpad_up);
         float rightInp = InputPlus.GetData(ui.controllerNum + 1, ControllerVarEnum.dpad_right);
         if (rightInp == 0)
         {
             Debug.Log("inp = " + inp);
             if (inp > 0)
             {
                 Debug.Log("inp = " + inp);
                 moveUp();
             }
             else if (inp < 0)
             {
                 Debug.Log("inp = " + inp);
                 moveDown();
             }
         }
         else
         {
             actions[selected]();
         }
     }
 }
Esempio n. 7
0
    }    //Disconnect

    void ListenForLearnRequest()
    {
        //Check for controller programming request. In this case keys '1' - '9' will trigger
        //controllers 1-9 into learn mode, (only one at a time please!) and '0' and 'a' will trigger
        //controllers 10 and 11 respectively. You'll most likely want to build the learning mode into your
        //project's UI


        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            InputPlus.LearnController(1);
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            InputPlus.LearnController(2);
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            InputPlus.LearnController(3);
        }
        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            InputPlus.LearnController(4);
        }
        if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            InputPlus.LearnController(5);
        }
        if (Input.GetKeyDown(KeyCode.Alpha6))
        {
            InputPlus.LearnController(6);
        }
        if (Input.GetKeyDown(KeyCode.Alpha7))
        {
            InputPlus.LearnController(7);
        }
        if (Input.GetKeyDown(KeyCode.Alpha8))
        {
            InputPlus.LearnController(8);
        }
        if (Input.GetKeyDown(KeyCode.Alpha9))
        {
            InputPlus.LearnController(9);
        }
        if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            InputPlus.LearnController(10);
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            InputPlus.LearnController(11);
        }
        if (Input.GetKeyDown(KeyCode.Z))
        {
            //InputPlus.LearnControllerSingle(1, ControllerVarEnum.dpad_up);
            // LearnControllerSingle is currently an experimental feature, it's likely problems exist
        }
    }    //ListenForLearnRequest
Esempio n. 8
0
 override protected void SteeringStart()
 {
     //InputPlus.LearnController (1);
     InputPlus.Initialize(); //Start up InputPlus.
     InputPlus.SetDebugText(false);
     foreach (UnityLikeInput input in inputs)
     {
         input.con = GamePad_Num;
     }
     Input = new Input2(inputs);
 }
Esempio n. 9
0
 void checkCamToggle()
 {
     if (controllerNum != -1)
     {
         if (InputPlus.GetData(controllerNum + 1, ControllerVarEnum.ShoulderTop_left) > 0)
         {
             carCam.BroadcastMessage("toggle");
         }
     }
     //carCam.BroadcastMessage("setTarget", (car.transform));
 }
Esempio n. 10
0
    }    //~Cube

    void Start()
    {
        InputPlus.Initialize();         //Start up InputPlus.
        InputPlus.SetDebugText(true);   //Do you want to see Debug text from InputPlus?

        /* Subscribe to the disconnect event. This event happens when a controller is disconnected. Unfortunately
         * it doesn't seem like Unity's core control features (v4.3.4) handle connecting and reconnecting controllers during
         * execution in a standalone build. So it's STRONGLY recommended to condiser handling this event to allow a
         * game save. Hopefully this will change in the future */
        InputPlus.On_EVENT_Disconnect += Disconnect;
    }    //Start
Esempio n. 11
0
    void MoveStrafe()
    {
        Vector3 moveDir;

        if (useKeyboard)
        {
            //FORWARD MOVEMENT
            float inputY = Input.GetKey(KeyCode.UpArrow) ? 1 : 0;
            if (inputY == 0)
            {
                inputY = Input.GetKey(KeyCode.DownArrow) ? -1 : 0;
            }


            //ROTATION
            float rotate = 0;
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                rotate = -1;
            }
            if (Input.GetKey(KeyCode.RightArrow))
            {
                rotate = 1;
            }
            transform.Rotate(Vector3.up * rotate * rotateSpeed);

            //STRAFE LEFT OR RIGHT ...
            var strafe = Input.GetKey(KeyCode.A) ? -1 : 0;
            if (strafe == 0)
            {
                strafe = Input.GetKey(KeyCode.D) ? 1 : 0;
            }

            //move direction
            moveDir = new Vector3(strafe,
                                  0,
                                  inputY);
        }
        else
        {
            //rotate ship
            transform.Rotate(Vector3.up * InputPlus.GetData(controllerID, ControllerVarEnum.ThumbLeft_x) * rotateSpeed);

            //move direction - strafe enabled
            moveDir = new Vector3(InputPlus.GetData(controllerID, ControllerVarEnum.ThumbRight_x),
                                  0,
                                  InputPlus.GetData(controllerID, ControllerVarEnum.ThumbLeft_y) * -1);                                                       //.normalized;
        }

        Vector3 targetMoveAmount = moveDir * (movementSpeed + boostModifier + movementModifier);

        moveAmount = Vector3.SmoothDamp(moveAmount, targetMoveAmount, ref smoothMoveVelocity, .15f);
    }
Esempio n. 12
0
    }    //Start

    void Update()
    {
        float moveX, moveY;                                                       //How much to move along X and Y coordinates

        moveX = InputPlus.GetData(1, LeftRight);                                  //Read the controller's value for the assigned control
        moveY = -(InputPlus.GetData(1, UpDown));                                  //flip axis with negative
        Vector3 MoveVector  = new Vector3(moveX, 0, moveY);                       //Put the read values into a vector representing movement direction
        Vector3 CurrentPos  = transform.position;                                 //the current position
        Vector3 NewPosition = CurrentPos + (MoveVector * Speed * Time.deltaTime); //apply speed and use delaTime to compensate for framerate

        GetComponent <Rigidbody>().MovePosition(NewPosition);                     //Move the object there
    }                                                                             //Update
Esempio n. 13
0
    void UpdateStrafeControls()
    {
        if (player.useKeyboard)
        {
            if (Input.GetKeyDown(KeyCode.W))
            {
                InvokeRepeating("FirePrimary", float.Epsilon, primaryInterval);
            }
            else if (Input.GetKeyUp(KeyCode.W))
            {
                isPrimaryFiring = false;
                CancelInvoke("FirePrimary");
            }

            if (Input.GetKeyDown(KeyCode.E))
            {
                InvokeRepeating("FireSecondary", float.Epsilon, secondaryInterval);
            }
            else if (Input.GetKeyUp(KeyCode.E))
            {
                isPrimaryFiring = false;
                CancelInvoke("FireSecondary");
            }
        }
        else
        {
            float primaryFireButton = InputPlus.GetData(player.controllerID, ControllerVarEnum.ShoulderBottom_right);
            primaryFireButton = Mathf.Clamp(primaryFireButton, 0, 1);

            if (primaryFireButton > 0 && !isPrimaryFiring)
            {
                isPrimaryFiring = true;
                InvokeRepeating("FirePrimary", float.Epsilon, primaryInterval);
            }
            else if (primaryFireButton == 0 && isPrimaryFiring)
            {
                isPrimaryFiring = false;
                CancelInvoke("FirePrimary");
            }

            if (InputPlus.GetData(player.controllerID, ControllerVarEnum.ThumbRight) == 1f && !isSecondaryFiring)
            {
                InvokeRepeating("FireSecondary", float.Epsilon, secondaryInterval);
                isSecondaryFiring = true;
            }
            else if (InputPlus.GetData(player.controllerID, ControllerVarEnum.ThumbRight) == 0f && isSecondaryFiring)
            {
                CancelInvoke("FireSecondary");
                isSecondaryFiring = false;
            }
        }
    }
Esempio n. 14
0
 void OnGUI()
 {
     //Write out basic usage instructions
     GUILayout.Label("Welcome to InputPlus - Press Tab to cycle between Raw Data / Programmed Values / Off");
     GUILayout.Label("Press keys 1-9 to program corresponding controller. 0 and A for 10 and 11, respectively\n");
     if (InputPlus.GetProgrammingStatus())
     {
         GUI.DrawTexture(new Rect(360, 160, 160, 160), ControllerVarEnum_to_Texture(InputPlus.GetWaitingForControl()),
                         ScaleMode.ScaleToFit, true, 1.0f);
         GUILayout.Label("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" +
                         "Programming for " + InputPlus.GetControllerName(InputPlus.GetListeningFor()));
     } //Show image of the control InputPlus is waiting to program. Display the name of the controller.
 }     //OnGUI
Esempio n. 15
0
    }    //Start

    // Update is called once per frame
    void Update()
    {
        ListenForLearnRequest();        //Explained in declaration
        ListenForDisplayMode();         //Listen for 'Tab' to toggle InputPlus's on screen data

        if (InputPlus.GetProgrammingStatus())
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                InputPlus.CancelProgramming();
            }
        } //If the controller is receiving assignments the user can press 'Escape' to Cancel.
    }     //Update
Esempio n. 16
0
    void UpdatePlaneControls()
    {
        if (player.useKeyboard)
        {
            if (Input.GetKeyDown(KeyCode.W))
            {
                InvokeRepeating("FirePrimary", float.Epsilon, primaryInterval);
            }
            else if (Input.GetKeyUp(KeyCode.W))
            {
                isPrimaryFiring = false;
                CancelInvoke("FirePrimary");
            }

            if (Input.GetKeyDown(KeyCode.E))
            {
                InvokeRepeating("FireSecondary", float.Epsilon, secondaryInterval);
            }
            else if (Input.GetKeyUp(KeyCode.E))
            {
                isPrimaryFiring = false;
                CancelInvoke("FireSecondary");
            }
        }
        else
        {
            if (InputPlus.GetData(player.controllerID, ControllerVarEnum.FP_bottom) == 1f && !isPrimaryFiring)
            {
                InvokeRepeating("FirePrimary", float.Epsilon, primaryInterval);
                isPrimaryFiring = true;
            }
            else if (InputPlus.GetData(player.controllerID, ControllerVarEnum.FP_bottom) == 0f && isPrimaryFiring)
            {
                CancelInvoke("FirePrimary");
                isPrimaryFiring = false;
            }

            if (InputPlus.GetData(player.controllerID, ControllerVarEnum.FP_left) == 1f && !isSecondaryFiring)
            {
                InvokeRepeating("FireSecondary", float.Epsilon, secondaryInterval);
                isSecondaryFiring = true;
            }
            else if (InputPlus.GetData(player.controllerID, ControllerVarEnum.FP_left) == 0f && isSecondaryFiring)
            {
                CancelInvoke("FireSecondary");
                isSecondaryFiring = false;
            }
        }
    }
Esempio n. 17
0
    public bool Get()
    {
        bool result = false;

        switch (Type)
        {
        case InputType.GamePad:
            result = InputPlus.GetData(con, GamePadInput) != 0f || InputPlus.GetData(con, GamePadInputNegative) != 0f;
            break;

        case InputType.Buttons:
            result = Input.GetKey(PositiveButton) || Input.GetKey(NegativeButton);
            break;

        case InputType.MouseMovement:
            result = false;
            break;
        }
        return(result);
    }
Esempio n. 18
0
    void MoveTank()
    {
        Vector3 moveDir;

        if (useKeyboard)
        {
            //ROTATION
            float rotate = 0;
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                rotate = -1;
            }
            if (Input.GetKey(KeyCode.RightArrow))
            {
                rotate = 1;
            }
            transform.Rotate(Vector3.up * rotate * rotateSpeed);

            //MOVEMENT
            inputY = Input.GetKey(KeyCode.UpArrow) ? 1 : 0;
            if (inputY == 0)
            {
                inputY = Input.GetKey(KeyCode.DownArrow) ? -1 : 0;
            }
            moveDir = new Vector3(0, 0, inputY);
        }
        else
        {
            //ROTATION
            transform.Rotate(Vector3.up * InputPlus.GetData(controllerID, ControllerVarEnum.ThumbLeft_x) * rotateSpeed);
            //MOVEMENT
            moveDir = new Vector3(0, 0, InputPlus.GetData(controllerID, ControllerVarEnum.ThumbLeft_y) * -1);            //.normalized;
        }


        Vector3 targetMoveAmount = moveDir * (movementSpeed + boostModifier + movementModifier);

        //higher values make acceleration sluggish
        moveAmount = Vector3.SmoothDamp(moveAmount, targetMoveAmount, ref smoothMoveVelocity, 0.5f);
    }
Esempio n. 19
0
 void Update()
 {
     for (int i = 0; i < activeCars.Length; i++)
     {
         int ctrnum = PlayerPrefs.GetInt("p" + (i), -1) + 1;
         Debug.Log("p" + i + " has controller " + ctrnum);
         int j = i + 1;                                                       //because Input is 1 indexed
         counter[i]--;
         float exit = InputPlus.GetData(ctrnum, ControllerVarEnum.FP_bottom); //Input.GetAxis("SelectMenu"+j);
         //Debug.Log("exit = " + exit);
         if (exit > 0)
         {
             Application.LoadLevel("Car");
         }
         float hAxis = InputPlus.GetData(ctrnum, ControllerVarEnum.ThumbLeft_x); // Input.GetAxis("Horizontal"+j);
         float vAxis = InputPlus.GetData(ctrnum, ControllerVarEnum.ThumbLeft_y); // Input.GetAxis("Vertical"+j);
         doSwitches(i, hAxis, vAxis);
     }
     for (int i = 0; i < numControllers; i++)
     {
         if (i >= activeCars.Length)
         {
             var temp = InputPlus.GetData(i + 1, ControllerVarEnum.Interface_right);                //Input.GetAxis ("Start" + (i + 1).ToString ());
             //Debug.Log ("Start input = " + temp);
             if (temp > 0)
             {
                 int          wc          = PlayerPrefs.GetInt("whichCar" + (i + 1).ToString(), 0);
                 GameObject[] tempForCopy = new GameObject[i + 1];
                 for (int j = 0; j < activeCars.Length; j++)
                 {
                     tempForCopy [j] = activeCars [j];
                 }
                 tempForCopy [activeCars.Length] = instantiateCarAndPos(cars [wc], activeCars.Length);
                 activeCars = tempForCopy;
                 PlayerPrefs.SetInt("actualActive", activeCars.Length);
             }
         }
     }
 }
Esempio n. 20
0
    void GamePadControls()
    {
        if (!canPress)
        {
            return;
        }

        if (selectorState == SelectorState.WaitingToJoin)
        {
            //press A to add player
            if (InputPlus.GetData(controllerID, ControllerVarEnum.FP_bottom) == 1)
            {
                JoinGame();
                StartCoroutine("ButtonDelay");
            }
            return;
        }

        //game joined
//		if (joinedGame) {

        //no selection made
//			if (!selctionConfirmed) {
        if (selectorState == SelectorState.WaitingForShipSelection)
        {
            //press B to remove player
            if (InputPlus.GetData(controllerID, ControllerVarEnum.FP_right) == 1)
            {
                QuitGame();
                StartCoroutine("ButtonDelay");

                //ship select up and down
            }
            else if (InputPlus.GetData(controllerID, ControllerVarEnum.dpad_down) == 1)
            {
                NextSelection(1);
                StartCoroutine("ButtonDelay");
            }
            else if (InputPlus.GetData(controllerID, ControllerVarEnum.dpad_up) == 1)
            {
                NextSelection(-1);
                StartCoroutine("ButtonDelay");

                //press A to confirm player selection
            }
            else if (InputPlus.GetData(controllerID, ControllerVarEnum.FP_bottom) == 1)
            {
                ConfirmSelection();
                StartCoroutine("ButtonDelay");
            }
            return;
        }

        //selection made
//			if (selctionConfirmed) {
        if (selectorState == SelectorState.ShipSelected)
        {
            //press B to cancel player selection
            if (InputPlus.GetData(controllerID, ControllerVarEnum.FP_right) == 1)
            {
                UnConfirmSelection();
                menuController.CancelCountDown();
                StartCoroutine("ButtonDelay");
            }
            return;
        }



        if (selectorState == SelectorState.WaitingForPlanetSelection &&
            playerID == PlayerID.P1)
        {
            if (InputPlus.GetData(controllerID, ControllerVarEnum.dpad_up) == 1)
            {
                menuController.ChangePlanet(1);
                StartCoroutine("ButtonDelay");
            }
            else if (InputPlus.GetData(controllerID, ControllerVarEnum.dpad_down) == 1)
            {
                menuController.ChangePlanet(-1);
                StartCoroutine("ButtonDelay");
            }

            if (InputPlus.GetData(controllerID, ControllerVarEnum.FP_bottom) == 1)
            {
                menuController.ConfirmPlanet();
            }
        }
//		}
    }
Esempio n. 21
0
    public float GetAxis()
    {
        float result = 0f;

        switch (Type)
        {
        case InputType.GamePad:
            if (needsVirtual)
            {
                if (InputPlus.GetData(con, GamePadInput) == 1f)
                {
                    if (Snap && virtual_axis < 0f)
                    {
                        virtual_axis = 0;
                    }
                    virtual_axis += Sensivity * Time.deltaTime;
                }
                else if (InputPlus.GetData(con, GamePadInputNegative) == 1f)
                {
                    if (Snap && virtual_axis > 0f)
                    {
                        virtual_axis = 0;
                    }
                    virtual_axis -= Sensivity * Time.deltaTime;
                }
                else
                {
                    virtual_axis = Mathf.MoveTowards(virtual_axis, 0, Gravity * Time.deltaTime);
                }
                virtual_axis = Mathf.Clamp(virtual_axis, -1f, 1f);
                result       = virtual_axis;
            }
            else
            {
                result = InputPlus.GetData(con, GamePadInput) * Sensivity;
                result = Mathf.Clamp(result, -1f, 1f);
            }
            break;

        case InputType.Buttons:
            if (Input.GetKey(PositiveButton))
            {
                if (Snap && virtual_axis < 0f)
                {
                    virtual_axis = 0;
                }
                virtual_axis += Sensivity * Time.deltaTime;
            }
            else if (Input.GetKey(NegativeButton))
            {
                if (Snap && virtual_axis > 0f)
                {
                    virtual_axis = 0;
                }
                virtual_axis -= Sensivity * Time.deltaTime;
            }
            else
            {
                virtual_axis = Mathf.MoveTowards(virtual_axis, 0, Gravity * Time.deltaTime);
            }
            virtual_axis = Mathf.Clamp(virtual_axis, -1f, 1f);
            result       = virtual_axis;
            break;

        case InputType.MouseMovement:
            float inv = 1f;
            if (Invert)
            {
                inv = -1f;
            }
            switch (mouseAxis)
            {
            case MouseAxis.X:
                return(Input.GetAxis("Mouse X") * inv);

            case MouseAxis.Y:
                return(Input.GetAxis("Mouse Y") * inv);

            case MouseAxis.Scroll:
                return(Input.GetAxis("Mouse ScrollWheel") * inv);
            }
            break;
        }

        if (Mathf.Abs(result) < Dead)
        {
            return(0);
        }
        else
        {
            if (Invert)
            {
                result *= -1f;
            }
            return(result);
        }
    }
Esempio n. 22
0
    void FixedUpdate()
    {
        //chunkHandler.act();
        foreach (PlayerController p in players)
        {
            p.updateThis();
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.LoadLevel("Menu");
        }
        else if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            //chunkHandler.handleStep(new int[2] { 0, 2 }, new int[2] { 0, 3 });
        }
        for (int i = 0; i < numControllers; i++)
        {
            if (controllerNumToPlayerNum[i] == -1)                                   //controller not registered to car yet
            {
                if (InputPlus.GetData(i + 1, ControllerVarEnum.Interface_right) > 0) //if controller i is pressing start
                {
                    if (playerNumCounter < actualActive)                             //If the players all have controller assigned to them we need to create a new player
                    {
                        Debug.Log("Controller " + (i + 1) + " pushed start");
                        if (playerNumCounter < 2)//temporary becasue we don't handle more than 2 right now.
                        {
                            controllerNumToPlayerNum[i] = playerNumCounter;
                            playerNumToControllerNum[playerNumCounter] = i;
                            PlayerPrefs.SetInt("p" + playerNumCounter, i);
                            playerNumCounter++;
                            //TODO assigncontroller to car and handle that in the car's calls.
                            //activeCars[playerNumCounter - 1].BroadcastMessage("assignControllerNumber", i);
                            players[playerNumCounter - 1].setControllerNum(i);
                        }
                    }
                    else
                    {
                        Debug.Log("ctr " + i + " is trying to add player");

                        addPlayer(i + 1);
                    }
                }
                else if (controllerNumToPlayerNum[i] != -1 && controllerNumToPlayerNum[i] < actualActive)
                {
                    float resetPushed = InputPlus.GetData(playerNumToControllerNum[i] + 1, ControllerVarEnum.FP_top);//Input.GetAxis ("Reset"+(i+1).ToString ());
                    if (resetPushed > 0)
                    {
                        resetCounter++;
                        if (resetCounter == 60)
                        {
                            activeCars[i].BroadcastMessage("reset");
                        }
                    }
                    else
                    {
                        resetCounter = 0;
                    }
                }
                else
                {
                    var temp = InputPlus.GetData(i + 1, ControllerVarEnum.Interface_right);//("Start"+(i+1).ToString ());
                    if (temp > 0)
                    {
                    }
                }
            }
        }
    }
Esempio n. 23
0
    void UpdateTankControls()
    {
        if (player.useKeyboard)
        {
            //rotate turret
            float rot = Input.GetKey(KeyCode.D) ? 1 : 0;
            if (rot == 0)
            {
                rot = Input.GetKey(KeyCode.A) ? -1 : 0;
            }
            Debug.Log(rot);

            if (rot != 0f)
            {
                Vector3 a = transform.localRotation.eulerAngles;
                a.y += rot * 30f;
                transform.localRotation = Quaternion.Slerp(transform.localRotation, Quaternion.Euler(a), .1f);
            }
            if (Input.GetKeyDown(KeyCode.W))
            {
                InvokeRepeating("FirePrimary", float.Epsilon, primaryInterval);
            }
            else if (Input.GetKeyUp(KeyCode.W))
            {
                isPrimaryFiring = false;
                CancelInvoke("FirePrimary");
            }

            if (Input.GetKeyDown(KeyCode.S))
            {
                InvokeRepeating("FireSecondary", float.Epsilon, secondaryInterval);
            }
            else if (Input.GetKeyUp(KeyCode.S))
            {
                isPrimaryFiring = false;
                CancelInvoke("FireSecondary");
            }
        }
        else
        {
            //rotate turret
            float x = InputPlus.GetData(player.controllerID, ControllerVarEnum.ThumbRight_x);
            float y = InputPlus.GetData(player.controllerID, ControllerVarEnum.ThumbRight_y);
            if (x != 0.0f || y != 0.0f)
            {
                float angle = Mathf.Atan2(y, x) * Mathf.Rad2Deg;
                angle += 90f;
                transform.localRotation = Quaternion.Slerp(transform.localRotation, Quaternion.AngleAxis(angle, Vector3.up), .1f);
            }

            //fire weapons
            float inputY = InputPlus.GetData(player.controllerID, ControllerVarEnum.ShoulderBottom_right);
            inputY = Mathf.Clamp(inputY, 0, 1);

            if (inputY > 0 && !isPrimaryFiring)
            {
                isPrimaryFiring = true;
                InvokeRepeating("FirePrimary", float.Epsilon, primaryInterval);
            }
            else if (inputY == 0 && isPrimaryFiring)
            {
                isPrimaryFiring = false;
                CancelInvoke("FirePrimary");
            }

            if (InputPlus.GetData(player.controllerID, ControllerVarEnum.ThumbRight) == 1f && !isSecondaryFiring)
            {
                InvokeRepeating("FireSecondary", float.Epsilon, secondaryInterval);
                isSecondaryFiring = true;
            }
            else if (InputPlus.GetData(player.controllerID, ControllerVarEnum.ThumbRight) == 0f && isSecondaryFiring)
            {
                CancelInvoke("FireSecondary");
                isSecondaryFiring = false;
            }
        }
    }
Esempio n. 24
0
    public void FixedUpdate()
    {
        if (!frozen)
        {
            if (canDrive)
            {
                //Apply the accelerator pedal
                float acc = (InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ShoulderBottom_right) - InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ShoulderBottom_left)); //Input.GetAxis (getAxisString ("Accelerate")));
                //Debug.Log("acc = " + acc);
                float hAxis = (InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ThumbLeft_x));                                                                               //Input.GetAxis (getAxisString ("Horizontal"));
                float vAxis = (InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ThumbLeft_y));                                                                               //Input.GetAxis (getAxisString ("Vertical"));
                if (invertY)
                {
                    vAxis = -vAxis;
                }
                if (canDrive)
                {
                    //ApplyControls (acc, hAxis, vAxis, Input.GetAxis (getAxisString ("Boost")), Input.GetAxis (getAxisString ("EBrake")), Input.GetAxis (getAxisString ("Jump")), Input.GetAxis (getAxisString ("AxisToggle")));
                    ApplyControls(acc, hAxis, vAxis,
                                  InputPlus.GetData(ctrNum + 1, ControllerVarEnum.FP_bottom),
                                  InputPlus.GetData(ctrNum + 1, ControllerVarEnum.FP_left),
                                  InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ShoulderTop_right),
                                  InputPlus.GetData(ctrNum + 1, ControllerVarEnum.FP_left),
                                  InputPlus.GetData(ctrNum + 1, ControllerVarEnum.FP_top),
                                  InputPlus.GetData(ctrNum + 1, ControllerVarEnum.FP_right),
                                  new Vector2(InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ThumbRight_x), InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ThumbRight_x)));
                }
                //Debug.Log(Input.GetAxis(getAxisString("Vertical")));
                //setUIText();
                if (boostAmount > 500)
                {
                    boostLevel.startColor = Color.Lerp(Color.blue, Color.yellow, ((float)boostAmount - (maxBoost / 2)) / ((float)maxBoost / 2));
                }
                else
                {
                    boostLevel.startColor = Color.Lerp(Color.red, Color.blue, ((float)boostAmount) / ((float)maxBoost / 2));
                }
                boostLevel.startLifetime = Remap(boostAmount, 0, maxBoost, 0f, .45f);
            }
            else
            {
                Debug.Log("canDrive is false");
                BackLeftWheel.BrakeTorque  = 200000.0f;
                BackRightWheel.BrakeTorque = 200000.0f;
            }
        }
        else
        {
            Debug.Log("p " + playerNumber + ", ctr " + ctrNum + " frozen!");
            if (ctrNum > -1)
            {
                unfreeze();
            }
            this.transform.position = freezePos;
            this.transform.rotation = freezeRot;
        }
        fireCount++;
        RaycastHit[] result = Physics.RaycastAll(new Ray(transform.position, -Vector3.up));

        foreach (RaycastHit r in result)
        {
            string objName = r.transform.gameObject.name;
            string pat     = @".*_\d\d?_\d\d?_.*";
            Regex  reg     = new Regex(pat);
            Match  m       = reg.Match(objName);
            if (m.Success)
            {
                currentlyOn = r.transform.gameObject;
            }
        }
        //currentlyOn = FrontRightWheel.currentlyOn;
    }
Esempio n. 25
0
 public void FixedUpdate()
 {
     if (!frozen)
     {
         if (canDrive)
         {
             //Apply the accelerator pedal
             //float acc = (InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ShoulderBottom_right) - InputPlus.GetData(ctrNum + 1 , ControllerVarEnum.ShoulderBottom_left));//Input.GetAxis (getAxisString ("Accelerate")));
             float forward = InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ShoulderBottom_right);
             minRT   = Math.Min(forward, minRT);
             maxRT   = Math.Max(forward, maxRT);
             forward = Remap(forward, minRT, maxRT, 0, 1);
             float backward = InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ShoulderBottom_left);
             print("minRT = " + minRT);
             print("maxRT = " + maxRT);
             print("forward = " + forward);
             print("backward = " + backward);
             float acc   = forward - backward;
             float hAxis = (InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ThumbLeft_x));
             float vAxis = (InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ThumbLeft_y));
             if (invertY)
             {
                 vAxis = -vAxis;
             }
             if (canDrive)
             {
                 ApplyControls(acc, hAxis, vAxis,
                               InputPlus.GetData(ctrNum + 1, ControllerVarEnum.FP_bottom),
                               InputPlus.GetData(ctrNum + 1, ControllerVarEnum.FP_left),
                               InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ShoulderTop_right),
                               InputPlus.GetData(ctrNum + 1, ControllerVarEnum.FP_left),
                               InputPlus.GetData(ctrNum + 1, ControllerVarEnum.FP_top),
                               InputPlus.GetData(ctrNum + 1, ControllerVarEnum.FP_right),
                               new Vector2(InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ThumbRight_x), InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ThumbRight_y)),
                               InputPlus.GetData(ctrNum + 1, ControllerVarEnum.ShoulderTop_left));
             }
             //print(Input.GetAxis(getAxisString("Vertical")));
             //setUIText();
             if (boostAmount > 500)
             {
                 boostLevel.startColor = Color.Lerp(Color.blue, Color.yellow, ((float)boostAmount - (maxBoost / 2)) / ((float)maxBoost / 2));
             }
             else
             {
                 boostLevel.startColor = Color.Lerp(Color.red, Color.blue, ((float)boostAmount) / ((float)maxBoost / 2));
             }
             boostLevel.startLifetime = Remap(boostAmount, 0, maxBoost, 0f, .45f);
         }
         else
         {
             print("canDrive is false");
         }
     }
     else
     {
         print("p " + playerNumber + ", ctr " + ctrNum + " frozen!");
         if (ctrNum > -1)
         {
             unfreeze();
         }
         this.transform.position = freezePos;
         this.transform.rotation = freezeRot;
     }
     fireCount++;
     setBoostGrad();
 }
Esempio n. 26
0
    // Update is called once per frame
    void Update()
    {
        if (player.dummy)
        {
            return;
        }

        isBoosting = false;

        if (player.useKeyboard)
        {
            boostInput = Input.GetKey(KeyCode.LeftShift) ? 1 : 0;
        }
        else
        {
            boostInput = InputPlus.GetData(player.controllerID, ControllerVarEnum.ShoulderBottom_left);
        }
        boostInput = Mathf.Clamp(boostInput, 0, 1);

        if (boostInput > 0 && fuel > 0 && !blockBoost)
        {
            isBoosting = true;
        }

//		if (player.shipType == ShipType.Plane) {
//
//			boostInput = InputPlus.GetData (player.controllerID, ControllerVarEnum.ShoulderBottom_right);
//			boostInput = Mathf.Clamp (boostInput, 0, 1);
//
//			if (boostInput > 0 && fuel > 0 && !blockBoost) isBoosting = true;
//
//		} else if (player.shipType == ShipType.Tank) {
//			boostInput = InputPlus.GetData (player.controllerID, ControllerVarEnum.ShoulderBottom_left);
//			boostInput = Mathf.Clamp (boostInput, 0, 1);
//
//			if (boostInput > 0 && fuel > 0 && !blockBoost) isBoosting = true;
//
//		} else if (player.shipType == ShipType.Strafe) {
//
//
//		}


        //if (Input.GetButton("Boost_"+player.playerID) && fuel > 0 && !blockBoost) {
        if (isBoosting)
        {
            //deplete fuel
            fuel -= depletionRate;
            fuel  = Mathf.Clamp(fuel, 0, maxFuel);
            //increase player speed
            player.boostModifier = speedIncrease;
//			trail.enabled = true;
            if (!renderOn)
            {
                StartCoroutine("TrailOn");
                renderOn = true;
            }
        }
        else
        {
            //regen fuel
            fuel += regenRate;
            fuel  = Mathf.Clamp(fuel, 0, maxFuel);
            //set player speed back to normal
            player.boostModifier = 0;
//			trail.enabled = false;
            if (renderOn)
            {
                StartCoroutine("TrailOff");
                renderOn = false;
            }


            if (fuel > 3f)
            {
                blockBoost = false;
            }
            else
            {
                blockBoost = true;
            }
        }
    }