ResetOrientation() public method

public ResetOrientation ( ) : void
return void
Ejemplo n.º 1
0
	// Use this for initialization
	void Start () {
		controller = gameObject.AddComponent<UniMoveController>();
		
		if(!controller.Init(playerIndex))
		{
			Debug.Log ("Could not initialize controller "+playerIndex);
		}
		
		controller.InitOrientation();
		controller.ResetOrientation();
		controller.SetLED(playerColor);
		
		
	}
Ejemplo n.º 2
0
    void Start()
    {
        /* NOTE! We recommend that you limit the maximum frequency between frames.
         * This is because the controllers use Update() and not FixedUpdate(),
         * and yet need to update often enough to respond sufficiently fast.
         * Unity advises to keep this value "between 1/10th and 1/3th of a second."
         * However, even 100 milliseconds could seem slightly sluggish, so you
         * might want to experiment w/ reducing this value even more.
         * Obviously, this should only be relevant in case your framerare is starting
         * to lag. Most of the time, Update() should be called very regularly.
         */

        Time.maximumDeltaTime = 0.1f;

        int count = UniMoveController.GetNumConnected();

        Debug.Log("count = " + count);

        for (int i = 0; i < count; i++)
        {
            UniMoveController move = gameObject.AddComponent <UniMoveController>();  // It's a MonoBehaviour, so we can't just call a constructor
            move.CameraPosition = "Back";


            // Remember to initialize!
            if (!move.Init(i))
            {
                Destroy(move);  // If it failed to initialize, destroy and continue on
                continue;
            }


            // This example program only uses Bluetooth-connected controllers
            PSMoveConnectionType conn = move.ConnectionType;

            if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
            {
                Destroy(move);
            }
            else
            {
                moves.Add(move);
                move.ResetOrientation();

                sphere.GetComponent <SphereController>().Move = move;
                sphere.GetComponent <SphereController>().AlternativeStart();
            }
        }
    }
Ejemplo n.º 3
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);
            }
        }
    }
Ejemplo n.º 4
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();
                }
            }
        }
    }
Ejemplo n.º 5
0
    void Start()
    {
        /* NOTE! We recommend that you limit the maximum frequency between frames.
         * This is because the controllers use Update() and not FixedUpdate(),
         * and yet need to update often enough to respond sufficiently fast.
         * Unity advises to keep this value "between 1/10th and 1/3th of a second."
         * However, even 100 milliseconds could seem slightly sluggish, so you
         * might want to experiment w/ reducing this value even more.
         * Obviously, this should only be relevant in case your framerare is starting
         * to lag. Most of the time, Update() should be called very regularly.
         */
        Time.maximumDeltaTime = 0.1f;

        moveControllerPrefab = GameObject.Find("MoveController");
        Destroy(moveControllerPrefab);
        if (moveControllerPrefab == null || moveControllerPrefab.GetComponent <MoveController>() == null)
        {
            Debug.LogError("GameObject with object named \"MoveController\" with script MoveController is missing from the scene");
        }



        int count = UniMoveController.GetNumConnected();

        // Iterate through all connections (USB and Bluetooth)
        for (int i = 0; i < count; i++)
        {
            UniMoveController move = gameObject.AddComponent <UniMoveController>();             // It's a MonoBehaviour, so we can't just call a constructor


            // Remember to initialize!
            if (!move.Init(i))
            {
                Destroy(move);                  // If it failed to initialize, destroy and continue on
                continue;
            }



            // This example program only uses Bluetooth-connected controllers
            PSMoveConnectionType conn = move.ConnectionType;
            if (conn == PSMoveConnectionType.Unknown)            // || conn == PSMoveConnectionType.USB)
            {
                Destroy(move);
            }
            else
            {
                moves.Add(move);

                move.OnControllerDisconnected += HandleControllerDisconnected;

                move.InitOrientation();
                move.ResetOrientation();

                // Start all controllers with a white LED
                move.SetLED(Color.white);

                // adding the MoveController Objects on screen
                GameObject moveController = GameObject.Instantiate(moveControllerPrefab,
                                                                   Vector3.right * count * 2 + Vector3.left * i * 4, Quaternion.identity) as GameObject;
                MoveController moveObj = moveController.GetComponent <MoveController>();
                moveObjs.Add(moveObj);
                moveObj.SetLED(Color.white);
            }
        }
    }
Ejemplo n.º 6
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);
                }
            }
        }
Ejemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        if (phase == Phase.Connecting)
        {
            bool allConnected = true;
            for (int i = 0; i < nodes.Count; i++)
            {
                if (UniMoveController.GetNumConnected() > 0)
                {
                    if (nodes[i].controller == null)
                    {
                        UniMoveController controller = nodes[i].gameObject.AddComponent <UniMoveController>();
                        if (controller.Init(i))
                        {
                            controller.InitOrientation();
                            controller.ResetOrientation();
                            nodes[i].Init(controller, this.debugButtons[i]);
                        }
                        else
                        {
                            Destroy(controller);
                            allConnected = false;
                        }
                    }
                }
                else
                {
                    nodes[i].InitDebug(i <= 1?1:2, this.debugButtons[i]);
                }
            }

            if (allConnected)
            {
                for (int i = 0; i < nodes.Count; i++)
                {
                    if (nodes[i].type == 1)
                    {
                        Target target = nodes[i].gameObject.AddComponent <Target>();
                        target.HitEvent += OnTargetHit;
                        targets.Add(target);
                    }
                    else
                    {
                        Attacker attacker = nodes[i].gameObject.AddComponent <Attacker>();
                        attacker.HitEvent            += OnAttackerHit;
                        attacker.TimeoutEvent        += OnAttackerTimeout;
                        attacker.TimeoutWarningEvent += OnAttackerTimeoutWarning;
                        attackers.Add(attacker);
                    }
                }

                phase = Phase.Waiting;
            }
        }

        else if (phase == Phase.Waiting)
        {
            // start game
            if (Input.GetKeyDown(KeyCode.Space))
            {
                bool practice = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
                StartGame(practice);
            }
        }

        else if (phase == Phase.Playing)
        {
            // stop game
            if (Input.GetKeyDown(KeyCode.Space))
            {
                StopGame();
            }

            // heal
            if (Input.GetKeyDown(KeyCode.H))
            {
                Heal();
            }
        }

        else if (phase == Phase.Ended)
        {
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            //ControllerDebug.Active = !ControllerDebug.Active;
            debugPanel.SetActive(!debugPanel.activeSelf);
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            setupPanel.SetActive(!setupPanel.activeSelf);
        }
    }