Ejemplo n.º 1
0
        void Update()
        {
            if (!SixenseInput.IsBaseConnected(0))
            {
                active = false;
                return;
            }

            for (var i = 0; i < SixenseInput.MAX_CONTROLLERS; i++)
            {
                if (SixenseInput.Controllers[i] == null || !SixenseInput.Controllers[i].Enabled)
                {
                    continue;
                }

                active = true;

                int deviceIndex = k_DeviceOffset + (SixenseInput.Controllers[i].Hand == SixenseHands.LEFT ? 0 : 1);
                SendButtonEvents(i, deviceIndex);
                SendAxisEvents(i, deviceIndex);
                SendTrackingEvents(i, deviceIndex);
            }

            // Check for calibrate
            if (SixenseInput.Controllers[0] != null && SixenseInput.Controllers[1] != null)
            {
                if (SixenseInput.Controllers[0].GetButton(SixenseButtons.START) &&
                    SixenseInput.Controllers[1].GetButton(SixenseButtons.START))
                {
                    CalibrateControllers();
                }
            }
        }
Ejemplo n.º 2
0
    // Override GUI to only display instructions if Sixense hands exist and support display in OVR cameras.
    void OnGUI()
    {
        if (Hand == SixenseHands.UNKNOWN)
        {
            return;
        }

        if (SixenseInput.IsBaseConnected(0) && !m_enabled)
        {
            string handStr = Hand == SixenseHands.LEFT ? "left" : "right";

            if (HMDPresent && StorageManager.data.optionControlsEnableRift == true)
            {
                string instructions = "To enable a Hydra controller:\n\r";
                instructions += "Point it at base, pull trigger,\n\r";
                instructions += "place on respective shoulder and press START\n\r";
                DisplayStereoMessage(instructions, "center", "Sixense-center");
                DisplayStereoMessage("Press " + handStr + " START\n\rto control " + gameObject.name, handStr, "Sixense-" + handStr);
            }
            else
            {
                int labelWidth   = 250;
                int labelPadding = 120;
                int horizOffset  = Hand == SixenseHands.LEFT ? -labelWidth - labelPadding  : labelPadding;

                GUI.Box(new Rect(Screen.width / 2 + horizOffset, Screen.height - 40, labelWidth, 30), "Press " + handStr + " START to control " + gameObject.name);
            }
        }
    }
    void Update()
    {
        GameObject guiText = null;

        guiText = GameObject.Find("gui_text_base_connected");
        if (guiText)
        {
            guiText.GetComponent <GUIText>().text = "Base Connected = " + SixenseInput.IsBaseConnected(0);
        }

        for (uint i = 0; i < 2; i++)
        {
            if (SixenseInput.Controllers[i] != null)
            {
                uint controllerNumber = i + 1;

                guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_enabled");
                if (guiText)
                {
                    guiText.GetComponent <GUIText>().text = "Enabled = " + SixenseInput.Controllers[i].Enabled;
                }

                guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_docked");
                if (guiText)
                {
                    guiText.GetComponent <GUIText>().text = "Docked = ";
                    if (SixenseInput.Controllers[i].Enabled)
                    {
                        guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].Docked;
                    }
                }

                guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_hand");
                if (guiText)
                {
                    guiText.GetComponent <GUIText>().text = "Hand = ";
                    if (SixenseInput.Controllers[i].Enabled)
                    {
                        guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].Hand;
                    }
                }

                guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_buttons");
                GameObject guiText2 = GameObject.Find("gui_text_controller_" + controllerNumber + "_buttons_2");;
                if (guiText && guiText2)
                {
                    uint   buttonsCount = 0;
                    string buttonsText  = "";
                    string buttonsText2 = "";
                    if (SixenseInput.Controllers[i].Enabled)
                    {
                        foreach (SixenseButtons button in System.Enum.GetValues(typeof(SixenseButtons)))
                        {
                            if (SixenseInput.Controllers[i].GetButton(button) && (buttonsCount < 4))
                            {
                                if (buttonsText != "")
                                {
                                    buttonsText += " | ";
                                }
                                buttonsText += button;
                                buttonsCount++;
                            }
                            else if (SixenseInput.Controllers[i].GetButton(button) && (buttonsCount >= 4))
                            {
                                if (buttonsText2 != "")
                                {
                                    buttonsText2 += " | ";
                                }
                                buttonsText2 += button;
                                buttonsCount++;
                            }

                            //if ( SixenseInput.Controllers[i].GetButtonDown( button ) )
                            //{
                            //	Debug.Log( "Pressed = " + button );
                            //}

                            //if ( SixenseInput.Controllers[i].GetButtonUp( button ) )
                            //{
                            //	Debug.Log( "Released = " + button );
                            //}
                        }
                    }
                    guiText.GetComponent <GUIText>().text  = "Buttons = " + buttonsText;
                    guiText2.GetComponent <GUIText>().text = "" + buttonsText2;
                }

                guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_trigger");
                if (guiText)
                {
                    guiText.GetComponent <GUIText>().text = "Trigger = ";
                    if (SixenseInput.Controllers[i].Enabled)
                    {
                        guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].Trigger;
                    }
                }

                guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_joystick_x");
                if (guiText)
                {
                    guiText.GetComponent <GUIText>().text = "Joystick X = ";
                    if (SixenseInput.Controllers[i].Enabled)
                    {
                        guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].JoystickX;
                    }
                }

                guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_joystick_y");
                if (guiText)
                {
                    guiText.GetComponent <GUIText>().text = "Joystick Y = ";
                    if (SixenseInput.Controllers[i].Enabled)
                    {
                        guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].JoystickY;
                    }
                }

                guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_position");
                if (guiText)
                {
                    guiText.GetComponent <GUIText>().text = "Position = ";
                    if (SixenseInput.Controllers[i].Enabled)
                    {
                        guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].Position;
                    }
                }

                guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_rotation");
                if (guiText)
                {
                    guiText.GetComponent <GUIText>().text = "Rotation = ";
                    if (SixenseInput.Controllers[i].Enabled)
                    {
                        guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].Rotation;
                    }
                }
            }
        }
    }
Ejemplo n.º 4
0
    // Fixed frame update func
    void Update()
    {
        // Check if game over
        if (isGameOver)
        {
            isPush = false;
            if (finger != null)
            {
                finger.SetActive(false);
                finger = null;
            }
            // Force update the brick info lists
            if (wasGameOver)
            {
                wasGameOver = false;
                brickTimer.Stop();
                brickTimer.Reset();
                for (int i = 0; i < height * 3; ++i)
                {
                    positions [i]    = tempPositions [i];
                    orientations [i] = tempOrientations [i];
                }
                lastTurn = turn - 1;                 // Change the turn count
            }
        }

        // Check if a brick fell
        if (brickFell)
        {
            brickFell = false;
            // Start the timer if is hasn't started
            if (brickTimer.ElapsedMilliseconds == 0 && !isGameOver)
            {
                brickTimer.Start();
                // Now switch turns
                turn++;
                if (!isReplaying)
                {
                    // Save the state of the cameras and bricks
                    prevCam1                 = cam.transform.rotation;
                    prevCamPos               = cam.transform.position;
                    prevCam2                 = cam2.transform.rotation;
                    prevCam2Pos              = cam2.transform.position;
                    fingerList               = new LinkedList <Vector3> (tempFingerList);
                    intermediatePositions    = new ArrayList(tempPositions);
                    intermediateOrientations = new ArrayList(tempOrientations);
                }
                if (players == 2)
                {
                    if (turn % 2 == 0)
                    {
                        playerText.text = "CURRENT TURN: PLAYER 2";
                    }
                    else
                    {
                        playerText.text = "CURRENT TURN: PLAYER 1";
                    }
                }
            }
        }
        // Check if "safe"
        if (brickTimer.ElapsedMilliseconds >= 6000)
        {
            // Reset the timer
            brickTimer.Stop();
            brickTimer.Reset();
            // Now copy over all the previously stored transformation data
            if (!isGameOver)
            {
                for (int i = 0; i < height * 3; ++i)
                {
                    positions [i]    = intermediatePositions [i];
                    orientations [i] = intermediateOrientations [i];
                }
                lastTurn = turn - 1;                 // Change the turn count
            }
        }

        if (isReplaying)
        {
            Vector3 front = tempFingerList.First.Value;
            tempFingerList.RemoveFirst();
            finger.transform.position = front;
            if (tempFingerList.Count == 0)
            {
                finger.SetActive(false);
                finger      = null;
                isReplaying = false;
            }
            return;
        }
        // Test if hydra is connected
        if (!SixenseInput.IsBaseConnected(0))
        {
            print("SIXENSE DEVICE NOT CONNECTED");
        }
        else
        {
            if (isMenu)
            {
                Vector3 pos = SixenseInput.Controllers [1].Position;
                // Disable the text objects and cameras
                playerText.gameObject.SetActive(false);
                fullStackText.gameObject.SetActive(false);
                cam.gameObject.SetActive(false);
                cam2.gameObject.SetActive(false);
                brickFrame.gameObject.SetActive(false);
                // Enable full-screen camera and the buttons
                camMenu.gameObject.SetActive(true);
                UNDO.gameObject.SetActive(true);
                REDO.gameObject.SetActive(true);
                RESET.gameObject.SetActive(true);
                QUIT.gameObject.SetActive(true);
                CONT.gameObject.SetActive(true);
                // Determine which button to highlight
                if (pos.y <= MINY + (MAXY - MINY) / 5)
                {
                    highlightButton("QUIT");
                }
                else if (pos.y <= MINY + (MAXY - MINY) * 2 / 5)
                {
                    highlightButton("CONT");
                }
                else if (pos.y <= MINY + (MAXY - MINY) * 3 / 5)
                {
                    highlightButton("RESET");
                }
                else if (pos.y <= MINY + (MAXY - MINY) * 4 / 5)
                {
                    highlightButton("REDO");
                }
                else
                {
                    highlightButton("UNDO");
                }
                // Now determine if a button was pressed
                if (SixenseInput.Controllers [1].GetButton(SixenseButtons.BUMPER))
                {
                    wasPressed = true;
                }
                else
                {
                    if (wasPressed)
                    {
                        wasPressed = false;
                        isMenu     = false;
                        // Back to game
                        if (isCont)
                        {
                            isCont           = false;
                            CONT.image.color = Color.white;
                            // Enable the text objects and cameras
                            playerText.gameObject.SetActive(true);
                            fullStackText.gameObject.SetActive(true);
                            cam.gameObject.SetActive(true);
                            cam2.gameObject.SetActive(true);
                            brickFrame.gameObject.SetActive(true);
                            // Disable full-screen camera and the buttons
                            camMenu.gameObject.SetActive(false);
                            UNDO.gameObject.SetActive(false);
                            REDO.gameObject.SetActive(false);
                            RESET.gameObject.SetActive(false);
                            QUIT.gameObject.SetActive(false);
                            CONT.gameObject.SetActive(false);
                            return;
                        }
                        // Back to main menu
                        if (isQuit)
                        {
                            SceneManager.LoadScene("MainMenu");
                        }
                        // Reset the game
                        if (isReset)
                        {
                            positions.Clear();
                            orientations.Clear();
                            // Deactive all current bricks and clear brick info lists
                            for (int i = 0; i < height * 3; i++)
                            {
                                ((GameObject)bricks [i]).SetActive(true);
                                ((GameObject)bricks [i]).transform.position = (Vector3)initPositions [i];
                                positions.Add((Vector3)initPositions [i]);
                                ((GameObject)bricks [i]).transform.rotation = (Quaternion)initOrientations [i];
                                orientations.Add((Quaternion)initOrientations [i]);
                            }
                            // Shift camera back to init settings
                            cam.transform.position  = initCamPos;
                            cam.transform.rotation  = initCam1;
                            cam2.transform.position = initCam2Pos;
                            cam2.transform.rotation = initCam2;

                            toCenter = new Vector3(1.5f, 0.0f, 1.5f).normalized;
                            toRight  = new Vector3(-1.5f, 0.0f, 1.5f).normalized;
                            if (finger != null)
                            {
                                finger.SetActive(false);
                                finger = null;
                            }

                            // Back to game
                            isReset          = isMenu = isGameOver = false;
                            CONT.image.color = Color.white;
                            // Enable the text objects and cameras
                            playerText.gameObject.SetActive(true);
                            fullStackText.gameObject.SetActive(true);
                            cam.gameObject.SetActive(true);
                            cam2.gameObject.SetActive(true);
                            brickFrame.gameObject.SetActive(true);
                            brickFrame = GameObject.Find("frame").GetComponent <RawImage>();
                            Vector3 ps = brickFrame.transform.position;
                            brickFrame.transform.position = new Vector3(Screen.width * 0.8f, Screen.height * 0.165f, ps.z);
                            turn     = -1;
                            lastTurn = -2;

                            if (players == 2)
                            {
                                if (turn % 2 == 0)
                                {
                                    playerText.text = "CURRENT TURN: PLAYER 2";
                                }
                                else
                                {
                                    playerText.text = "CURRENT TURN: PLAYER 1";
                                }
                            }
                            // Disable full-screen camera and the buttons
                            camMenu.gameObject.SetActive(false);
                            UNDO.gameObject.SetActive(false);
                            REDO.gameObject.SetActive(false);
                            RESET.gameObject.SetActive(false);
                            QUIT.gameObject.SetActive(false);
                            CONT.gameObject.SetActive(false);
                            return;
                        }
                        // Undo last move
                        if (isUndo)
                        {
                            isUndo = false;
                            // Just go back to game if first move
                            if (turn == -1 || turn == lastTurn)
                            {
                                // Enable the text objects and cameras
                                playerText.gameObject.SetActive(true);
                                playerText.text = "NO MOVES TO UNDO!";
                                fullStackText.gameObject.SetActive(true);
                                cam.gameObject.SetActive(true);
                                cam2.gameObject.SetActive(true);
                                brickFrame.gameObject.SetActive(true);
                                brickFrame = GameObject.Find("frame").GetComponent <RawImage> ();
                                Vector3 ps = brickFrame.transform.position;
                                brickFrame.transform.position = new Vector3(Screen.width * 0.8f, Screen.height * 0.165f, ps.z);
                                // Disable full-screen camera and the buttons
                                camMenu.gameObject.SetActive(false);
                                UNDO.gameObject.SetActive(false);
                                REDO.gameObject.SetActive(false);
                                RESET.gameObject.SetActive(false);
                                QUIT.gameObject.SetActive(false);
                                CONT.gameObject.SetActive(false);
                                return;
                            }
                            else
                            {
                                // Undo last turn
                                turn -= 1;
                                for (int i = 0; i < height * 3; i++)
                                {
                                    GameObject brick = (GameObject)bricks [i];
                                    brick.transform.position = (Vector3)positions [i];
                                    brick.transform.rotation = (Quaternion)orientations [i];
                                    brick.gameObject.GetComponent <Rigidbody> ().useGravity = true;
                                }
                                // Set the turn text accordingly
                                if (players == 2)
                                {
                                    if (turn % 2 == 0)
                                    {
                                        playerText.text = "CURRENT TURN: PLAYER 2";
                                    }
                                    else
                                    {
                                        playerText.text = "CURRENT TURN: PLAYER 1";
                                    }
                                }
                                // Undo game over state
                                isGameOver = false;

                                // Now go back to game
                                // Enable the text objects and cameras
                                playerText.gameObject.SetActive(true);
                                fullStackText.gameObject.SetActive(true);
                                cam.gameObject.SetActive(true);
                                cam2.gameObject.SetActive(true);
                                brickFrame.gameObject.SetActive(true);
                                brickFrame = GameObject.Find("frame").GetComponent <RawImage>();
                                Vector3 ps = brickFrame.transform.position;
                                brickFrame.transform.position = new Vector3(Screen.width * 0.8f, Screen.height * 0.165f, ps.z);
                                // Disable full-screen camera and the buttons
                                camMenu.gameObject.SetActive(false);
                                UNDO.gameObject.SetActive(false);
                                REDO.gameObject.SetActive(false);
                                RESET.gameObject.SetActive(false);
                                QUIT.gameObject.SetActive(false);
                                CONT.gameObject.SetActive(false);
                                return;
                            }
                        }
                        // Replay last move
                        if (isRedo)
                        {
                            isRedo = false;
                            // Just go back to game if first move
                            if (turn == -1)
                            {
                                // Enable the text objects and cameras
                                playerText.gameObject.SetActive(true);
                                playerText.text = "NO MOVES TO REPLAY!";
                                fullStackText.gameObject.SetActive(true);
                                cam.gameObject.SetActive(true);
                                cam2.gameObject.SetActive(true);
                                brickFrame.gameObject.SetActive(true);
                                brickFrame = GameObject.Find("frame").GetComponent <RawImage> ();
                                Vector3 ps = brickFrame.transform.position;
                                brickFrame.transform.position = new Vector3(Screen.width * 0.8f, Screen.height * 0.165f, ps.z);
                                // Disable full-screen camera and the buttons
                                camMenu.gameObject.SetActive(false);
                                UNDO.gameObject.SetActive(false);
                                REDO.gameObject.SetActive(false);
                                RESET.gameObject.SetActive(false);
                                QUIT.gameObject.SetActive(false);
                                CONT.gameObject.SetActive(false);
                                return;
                            }
                            else
                            {
                                // Undo last turn
                                turn -= 1;
                                for (int i = 0; i < height * 3; i++)
                                {
                                    GameObject brick = (GameObject)bricks [i];
                                    brick.transform.position = (Vector3)positions [i];
                                    brick.transform.rotation = (Quaternion)orientations [i];
                                    brick.gameObject.GetComponent <Rigidbody> ().useGravity = true;
                                }
                                // Set the turn text accordingly
                                if (players == 2)
                                {
                                    if (turn % 2 == 0)
                                    {
                                        playerText.text = "CURRENT TURN: PLAYER 2";
                                    }
                                    else
                                    {
                                        playerText.text = "CURRENT TURN: PLAYER 1";
                                    }
                                }
                                // Undo game over state
                                isGameOver     = false;
                                isReplaying    = true;
                                finger         = GameObject.Instantiate(UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Models/Fingertip.prefab", typeof(GameObject))) as GameObject;
                                tempFingerList = new LinkedList <Vector3>(fingerList);

                                // Now go back to game
                                // Enable the text objects and cameras
                                playerText.gameObject.SetActive(true);
                                fullStackText.gameObject.SetActive(true);
                                cam.gameObject.SetActive(true);
                                cam2.gameObject.SetActive(true);
                                cam.transform.position  = prevCamPos;
                                cam.transform.rotation  = prevCam1;
                                cam2.transform.position = prevCam2Pos;
                                cam2.transform.rotation = prevCam2;
                                brickFrame.gameObject.SetActive(true);
                                brickFrame = GameObject.Find("frame").GetComponent <RawImage>();
                                Vector3 ps = brickFrame.transform.position;
                                brickFrame.transform.position = new Vector3(Screen.width * 0.8f, Screen.height * 0.165f, ps.z);
                                // Disable full-screen camera and the buttons
                                camMenu.gameObject.SetActive(false);
                                UNDO.gameObject.SetActive(false);
                                REDO.gameObject.SetActive(false);
                                RESET.gameObject.SetActive(false);
                                QUIT.gameObject.SetActive(false);
                                CONT.gameObject.SetActive(false);
                                return;
                            }
                        }
                    }
                }
            }
            else
            {
                if (isPush)
                {
                    if (isPushing)
                    {
                        // Determine if there's a button release
                        if (!SixenseInput.Controllers [1].GetButton(SixenseButtons.BUMPER))
                        {
                            wasPressed = false;
                            clickTimer.Stop();
                            long timePassed = clickTimer.ElapsedMilliseconds;
                            clickTimer.Reset();
                            isPushing = false;
                            // Player probably gave up on push. Back to normal.
                            if (timePassed < 700)
                            {
                                isPush = isPushing = false;
                                finger.SetActive(false);
                                finger = null;
                                return;
                            }
                            if (isGameOver)
                            {
                                isPush = isPushing = false;
                                return;
                            }
                        }
                        // Otherwise, push as normal
                        Vector3 pos          = SixenseInput.Controllers [1].Position;
                        Vector3 dPos         = pos - prevFinger;
                        Vector3 fingerPos    = finger.transform.position;
                        Vector3 newFingerPos = new Vector3(fingerPos.x - (dPos).x / (MAXX - MINX) * toRight.z / 7.0f,
                                                           fingerPos.y + (dPos).y / (MAXY - MINY) / 7.0f,
                                                           fingerPos.z - (dPos).x / (MAXX - MINX) * toRight.z / 7.0f)
                                               + toCenter * (dPos).z / (MAXZ - MINZ) * 3.0f;
                        finger.transform.position = newFingerPos;
                        prevFinger = pos;
                        tempFingerList.AddLast(newFingerPos);
                    }
                    else
                    {
                        // Get the controller position
                        Vector3 pos = SixenseInput.Controllers [1].Position;
                        // The camera position
                        Vector3 camPosition = cam.transform.position;
                        // Create the "finger" if it's null
                        if (finger == null)
                        {
                            finger = GameObject.Instantiate(UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Models/Fingertip.prefab", typeof(GameObject))) as GameObject;
                            finger.transform.position = new Vector3(camPosition.x * 0.6f, camPosition.y, camPosition.z * 0.6f);
                        }
                        Vector3 fingerPos = new Vector3(camPosition.x * 0.6f - ((pos.x - MINX - (MAXX - MINX) / 2.0f) / (MAXX - MINX) * 0.6f * toRight).x,
                                                        camPosition.y + (pos.y - MINY - (MAXY - MINY) / 2.0f) / (MAXY - MINY) * 0.5f,
                                                        camPosition.z * 0.6f - ((pos.x - MINX - (MAXX - MINX) / 2.0f) / (MAXX - MINX) * 0.6f * toRight).z);
                        finger.transform.position = fingerPos;
                        UnityEngine.Debug.DrawRay(fingerPos, toCenter, Color.red);
                        // Determine if there's a button press
                        if (SixenseInput.Controllers [1].GetButton(SixenseButtons.BUMPER))
                        {
                            clickTimer.Reset();
                            clickTimer.Start();
                            if (!isPushing)
                            {
                                // Save temp state of bricks if not pushing
                                tempPositions.Clear();
                                tempOrientations.Clear();
                                for (int i = 0; i < height * 3; ++i)
                                {
                                    GameObject brick = (GameObject)bricks [i];
                                    tempPositions.Add(brick.transform.position);
                                    tempOrientations.Add(brick.transform.rotation);
                                }
                            }
                            wasPressed     = true;
                            isPushing      = true;
                            prevFinger     = pos;
                            tempFingerList = new LinkedList <Vector3> ();
                        }
                    }
                }
                else
                {
                    // Obtain position information for the right controller
                    Vector3 pos = SixenseInput.Controllers [1].Position;

                    // Determine camera operations
                    // Rotate camera left
                    if (pos.x <= MINX + (MAXX - MINX) / 6)
                    {
                        cam.transform.RotateAround(origin, upVect, 1.0f);
                        cam2.transform.RotateAround(origin, upVect, 1.0f);
                        toRight  = Quaternion.Euler(0, 1, 0) * toRight;
                        toCenter = Quaternion.Euler(0, 1, 0) * toCenter;
                    }
                    // Rotate camera right
                    else if (pos.x >= MAXX - (MAXX - MINX) / 6)
                    {
                        cam.transform.RotateAround(origin, upVect, -1.0f);
                        cam2.transform.RotateAround(origin, upVect, -1.0f);
                        toRight  = Quaternion.Euler(0, -1, 0) * toRight;
                        toCenter = Quaternion.Euler(0, -1, 0) * toCenter;
                    }
                    // Shift camera down
                    if (pos.y <= MINY + (MAXY - MINY) / 6)
                    {
                        if (cam.transform.position.y >= 0.30f)
                        {
                            cam.transform.Translate(minorDown);
                            Vector3 ps = brickFrame.transform.position;
                            brickFrame.transform.position = new Vector3(Screen.width * 0.8f, ps.y - 0.00253f * Screen.width, ps.z);
                        }
                    }
                    // Shift camera up
                    else if (pos.y >= MAXY - (MAXY - MINY) / 6)
                    {
                        cam.transform.Translate(minorUp);
                        Vector3 ps = brickFrame.transform.position;
                        brickFrame.transform.position = new Vector3(Screen.width * 0.8f, ps.y + 0.00253f * Screen.width, ps.z);
                    }

                    if (isGameOver)
                    {
                        if (players == 1)
                        {
                            playerText.text = "Game Over!";
                        }
                        else
                        {
                            if (turn % 2 == 0)
                            {
                                playerText.text = "Game Over! Player 2 wins!";
                            }
                            else
                            {
                                playerText.text = "Game Over! Player 1 wins!";
                            }
                        }
                        if (SixenseInput.Controllers [1].GetButton(SixenseButtons.BUMPER))
                        {
                            wasPressed = true;
                        }
                        else                             // Bumper unpressed or released
                        {
                            if (wasPressed)
                            {
                                wasPressed = false;
                                isMenu     = true;
                            }
                        }
                    }

                    // Now determine if a button was pressed
                    if (SixenseInput.Controllers [1].GetButton(SixenseButtons.BUMPER))
                    {
                        if (wasPressed == false)
                        {
                            // Start the timer
                            clickTimer.Reset();
                            clickTimer.Start();
                        }
                        wasPressed = true;
                    }
                    else                         // Bumper unpressed or released
                    {
                        if (wasPressed && !isPushing)
                        {
                            wasPressed = false;
                            clickTimer.Stop();
                            long timePassed = clickTimer.ElapsedMilliseconds;
                            clickTimer.Reset();
                            if (timePassed < 700)
                            {
                                isPush = true;
                                isMenu = false;
                            }
                            else
                            {
                                isPush = false;
                                isMenu = true;
                            }
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 5
0
 // Fixed frame update func
 void FixedUpdate()
 {
     // Test if hydra is connected
     if (!SixenseInput.IsBaseConnected(0))
     {
         print("SIXENSE DEVICE NOT CONNECTED");
     }
     else
     {
         // Obtain the position information for this and update accordingly
         Vector3 pos = SixenseInput.Controllers[1].Position;
         if (pos.y >= MINY + (MAXY - MINY) / 4 * 3)
         {
             highlightButton("MODE");
         }
         else if (pos.y >= MINY + (MAXY - MINY) / 2)
         {
             if (pos.x >= MINX + (MAXX - MINX) / 2)
             {
                 highlightButton("MORE");
             }
             else
             {
                 highlightButton("LESS");
             }
         }
         else if (pos.y >= MINY + (MAXY - MINY) / 4)
         {
             highlightButton("START");
         }
         else
         {
             highlightButton("QUIT");
         }
         // Determine if there was a RT press
         if (SixenseInput.Controllers [1].GetButton(SixenseButtons.BUMPER))
         {
             wasPressed = true;
         }
         else
         {
             if (wasPressed)
             {
                 wasPressed = true;                     // Prevent unwanted modifies
                 if (isMode)
                 {
                     toggleMode();
                 }
                 else if (isMore)
                 {
                     modifyLayers(true);
                 }
                 else if (isLess)
                 {
                     modifyLayers(false);
                 }
                 else if (isStart)
                 {
                     gameStart();
                 }
                 else if (isQuit)
                 {
                     quitApp();
                 }
                 wasPressed = false;
             }
         }
     }
 }