Inheritance: MonoBehaviour
Ejemplo n.º 1
0
    public void Init()
    {
        Time.maximumDeltaTime = 0.1f;
        int count = UniMoveController.GetNumConnected();

        Debug.Log(UniMoveController.GetNumConnected() + " controllers connected");

        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;
            }
        }
    }
Ejemplo n.º 2
0
    void Start()
    {
        nodes     = new List <Node>();
        attackers = new List <Attacker>();
        targets   = new List <Target>();

        InitSetup();
        setupInited = true;

        int count = UniMoveController.GetNumConnected();

        Debug.Log("Controllers connected: " + count);

        if (count == 0)
        {
            count = 6;             // debug mode
        }

        for (int i = 0; i < count; i++)
        {
            Node node = Instantiate(nodePrefab);
            nodes.Add(node);

            node.transform.SetParent(this.transform);
        }

        phase = Phase.Connecting;
    }
    // Use this for initialization
    void Awake()
    {
        client = new OSCClient(IPAddress.Parse(Host), port + droneIndex);
        Time.maximumDeltaTime = 0.1f;
        int count = UniMoveController.GetNumConnected();

        Debug.Log(count);
        // Iterate through all connections (USB and Bluetooth)
        if (moves.Count == 0)
        {
            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;
                }
            }
        }
    }
Ejemplo n.º 4
0
    public void Init(UniMoveController controller, Button debugButton)
    {
        this.controller  = controller;
        this.debugButton = debugButton;

        canIBeCalibrating = true;
        mxMax             = -2048;
        mxMin             = 2048;
        myMax             = -2048;
        myMin             = 2048;
        mzMax             = -2048;
        mzMax             = 2048;
        mxMinDriftTicks   = 0;
        mxMaxDriftTicks   = 0;
        myMinDriftTicks   = 0;
        myMaxDriftTicks   = 0;
        mzMinDriftTicks   = 0;
        mzMaxDriftTicks   = 0;

        active = true;

        LoadCalibration();
        ResetLEDAndRumble();

        Invoke("CalibrateForever", 0);
    }
Ejemplo n.º 5
0
        private void updateButtonTrigger(ref UniMoveController move)
        {
            if (move.GetButtonDown(PSMoveButton.Trigger))
            {
                buttonTriggerIsDown = true;
            }

            if (move.GetButtonUp(PSMoveButton.Trigger))
            {
                buttonTriggerIsDown = false;
            }
        }
Ejemplo n.º 6
0
    public Player(int initId, UniMoveController initMove, GameManager gameManReference)
    {
        id      = initId;
        move    = initMove;
        gameMan = gameManReference;

        defaultColour = COLORS[id];
        state         = PlayerState.IDLE;

        accelerationStory = new List <Vector3>();

        StartGlow();
    }
Ejemplo n.º 7
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);
		
		
	}
    void Start()
    {
        this.transform.parent        = GameObject.Find("RightHandMiddle4").transform;
        this.transform.localPosition = Vector3.zero;
        Time.maximumDeltaTime        = 0.1f;
        audioSource      = (AudioSource)gameObject.AddComponent("AudioSource");
        audioSource.clip = audioClip;
        audioSource.loop = false;

        handPoint = GameObject.Find("PSMoveController");
        //handPoint.transform.position = GameObject.Find("23_Hand_Right").transform.position + psmoveVec;
        //handPoint.transform.parent = GameObject.Find("23_Hand_Right").transform;
        //handPoint.rigidbody.isKinematic = true;


        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;

                // Start all controllers with a white LED
                move.SetLED(Color.white);
                Debug.Log(count);
            }
        }

        orig = handPoint.renderer.material.color;
        moves[0].SetLED(Color.red);
    }
Ejemplo n.º 9
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.º 10
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();

        // 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;

                // Start all controllers with a white LED
                move.SetLED(Color.white);
            }
        }
        if (moves.Count <= 0)
        {
            Debug.Log("No Bluetooth-connected controllers found. Make sure one or more are both paired and connected to this computer.");
        }
    }
Ejemplo n.º 11
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();
        }
Ejemplo n.º 12
0
    // Use this for initialization
    void Start()
    {
        gm = FindObjectOfType<GameMaster> ();
        rb =   gameObject.GetComponent<Rigidbody2D>();
        anim = GetComponent<Animator>();

        Time.maximumDeltaTime = 0.1f;

        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
            {

                //move.OnControllerDisconnected += HandleControllerDisconnected;
                move.EnableOrientation ();
                move.InitOrientation();
            //	move.ResetOrientation();

                // Start all controllers with a white LED
                move.SetLED(Color.white);
                move.UpdateRate = 0.02f;

                moves = move;

            }
        }
    }
Ejemplo n.º 13
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);

        move = gameObject.AddComponent <UniMoveController>();  // It's a MonoBehaviour, so we can't just call a constructor
        move.CameraPosition = "Front";

        // Remember to initialize!
        if (!move.Init(0))  // <F> 0 es el primer y único mando
        {
            Destroy(move);  // If it failed to initialize, destroy and continue on
        }

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

        if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
        {
            Destroy(move);
        }
        else
        {
            // Start all controllers with a white LED
            move.SetLED(Color.magenta);

            transform.localRotation = move.Orientation;
            transform.localPosition = move.Position;
        }

        Debug.Log(gameObject.tag);
    }
Ejemplo n.º 14
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);
        }
    void buzzMove(UniMoveController move, float amount, Color color, double duration)
    {
        // Play a rumble at a given level and duration.
        move.SetRumble(amount);
        move.SetLED(color);
        if (buzzTimer != null)
        {
            buzzTimer.Dispose();
            buzzTimer = null;
        }

        buzzTimer = new System.Threading.Timer(
            obj => {
            move.SetLED(Color.grey);
            move.SetRumble(0);
            buzzTimer = null;
        },
            null,
            (uint)(duration * 1000),
            System.Threading.Timeout.Infinite);
    }
Ejemplo n.º 16
0
    void Update()
    {
        if(!gameOver) {
          if(gameMoves.Count >= 2) {
        foreach (UniMoveController gameMove in gameMoves) {
          if (gameMove.Disconnected) continue;

          if(gameMove.AnyButtonDown()) {
            gameMove.SetLED(Color.red);
            gameMove.SetRumble(1);
            audio.PlayOneShot(deathSound);
            gameOver = true;
            musicPlayer.audio.Stop();
            foreach (UniMoveController otherMove in gameMoves) {
              if (otherMove != gameMove) moveToFlash = otherMove;
            }
          }
        }
          } else {
        foreach (UniMoveController move in moves) {
          if (move.Disconnected) continue;

          if (move.AnyButtonDown() && !gameMoves.Contains(move)) {
            audio.PlayOneShot(enableSound);
            gameMoves.Add(move);
            move.SetLED(isCyan ? Color.cyan : Color.magenta);
            isCyan = !isCyan;
          }
        }
          }
        } else {
          FlashMove();
          foreach (UniMoveController move in moves) {
        if(move.AnyButtonDown()) {
          Application.LoadLevel(0);
        }
          }
        }
    }
    // Use this for initialization
    void Start()
    {
        // Keep the updates coming at 10Hz
        Time.maximumDeltaTime = 0.1f;
        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;

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

//		rightSensorFusion = new AHRS.MahonyAHRS(Time.deltaTime); // Assume 60Hz update rate
    }
    void UpdateHands()
    {
        // FIXME: Just update first hand we match.
        if (rightHandController == null)
        {
            return;
        }
        if (moves.Count < 1)
        {
            return;
        }
        UniMoveController rightMove = moves[0];

        // Fist pulling gesture.
        rightHandController.fistPull = rightMove.Trigger;

        // Update sensor fusion computation of the rigid body xform.
//		Vector3 gyro = rightMove.Gyro;
//		Vector3 accel = rightMove.Acceleration;
//		rightSensorFusion.SamplePeriod = Time.deltaTime;
//		rightSensorFusion.Update(gyro.x, gyro.y, gyro.z, accel.x, accel.y, accel.z);
//		float[] rightQuat = rightSensorFusion.Quaternion;
//		rightHandController.transform.rotation = new Quaternion(rightQuat[0], rightQuat[1], rightQuat[2], rightQuat[3]);
    }
Ejemplo n.º 19
0
    void Start()
    {
        arrow.transform.position = new Vector3(leftBorder, 0.487829f, 0);

        /* Increase Gravity */
        Physics.gravity = new Vector3(0, -20, 0);
        Player          = GameObject.Find("Player");

        varDifficulty = GameObject.Find("varDifficulty");
        if (varDifficulty != null)
        {
            difficulty = int.Parse(varDifficulty.GetComponent <GUIText> ().text);
        }
        else
        {
            difficulty = 3;
        }

        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;
        }

        //TimerHUD = GameObject.Find("TimerHUD");
        //timerScript = (TimerScript) TimerHUD.GetComponent(typeof(TimerScript));
        Time.maximumDeltaTime = 0.1f;

        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))   // TENTA INICIALIZAR
            {                    // QUANDO RESTARTA O PROGRAMA ELE TENTA INICIALIZAR E NAO CONSEGUE PQ JA ESTA INICIADO
                // ENTAO ELE DESTROI AS CONEXOES ABERTAS
                // E POR ISSO DESLIGA O CONTROLE
                // === EU ACHO... ===
                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;

                // Start all controllers with a white LED
                move.SetLED(Color.white);
                Debug.Log("PSMove conectado.");
            }
        }
        if (moves.Count <= 0)
        {
            Debug.Log("No Bluetooth-connected controllers found. Make sure one or more are both paired and connected to this computer.");
        }
    }
Ejemplo n.º 20
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);
         * }*/
    }
Ejemplo n.º 21
0
	IEnumerator Blink(UniMoveController controller, Color color){
		GestureManager.Instance.SetControllerLEDColor(controller.ControllerId, Color.white);
		yield return new WaitForSeconds(0.05f);
		GestureManager.Instance.SetControllerLEDColor(controller.ControllerId, color);
		yield return new WaitForSeconds(0.05f);
		GestureManager.Instance.SetControllerLEDColor(controller.ControllerId, Color.white);
		yield return new WaitForSeconds(0.05f);
		GestureManager.Instance.SetControllerLEDColor(controller.ControllerId, color);
		yield return new WaitForSeconds(0.05f);
		GestureManager.Instance.SetControllerLEDColor(controller.ControllerId, Color.white);
	}
Ejemplo n.º 22
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);
            }
        }
    }
        /**
            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;
            }

        }
Ejemplo n.º 25
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.º 26
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.
         */

        // If you have changed these names, please replace below "names"

        /*Left = GameObject.Find("LeftWall");
        *  Right = GameObject.Find("RightWall");
        *  Racket = GameObject.Find("Racket");*/
        try {
            Sword       = GameObject.Find("Sword");
            Light       = GameObject.Find("VolumetricLinePrefab");
            Player      = GameObject.Find("player");
            EnemyMaster = GameObject.Find("EnemyMaster");
            Unitychan   = GameObject.Find("unitychan");
            Cube        = GameObject.Find("Cube");
            Enemy0      = GameObject.Find("Enemy0");
            Enemy1      = GameObject.Find("Enemy1");
            Camera      = GameObject.Find("Main Camera");
            text        = GameObject.Find("Text").GetComponent <Text>();
            animator    = Unitychan.GetComponent <Animator>();
            rb          = Unitychan.GetComponent <Rigidbody>();
            opening     = true;
            countdown   = false;
            playing     = false;
            gameover    = false;
            clear       = false;
        } catch (Exception e) {
            Debug.Log("exception");
        }

        Light.SetActive(false);
        Sword.SetActive(false);
        Player.SetActive(false);
        EnemyMaster.SetActive(false);
        Enemy0.SetActive(false);
        Enemy1.SetActive(false);
        Unitychan.SetActive(false);
        Cube.SetActive(false);


        _Style          = new GUIStyle();
        _Style.fontSize = 20;

        Time.maximumDeltaTime = 0.1f;

        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) == PSMove_Connect_Status.MoveConnect_NoData)
            {
                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;

                // 球体LEDの基本セッティング 赤色
                move.SetLED(Color.red);
            }
        }
        _TimeCount = Time.time;
    }
    // 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;
    }
Ejemplo n.º 28
0
 public void Init(UniMoveController c, GameObject co)
 {
     controller = c;
     controllerObj = co;
 }
        /**
            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);
        }
Ejemplo n.º 30
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);
        }*/
    }
Ejemplo n.º 31
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);
        }
    }