GetButtonDown() public method

Returns true if "button" is pressed down this instant.
public GetButtonDown ( PSMoveButton b ) : bool
b PSMoveButton
return bool
Esempio n. 1
0
        /**
         *  Update write mode
         *  Modify the texte of current selected object.
         *
         */
        private void updateWriteMode(ref MoveController moveObj, ref UniMoveController move)
        {
            //update psmove rotation
            moveObj.gameObject.transform.localRotation = new Quaternion(move.Orientation.x, -move.Orientation.y, -move.Orientation.z, move.Orientation.w);

            if (move.GetButtonDown(PSMoveButton.Circle))
            {
                //We remove the last letter because it's only a letter to show the next letter to add.
                String newText = this.textMesh.text.Substring(0, this.textMesh.text.Length - 1);
                renameAction.NewName = newText;
                base.managerListener.doAction(renameAction);

                this.writeMode = false;
                this.textMesh  = null;
                return;
            }

            StringBuilder textPanel = new StringBuilder(this.textMesh.text);

            if (move.GetButtonDown(PSMoveButton.Square))
            {
                // remove last letter
                textPanel.Length = (textPanel.Length > 1) ? textPanel.Length - 1 : 1;
            }
            else if (move.GetButtonDown(PSMoveButton.Triangle))
            {
                // add letter
                textPanel.Append(ALPHABET[indexAlphabet]);
            }
            else
            {
                //change last letter
                float z    = moveObj.transform.rotation.eulerAngles.z;
                int   step = 360 / ALPHABET.Length;
                this.indexAlphabet = (int)(z / step);

                if (indexAlphabet >= ALPHABET.Length)
                {
                    indexAlphabet = 0;
                }
                textPanel[textPanel.Length - 1] = ALPHABET[indexAlphabet];
            }

            //update the text panel
            this.textMesh.text = textPanel.ToString();
        }
Esempio n. 2
0
        private void updateButtonTrigger(ref UniMoveController move)
        {
            if (move.GetButtonDown(PSMoveButton.Trigger))
            {
                buttonTriggerIsDown = true;
            }

            if (move.GetButtonUp(PSMoveButton.Trigger))
            {
                buttonTriggerIsDown = false;
            }
        }
Esempio n. 3
0
 void Update()
 {
     if (move.GetButtonDown(PSMoveButton.Circle))
     {
         Debug.Log("Circle click");
         canMove = !canMove;
     }
     if (canMove)
     {
         transform.localRotation = move.Orientation;
         transform.localPosition = move.Position;
     }
 }
Esempio n. 4
0
        /**
         *  Update the ray
         *
         *  Draw a ray from Psmove to retrieve the object selected.
         */
        private void updateRay(ref UniMoveController move, ref MoveController moveObj)
        {
            Transform  sphereTransform  = moveObj.transform.Find("Sphere");
            Transform  capsuleTransform = moveObj.transform.Find("Capsule");
            Vector3    heading          = sphereTransform.position - capsuleTransform.transform.position;
            Vector3    direction        = heading.normalized;
            RaycastHit hit;
            Ray        ray = new Ray(sphereTransform.position, direction);

            Boolean haveCollision = Physics.Raycast(ray, out hit);

            if (haveCollision && move.GetButtonDown(PSMoveButton.Move))
            {
                if (objectSelected == null || objectSelected != hit.collider.gameObject)
                {
                    GameObject obj = hit.collider.gameObject;
                    selectCollisionObject(ref obj);
                    this.moveAction = new MoveAction(obj);
                }
                else
                {
                    if (this.objectSelected != null)
                    {
                        Vector3 position = this.objectSelected.transform.localPosition;
                        this.moveAction.NewLocation = new Vector3(position.x, position.y, position.z);
                        base.managerListener.doAction(this.moveAction);
                    }

                    deselectCollisionObject();
                }
            }

            if (this.objectSelected != null && buttonTriggerIsDown)
            {
                float   distance = Vector3.Distance(moveObj.transform.position, this.objectSelected.transform.position);
                float   z        = this.objectSelected.transform.localPosition.z;
                Vector3 location = moveObj.transform.position + direction * distance;
                location.z = z;
                this.objectSelected.transform.localPosition = location;
            }

            Debug.DrawRay(sphereTransform.position, direction * 10, Color.green);
        }
Esempio n. 5
0
 // Update is called once per frame
 void Update()
 {
     if (move.GetButtonDown(PSMoveButton.Start))
     {
         canMove = true;
         if (canMove)
         {
             if (!alreadyStarted)
             {
                 Messenger.Broadcast(GameEvent.START_GAME);
                 alreadyStarted = true;
             }
         }
     }
     if (canMove)
     {
         Vector3 newPosition = new Vector3(move.Position.x / 20, move.Position.y / 10, positionZ);
         transform.localPosition = newPosition;
     }
 }
Esempio n. 6
0
    void Update()
    {
        GetComponent <SpriteRenderer>().sprite = hand;

        Vector3 newPosition = new Vector3(move.Position.x, move.Position.y, -315);

        transform.localPosition = newPosition;

        pointerEventData.position = Camera.main.WorldToScreenPoint(transform.position);

        List <RaycastResult> results = new List <RaycastResult>();

        graphicRaycaster.Raycast(pointerEventData, results);
        if (move.GetButtonDown(PSMoveButton.Move))
        {
            GetComponent <SpriteRenderer>().sprite = hand_click;
            if (results.Count > 0)
            {
                results[0].gameObject.GetComponentInParent <MainMenuButton>().goToScene();
            }
        }
    }
Esempio n. 7
0
    void FixedUpdate()
    {
        /* Move Meter Arrow */
        if (arrow.transform.position.x < rightBorder && right)
        {
            arrow.transform.position += new Vector3(arrowSpeed, 0, 0);
            throwSpeedCount++;
        }
        if (arrow.transform.position.x >= rightBorder)
        {
            right = false;
        }
        if (right == false)
        {
            arrow.transform.position -= new Vector3(arrowSpeed, 0, 0);
            throwSpeedCount--;
        }
        if (arrow.transform.position.x <= leftBorder)
        {
            right = true;
        }

        foreach (UniMoveController move in moves) {
            if (move.Disconnected) {
                currentMove = null;
                continue;
            }
            currentMove = move;
            move.SetRumble (move.Trigger);
        }

        /* Shoot ball on Tap */
        //if ((Input.GetButton("Fire1") || move.GetButtonDown(PSMoveButton.Trigger)) && !thrown && availableShots > 0 && shootBlocked==false)
        bool shootButtonDown;
        if (currentMove == null)
            shootButtonDown = false;
        else
            shootButtonDown = currentMove.GetButtonDown (PSMoveButton.Trigger);
        if ((Input.GetButton("Fire1") || shootButtonDown) && !thrown && availableShots > 0 && shootBlocked==false)
        {
            //Debug.Log(moves[0].Acceleration.x);
            shootBlocked=true;
            arrowSpeed=0;
            thrown = true;
            availableShots--;
            //availableShotsGO.GetComponent().text = availableShots.ToString();
            availableShotsGO.GetComponent<GUIText>().text = availableShots.ToString();

            Vector3 playerPos = Player.transform.position;
            ballPos.x=playerPos.x+0.234f;
            ballPos.y=playerPos.y+1.4509f;
            ballPos.z=playerPos.z-0.0234f;
            ballClone = Instantiate(ball, ballPos, transform.rotation) as GameObject;
            respawnControl=false;

            if (throwSpeedCount*difficulty>97 && throwSpeedCount*difficulty<123) // Bem no meio
                throwSpeedMultiplier=11;
            else
                throwSpeedMultiplier=(throwSpeedCount*difficulty)/10;

            if (throwSpeedMultiplier==12) throwSpeedMultiplier=12.5f; // BUG FIX (Gambiarra)

            hoopRing = GameObject.Find ("Ring");
            Vector3 heading = hoopRing.transform.position - Player.transform.position;
            throwSpeed.x = heading.x;
            throwSpeed.z = heading.z + Player.transform.rotation.y/1000;
            throwSpeed.y = heading.y + throwSpeedMultiplier-2.5f;

            ballClone.GetComponent<Rigidbody>().AddForce(throwSpeed, ForceMode.Impulse);

            GetComponent<AudioSource>().Play(); //play shoot sound
        }

        /* Remove Ball when it hits the floor */
        if (ballClone != null && ballClone.transform.position.y < 0.25)
        { /* Fim da rodada */

            Destroy(ballClone,3);
            thrown = false;
            throwSpeed = new Vector3(3, 10, 0);//Reset perfect shot variable
            switch (difficulty) {
                case 1: arrowSpeed=0.001f; break;
                case 2: arrowSpeed=0.002f; break;
                case 3: arrowSpeed=0.003f; break;
                case 4: arrowSpeed=0.004f; break;
            }
            arrow.transform.position = new Vector3(leftBorder,0.487829f,0);
            right=true;
            throwSpeedCount=0;

            //Component TimerScript = GetComponent(Timer);

            Respawn ();
            StartCoroutine(enableShoot()); // Destrava o click

            /* Check if out of shots */

            if (availableShots == 0)
            {
                //arrow.renderer.enabled = false;
                arrow.GetComponent<GUITexture>().enabled=false;
                Invoke("restart", 2);
            }
        }

        /*if (timerScript.getCurrentTime()<=0){
            //Debug.Log ("Time Over!");
            arrow.guiTexture.enabled = false;
            //timerScript.restartTimer();
        //	TimerHUD = null;
        //	timerScript = null;
            //Destroy(TimerHUD);
            //availableShots = 0;
            timerScript.restartTimer();
            Invoke ("restart", 2);
        }*/
    }
Esempio n. 8
0
    // Update is called once per frame
    void Update()
    {
        if (!isGameOver && move != null)
        {
            if (move.GetButtonDown(PSMoveButton.Move))
            {
                move.ResetOrientation();
                canMove = true;
            }

            if (canMove)
            {
                if (move.GetButtonDown(PSMoveButton.Circle))
                {
                    circleButtonDown = true;
                }

                if (circleButtonDown)
                {
                    turboBar.GetComponent <Image>().fillAmount -= 0.2f;
                    actualVelocity = turboVelocity;
                    if (turboBar.GetComponent <Image>().fillAmount <= 0)
                    {
                        actualVelocity   = standardVelocity;
                        circleButtonDown = false;
                    }
                }

                turboBar.GetComponent <Image>().fillAmount += 0.01f;

                if (move.GetButtonDown(PSMoveButton.Cross))
                {
                    switch (activeCamera)
                    {
                    case 0:
                        insideCamera.enabled  = false;
                        topCamera.enabled     = false;
                        farCamera.enabled     = false;
                        outsideCamera.enabled = true;
                        canvas.GetComponent <Canvas>().worldCamera = outsideCamera;
                        break;

                    case 1:
                        insideCamera.enabled  = true;
                        topCamera.enabled     = false;
                        farCamera.enabled     = false;
                        outsideCamera.enabled = false;
                        canvas.GetComponent <Canvas>().worldCamera = insideCamera;
                        break;

                    case 2:
                        insideCamera.enabled  = false;
                        topCamera.enabled     = false;
                        farCamera.enabled     = true;
                        outsideCamera.enabled = false;
                        canvas.GetComponent <Canvas>().worldCamera = farCamera;
                        break;

                    case 3:
                        insideCamera.enabled  = false;
                        topCamera.enabled     = true;
                        farCamera.enabled     = false;
                        outsideCamera.enabled = false;
                        canvas.GetComponent <Canvas>().worldCamera = topCamera;
                        break;
                    }

                    if (insideCamera.enabled)
                    {
                        cockpit.SetActive(true);
                    }
                    else
                    {
                        cockpit.SetActive(false);
                    }

                    activeCamera++;
                    if (activeCamera == 4)
                    {
                        activeCamera = 0;
                    }
                }

                if (move.Trigger > 0)
                {
                    if (!isReloading)
                    {
                        if (shootBar.GetComponent <Image>().fillAmount > 0)
                        {
                            if (!isPlayingSound)
                            {
                                audioSource.GetComponent <AudioController>().SetLoop(true);
                                audioSource.GetComponent <AudioController>().PlayAudioClip(1); // play laser sound
                                isPlayingSound = true;
                                move.SetRumble(1f);
                            }
                            shootBar.GetComponent <Image>().fillAmount -= 0.01f;
                            Instantiate(bullet, bulletSpawnerLeft.transform.position, bulletSpawnerLeft.transform.rotation);
                            Instantiate(bullet, bulletSpawnerRight.transform.position, bulletSpawnerRight.transform.rotation);
                        }
                    }
                    else
                    {
                        audioSource.GetComponent <AudioController>().SetLoop(false);
                        isPlayingSound = false;
                        move.SetRumble(0f);
                    }
                }
                else
                {
                    audioSource.GetComponent <AudioController>().SetLoop(false);
                    isPlayingSound = false;
                    move.SetRumble(0f);
                }

                if (shootBar.GetComponent <Image>().fillAmount <= 0 && !isReloading)
                {
                    StartCoroutine("reloadBar");
                }


                rigidbody.velocity = transform.forward * actualVelocity;

                float Ymove     = move.Orientation.y; //probar mas adelante con el Round a ver si funciona mejor o no
                float Xrotation = transform.rotation.x;

                if (move.GetButtonDown(PSMoveButton.Square))
                {
                    Zrotation = 1;
                }
                if (move.GetButtonDown(PSMoveButton.Triangle))
                {
                    Zrotation = -1;
                }
                if (move.GetButtonUp(PSMoveButton.Triangle) || move.GetButtonUp(PSMoveButton.Square))
                {
                    Zrotation = 0;
                }

                transform.Rotate(move.Orientation.x * 10f, move.Orientation.y * 10f, Zrotation);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (droneIndex >= moves.Count)
        {
            return;
        }

        UniMoveController move = moves[droneIndex];

        timer        += Time.deltaTime;
        timerNoPress += Time.deltaTime;

        // Trigger is held down, do control
        if (move.Trigger > 0.9f && !doingAflip)
        {
            move.SetLED(MoveControllerColor);
            if (!isInAir)
            {
                isInAir = true;
                Debug.Log("Lift off");
                SendToNode("/startdrone", 1);
            }
            if (timer > 0.2f)
            {
                if (move.Acceleration.x > 0.02f)
                {
                    SendToNode("/left", move.Acceleration.x * move.Acceleration.x * 2.2f * power);
                }
                else if (move.Acceleration.x < -0.02f)
                {
                    SendToNode("/right", (move.Acceleration.x * move.Acceleration.x * 2.2f * power));
                }
                else
                {
                    SendToNode("/left", 0);
                    SendToNode("/right", 0);
                }

                if (move.Acceleration.y < -0.02f)
                {
                    SendToNode("/front", move.Acceleration.y * move.Acceleration.y * 2.2f * power);
                }
                else if (move.Acceleration.y > 0.02f)
                {
                    SendToNode("/back", move.Acceleration.y * move.Acceleration.y * 2.2f * power);
                }
                else
                {
                    SendToNode("/front", 0);
                    SendToNode("/back", 0);
                }
            }
        }
        if (move.GetButtonDown(PSMoveButton.Square))
        {
            if (timer > 0.2f)
            {
                SendToNode("/counterClockwise", 0.5f);
            }
        }
        else if (move.GetButtonUp(PSMoveButton.Square))
        {
            SendToNode("/counterClockwise", 0);
        }
        else if (move.GetButtonDown(PSMoveButton.Triangle))
        {
            if (timer > 0.2f)
            {
                SendToNode("/clockwise", 0.5f);
            }
        }
        else if (move.GetButtonUp(PSMoveButton.Triangle))
        {
            SendToNode("/clockwise", 0);
        }

        else if (move.GetButtonDown(PSMoveButton.Cross))
        {
            if (timer > 0.2f)
            {
                SendToNode("/down", 0.2f);
            }
        }
        else if (move.GetButtonUp(PSMoveButton.Cross))
        {
            SendToNode("/down", 0);
        }
        else if (move.GetButtonDown(PSMoveButton.Circle))
        {
            if (timer > 0.2f)
            {
                SendToNode("/up", 0.2f);
            }
        }
        else if (move.GetButtonUp(PSMoveButton.Circle))
        {
            SendToNode("/up", 0);
            SendToNode("/stop", 0);
        }
        else if (move.GetButtonUp(PSMoveButton.Move))
        {
            SendToNode("/land", 1);
        }
        else if (move.GetButtonUp(PSMoveButton.Select))
        {
            SendToNode("/flip", 1);
        }
        else if (move.GetButtonUp(PSMoveButton.Start))
        {
            SendToNode("/wave", 1);
        }
        else if (move.Trigger <= 0.8f && !doingAflip)
        {
            if (timer > 0.2f)
            {
                SendToNode("/stop", 0);
            }
            move.SetLED(MoveControllerColor * 0.2f);
        }

        if (move.GetButtonUp(PSMoveButton.PS))
        {
            isInAir = false;
            //TODO: Make panic
            SendToNode("/land", 1);
        }
        prevTrigger = move.Trigger;
    }
Esempio n. 10
0
    void FixedUpdate()
    {
        /* Move Meter Arrow */
        if (arrow.transform.position.x < rightBorder && right)
        {
            arrow.transform.position += new Vector3(arrowSpeed, 0, 0);
            throwSpeedCount++;
        }
        if (arrow.transform.position.x >= rightBorder)
        {
            right = false;
        }
        if (right == false)
        {
            arrow.transform.position -= new Vector3(arrowSpeed, 0, 0);
            throwSpeedCount--;
        }
        if (arrow.transform.position.x <= leftBorder)
        {
            right = true;
        }


        foreach (UniMoveController move in moves)
        {
            if (move.Disconnected)
            {
                currentMove = null;
                continue;
            }
            currentMove = move;
            move.SetRumble(move.Trigger);
        }

        /* Shoot ball on Tap */
        //if ((Input.GetButton("Fire1") || move.GetButtonDown(PSMoveButton.Trigger)) && !thrown && availableShots > 0 && shootBlocked==false)
        bool shootButtonDown;

        if (currentMove == null)
        {
            shootButtonDown = false;
        }
        else
        {
            shootButtonDown = currentMove.GetButtonDown(PSMoveButton.Trigger);
        }
        if ((Input.GetButton("Fire1") || shootButtonDown) && !thrown && availableShots > 0 && shootBlocked == false)
        {
            //Debug.Log(moves[0].Acceleration.x);
            shootBlocked = true;
            arrowSpeed   = 0;
            thrown       = true;
            availableShots--;
            //availableShotsGO.GetComponent().text = availableShots.ToString();
            availableShotsGO.GetComponent <GUIText>().text = availableShots.ToString();

            Vector3 playerPos = Player.transform.position;
            ballPos.x      = playerPos.x + 0.234f;
            ballPos.y      = playerPos.y + 1.4509f;
            ballPos.z      = playerPos.z - 0.0234f;
            ballClone      = Instantiate(ball, ballPos, transform.rotation) as GameObject;
            respawnControl = false;

            if (throwSpeedCount * difficulty > 97 && throwSpeedCount * difficulty < 123)     // Bem no meio
            {
                throwSpeedMultiplier = 11;
            }
            else
            {
                throwSpeedMultiplier = (throwSpeedCount * difficulty) / 10;
            }

            if (throwSpeedMultiplier == 12)
            {
                throwSpeedMultiplier = 12.5f;                                     // BUG FIX (Gambiarra)
            }
            hoopRing = GameObject.Find("Ring");
            Vector3 heading = hoopRing.transform.position - Player.transform.position;
            throwSpeed.x = heading.x;
            throwSpeed.z = heading.z + Player.transform.rotation.y / 1000;
            throwSpeed.y = heading.y + throwSpeedMultiplier - 2.5f;

            ballClone.GetComponent <Rigidbody>().AddForce(throwSpeed, ForceMode.Impulse);

            GetComponent <AudioSource>().Play();            //play shoot sound
        }

        /* Remove Ball when it hits the floor */
        if (ballClone != null && ballClone.transform.position.y < 0.25)
        {         /* Fim da rodada */
            Destroy(ballClone, 3);
            thrown     = false;
            throwSpeed = new Vector3(3, 10, 0);            //Reset perfect shot variable
            switch (difficulty)
            {
            case 1: arrowSpeed = 0.001f; break;

            case 2: arrowSpeed = 0.002f; break;

            case 3: arrowSpeed = 0.003f; break;

            case 4: arrowSpeed = 0.004f; break;
            }
            arrow.transform.position = new Vector3(leftBorder, 0.487829f, 0);
            right           = true;
            throwSpeedCount = 0;

            //Component TimerScript = GetComponent(Timer);


            Respawn();
            StartCoroutine(enableShoot());             // Destrava o click

            /* Check if out of shots */



            if (availableShots == 0)
            {
                //arrow.renderer.enabled = false;
                arrow.GetComponent <GUITexture>().enabled = false;
                Invoke("restart", 2);
            }
        }

        /*if (timerScript.getCurrentTime()<=0){
         *      //Debug.Log ("Time Over!");
         *      arrow.guiTexture.enabled = false;
         *      //timerScript.restartTimer();
         * //	TimerHUD = null;
         * //	timerScript = null;
         *      //Destroy(TimerHUD);
         *      //availableShots = 0;
         *      timerScript.restartTimer();
         *      Invoke ("restart", 2);
         * }*/
    }
Esempio n. 11
0
    void Update()
    {
        if (move == null)
        {
            this.gameObject.SetActive(false);
        }

        if (!gameOver)
        {
            if (move != null)
            {
                if (move.GetButtonDown(PSMoveButton.Move))
                {
                    audioControl.GetComponent <AudioControl>().ActivateAudioClip();

                    if (startGame)
                    {
                        Messenger.Broadcast(GameEvent.START_GAME);
                        startGame = false;
                    }

                    lightsaberOn = !lightsaberOn;
                    animator.SetBool("On", lightsaberOn);
                    //trailRenderer.emitting = lightsaberOn;
                    //trailGood.SetActive(lightsaberOn);
                    //lightsaberEdge.SetActive(lightsaberOn);
                    //Invoke("delayLightsaberEdge", 1f);

                    //StartCoroutine("ActivateRumble");
                }
                if (move.GetButtonDown(PSMoveButton.Square))
                {
                    trailGoodRenderer.material = lightsaberPurple;
                    edgeRenderer.material      = lightsaberPurple;
                }
                if (move.GetButtonDown(PSMoveButton.Triangle))
                {
                    trailGoodRenderer.material = lightsaberGreen;
                    edgeRenderer.material      = lightsaberGreen;
                }
                if (move.GetButtonDown(PSMoveButton.Circle))
                {
                    trailGoodRenderer.material = lightsaberRed;
                    edgeRenderer.material      = lightsaberRed;
                }
                if (move.GetButtonDown(PSMoveButton.Cross))
                {
                    trailGoodRenderer.material = lightsaberBlue;
                    edgeRenderer.material      = lightsaberBlue;
                }

                if (move.GetButtonDown(PSMoveButton.Select))
                {
                    move.ResetOrientation();
                }

                if (move.GetButtonDown(PSMoveButton.Start))
                {
                    canMove = !canMove;
                }

                if (lightsaberOn && !loopClipPlaying)
                {
                    audioControl.GetComponent <AudioControl>().LoopAudioClip();
                    loopClipPlaying = true;
                }

                if (!lightsaberOn && loopClipPlaying)
                {
                    audioControl.GetComponent <AudioControl>().LoopAudioClipStop();
                    loopClipPlaying = false;
                }

                if (canMove)
                {
                    transform.localRotation = move.Orientation;
                    transform.localPosition = move.Position;
                    //audioControl.GetComponent<AudioControl>().SwingAudioClip();
                }
            }
        }
    }
Esempio n. 12
0
        void Update()
        {
            for (int i = 0; i < moves.Count; i++)
            {
                UniMoveController move    = moves[i];
                MoveController    moveObj = moveObjs[i];

                // Instead of this somewhat kludge-y check, we'd probably want to remove/destroy
                // the now-defunct controller in the disconnected event handler below.
                if (move.Disconnected)
                {
                    continue;
                }


                //Update state button trigger
                updateButtonTrigger(ref move);


                //Write mode
                if (writeMode)
                {
                    updateWriteMode(ref moveObj, ref move);
                    return;
                }

                // Change the colors of the LEDs based on which button has just been pressed:
                if (move.GetButtonDown(PSMoveButton.Circle))
                {
                    moveObj.SetLED(Color.cyan); move.SetLED(Color.cyan);
                    activedWriteMode();
                }
                else if (move.GetButtonDown(PSMoveButton.Cross))
                {
                    moveObj.SetLED(Color.red); move.SetLED(Color.red);
                    removeObject();
                }
                else if (move.GetButtonDown(PSMoveButton.Square))
                {
                    moveObj.SetLED(Color.yellow); move.SetLED(Color.yellow);
                    addObject();
                }
                else if (move.GetButtonDown(PSMoveButton.Triangle))
                {
                    moveObj.SetLED(Color.magenta); move.SetLED(Color.magenta);

                    if (this.objectSelected != null && !visualisationMode)
                    {
                        activedVisualisationMode(ref moveObj);
                    }
                    else if (this.objectSelected != null)
                    {
                        desactivedVisualisationMode();
                    }
                }
                else if (move.GetButtonDown(PSMoveButton.PS))
                {
                    //Reset orientation
                    move.ResetOrientation();
                    moveObj.SetLED(Color.black);
                    move.SetLED(Color.black);
                }
                else if (move.GetButtonDown(PSMoveButton.Start))
                {
                    base.managerListener.redoAction();
                }
                else if (move.GetButtonDown(PSMoveButton.Select))
                {
                    base.managerListener.undoAction();
                }

                // Set the rumble based on how much the trigger is down
                moveObj.gameObject.transform.localRotation = new Quaternion(move.Orientation.x, -move.Orientation.y, -move.Orientation.z, move.Orientation.w);

                //Update modes
                if (visualisationMode)
                {
                    updateVisualisationMode(ref moveObj);
                }
                else
                {
                    updateRay(ref move, ref moveObj);
                }
            }
        }
        /**
            Update the ray

            Draw a ray from Psmove to retrieve the object selected.
        */
        private void updateRay(ref UniMoveController move, ref MoveController moveObj)
        {
            Transform sphereTransform = moveObj.transform.Find("Sphere");
            Transform capsuleTransform = moveObj.transform.Find("Capsule");
            Vector3 heading = sphereTransform.position - capsuleTransform.transform.position;
            Vector3 direction = heading.normalized;
            RaycastHit hit;
            Ray ray = new Ray(sphereTransform.position, direction);

            Boolean haveCollision = Physics.Raycast(ray, out hit);
            if (haveCollision && move.GetButtonDown(PSMoveButton.Move))
            {

                if (objectSelected == null || objectSelected != hit.collider.gameObject)
                {
                    GameObject obj = hit.collider.gameObject;
                    selectCollisionObject(ref obj);
                    this.moveAction = new MoveAction(obj);
                }
                else {
                    if (this.objectSelected != null)
                    {
                        Vector3 position = this.objectSelected.transform.localPosition;
                        this.moveAction.NewLocation = new Vector3(position.x, position.y, position.z);
                        base.managerListener.doAction(this.moveAction);
                    }

                    deselectCollisionObject();
                }

            }

            if (this.objectSelected != null && buttonTriggerIsDown)
            {
                float distance = Vector3.Distance(moveObj.transform.position, this.objectSelected.transform.position);
                float z = this.objectSelected.transform.localPosition.z;
                Vector3 location = moveObj.transform.position + direction * distance;
                location.z = z;
                this.objectSelected.transform.localPosition = location;
            }

            Debug.DrawRay(sphereTransform.position, direction * 10, Color.green);
        }
        /**
            Update write mode
            Modify the texte of current selected object.

        */
        private void updateWriteMode(ref MoveController moveObj, ref UniMoveController move) {
            //update psmove rotation
            moveObj.gameObject.transform.localRotation = new Quaternion(move.Orientation.x, -move.Orientation.y, -move.Orientation.z, move.Orientation.w);

            if ( move.GetButtonDown(PSMoveButton.Circle) ) {
                //We remove the last letter because it's only a letter to show the next letter to add.
                String newText = this.textMesh.text.Substring(0, this.textMesh.text.Length - 1);
                renameAction.NewName = newText;
                base.managerListener.doAction(renameAction);

                this.writeMode = false;
                this.textMesh = null;
                return;
            }

            StringBuilder textPanel = new StringBuilder(this.textMesh.text);

            if (move.GetButtonDown(PSMoveButton.Square))
            {
                // remove last letter
                textPanel.Length = (textPanel.Length > 1) ? textPanel.Length - 1 : 1;
            }
            else if (move.GetButtonDown(PSMoveButton.Triangle))
            {
                // add letter
                textPanel.Append(ALPHABET[indexAlphabet]);
            }
            else {
                //change last letter
                float z = moveObj.transform.rotation.eulerAngles.z;
                int step = 360 / ALPHABET.Length;
                this.indexAlphabet = (int) (z / step);

                if (indexAlphabet >= ALPHABET.Length) {
                    indexAlphabet = 0;
                }
                textPanel[textPanel.Length - 1] = ALPHABET[indexAlphabet];
            }

            //update the text panel
            this.textMesh.text = textPanel.ToString();

        }
        private void updateButtonTrigger(ref UniMoveController move) {
            if (move.GetButtonDown(PSMoveButton.Trigger))
            {
                buttonTriggerIsDown = true;
            }

            if (move.GetButtonUp(PSMoveButton.Trigger))
            {
                buttonTriggerIsDown = false;
            }

        }
Esempio n. 16
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            return;
        }

        // to switch node type, press all buttons while holding trigger
        // to turn an attacker on/off, press all buttons without trigger

        if ((controller.GetButton(PSMoveButton.Square) && controller.GetButton(PSMoveButton.Circle) && controller.GetButton(PSMoveButton.Cross) && controller.GetButton(PSMoveButton.Square)) &&
            (controller.GetButtonDown(PSMoveButton.Square) || controller.GetButtonDown(PSMoveButton.Circle) || controller.GetButtonDown(PSMoveButton.Cross) || controller.GetButtonDown(PSMoveButton.Square))
            )
        {
            if (controller.Trigger > 0.5f)
            {
                if (type == 1)
                {
                    type = 2;
                    PlayerPrefs.SetInt(controller.Serial + "Type", 2);
                }
                else
                {
                    type = 1;
                    PlayerPrefs.SetInt(controller.Serial + "Type", 1);
                }
            }
            else
            {
                active = !active;
            }
            ResetLEDAndRumble();
        }

//		if ( calibrationAllowed ) {
//			// Button presses
//			if ( controller.GetButtonDown(PSMoveButton.Circle) ) {
//				if ( !calibrating ) {
//					calibrating = true;
//					calibratingXMax = -2048;
//					calibratingXMin = 2048;
//					calibratingYMax = -2048;
//					calibratingYMin = 2048;
//					calibratingZMax = -2048;
//					calibratingZMin = 2048;
//				}
//				else {
//					calibrating = false;
//					PlayerPrefs.SetInt(controller.Serial + "Calibrated", 1);
//					PlayerPrefs.SetFloat(controller.Serial + "XMax", calibratingXMax);
//					PlayerPrefs.SetFloat(controller.Serial + "XMin", calibratingXMin);
//					PlayerPrefs.SetFloat(controller.Serial + "YMax", calibratingYMax);
//					PlayerPrefs.SetFloat(controller.Serial + "YMin", calibratingYMin);
//					PlayerPrefs.SetFloat(controller.Serial + "ZMax", calibratingZMax);
//					PlayerPrefs.SetFloat(controller.Serial + "ZMin", calibratingZMin);
//					LoadCalibration();
//					ResetLEDAndRumble();
//				}
//			}

        // accelerometer test
//			if ( !calibrating && (controller.Acceleration-lastAccel).magnitude > Game.Instance.attackAccelThreshold )  {
//				SetLED(Color.cyan);
//				SetLED(Color.black, 1f);
//			}

//		}

        mx = controller.Magnetometer.x;
        my = controller.Magnetometer.y;
        mz = controller.Magnetometer.z;
//		Debug.Log (mx.ToString() + " " + my.ToString() + " " + mz.ToString());

        if (inGame)
        {
            float d = type == 1 ? Game.Instance.magnetThresholdTarget : Game.Instance.magnetThresholdAttacker;
            if ((mx != 0 || my != 0 || mz != 0) && (mx < mxMin - d || mx > mxMax + d || my < myMin - d || my > myMax + d || mz < mzMin - d || mz > mzMax + d))
            {
//					alive = false;
//					SetLED(DEADCOLOR);
//					SetRumble(0);
                HitEvent(this);
            }
        }

//		if ( calibrating ) {
//			if ( mx > calibratingXMax ) calibratingXMax = mx;
//			if ( mx < calibratingXMin ) calibratingXMin = mx;
//			if ( my > calibratingYMax ) calibratingYMax = my;
//			if ( my < calibratingYMin ) calibratingYMin = my;
//			if ( mz > calibratingZMax ) calibratingZMax = mz;
//			if ( mz < calibratingZMin ) calibratingZMin = mz;
//			float target = 360;
//			float px = Math.Min(1, ( calibratingXMax - calibratingXMin ) / target);
//			float py = Math.Min(1, ( calibratingYMax - calibratingYMin ) / target);
//			float pz = Math.Min(1, ( calibratingZMax - calibratingZMin ) / target);
//			Debug.Log(px.ToString() + " " + py.ToString() + " " + pz.ToString());
//			float p = Mathf.Min(px, Mathf.Min(py, pz));
//			p = Mathf.Pow(p, 4f); // skew color curve
//			SetLED(new Color(1-p, p, 0));
//		}

        if (mx == 0 && my == 0 && mz == 0)
        {
            ResetLEDAndRumble();
            SetLED(Color.red);
            lostConnection = true;
        }
        else if (lostConnection)
        {
            lostConnection = false;
            ResetLEDAndRumble();
        }



//		lastAccel = controller.Acceleration;

        // DEBUG
        //		if ( hasBall ) {
        //			Debug.Log(controller.Orientation.eulerAngles);
        //			Debug.Log((controller.Orientation.eulerAngles - startOrientation));
        //			Debug.Log((controller.Orientation.eulerAngles - startOrientation).magnitude);
        //		}
        //		if ( Game.Instance.HoldingPlayer != null && Game.Instance.HoldingPlayer != this ) {
        //			Debug.Log (Game.Instance.HoldingPlayer.GetOrientationDifference(this));
        //		}

//		float D = Game.Instance.magnetThreshold;
//		Debug.Log(mx.ToString() + " " + my.ToString() + " " + mz.ToString() + " / " + mxMin.ToString()+"-"+mxMax.ToString() + " " + myMin.ToString()+"-"+myMax.ToString() + " " + mzMin.ToString()+"-"+mzMax.ToString());
//		if ( (mx!=0 || my!=0 || mz!=0 ) && ( mx < mxMin-D || mx > mxMax+D || my < myMin-D || my > myMax+D || mz < mzMin-D || mz > mzMax+D ) ) {
//			SetLED(Color.red);
//			GameObject.FindObjectOfType<AudioSource>().PlayOneShot(GameObject.FindObjectOfType<Game>().nodeHitSound);
//		} else {
//			SetLED(Color.green);
//		}
    }