Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Null Controller!");
            return;
        }

        triggerPressed = controller.GetPress(triggerButton);

        if (controller.GetPressDown(menuButton))
        {
            zoomMode = !zoomMode;
            if (zoomMode)
            {
                zoomModeMat.SetColor("_TintColor", Color.magenta);
            }
            else
            {
                zoomModeMat.SetColor("_TintColor", Color.blue);
            }
        }

        RaycastHit hit;

        if (controller.GetPressDown(triggerButton))
        {
            //print("GotPress, Looking Forward: " + (transform.rotation * -Vector3.up));
            if (fileMode)
            {
                if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, vFileLayer))
                {
                    ImageFilePanel ifp = hit.collider.gameObject.GetComponent <ImageFilePanel>();
                    ifp.Select();
                    iScript.GoToIndex(ifp.index);
                }
                else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, vFileLayer))
                {
                    FolderPanel fp = hit.collider.gameObject.GetComponent <FolderPanel>();
                    fp.Select();
                    iScript.fScript.OpenDirectory(fp.filePath);
                }
                // Check for clicking Video Mode or Quit
                else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, modeLayer))
                {
                    UnityEngine.Application.LoadLevel(1);
                }
                else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, quitLayer))
                {
                    UnityEngine.Application.Quit();
                }
                else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, proportionLayer))
                {
                    HighlightButton hb = hit.collider.gameObject.GetComponent <HighlightButton>();
                    hb.EngageModeCommand();
                }
                else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, arrangementLayer))
                {
                    HighlightButton hb = hit.collider.gameObject.GetComponent <HighlightButton>();
                    hb.EngageModeCommand();
                }
                else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, centerLayer))
                {
                    iScript.ResetPosition();
                    proximityFactor = 1.5f;
                    otherController.proximityFactor = proximityFactor;
                }
                // Registers click on "Load Copied Directory"
                else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, loadLayer))
                {
                    castOffset = Vector3.zero;
                    if (Clipboard.ContainsText())
                    {
                        string text = Clipboard.GetText();
                        loadText.text = text;
                        //print("Text: " + text);
                        if (text.Length > 0)
                        {
                            dirScriptObject.SendMessage("LoadText", text);
                            startupOverlay.SetActive(false);
                        }
                    }
                }
                // Registers click on folder
                else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, folderLayer))
                {
                }
                // Registers click on scroll button - needs to manage movement afterward while held!
                else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, folderScrollLayer))
                {
                    if (!holdingFolderScroll)
                    {
                        oldPos = hit.point - scrollScript.transform.position;
                    }
                    else
                    {
                        scrollScript.Scroll((hit.point - scrollScript.transform.position - oldPos).x);
                        oldPos = hit.point - scrollScript.transform.position;
                    }

                    holdingFolderScroll = true;
                }
            }
            else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000))
            {
                castOffset = hit.point - imageTransform.position;
                //print("Offset: " + castOffset);
            }
            else
            {
                castOffset          = Vector3.zero;
                holdingFolderScroll = false;
            }
        }

        if (triggerPressed && castOffset.magnitude > 0 && !fileMode)
        {
            // Enables dragging of the image
            if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000))
            {
                //castOffset = hit.point - imageTransform.position;
                //print("Offset: " + castOffset);
                imageTransform.position = hit.point - castOffset;
                iScript.UpdateActiveImage();
            }
        }
        if (controller.GetPressDown(dButton))
        {
            Vector2 padDir = controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);
            if (padDir.x > 0.7f)
            {
                dirScriptObject.SendMessage("IndexUp");
            }
            else if (padDir.x < -0.7f)
            {
                dirScriptObject.SendMessage("IndexDown");
            }
        }
        if (controller.GetPress(dButton))
        {
            Vector2 padDir = controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);
            if (zoomMode)
            {
                if (padDir.y > 0.7f)
                {
                    if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000))
                    {
                        print("HitPoint: " + hit.collider.gameObject); // is triggered

                        dirScriptObject.SendMessage("ZoomIn", hit.point);
                    }
                    else
                    {
                        dirScriptObject.SendMessage("ZoomIn", imageTransform.position);
                    }
                }
                else if (padDir.y < -0.7f)
                {
                    if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000))
                    {
                        print("HitPoint: " + hit.collider.gameObject); // is triggered
                        dirScriptObject.SendMessage("ZoomOut", hit.point);
                    }
                    else
                    {
                        dirScriptObject.SendMessage("ZoomOut", imageTransform.position);
                    }
                }
            }
            else
            {
                // Next to player at -29
                if (padDir.y > 0.7f)
                {
                    proximityFactor += 1.25f * Time.deltaTime;
                    otherController.proximityFactor = proximityFactor;
                    //imageTransform.position = new Vector3(imageTransform.position.x, imageTransform.position.y,
                    //                                imageTransform.position.z + 4 * Time.deltaTime);
                }
                else if (padDir.y < -0.7f)
                {
                    proximityFactor -= 1.25f * Time.deltaTime;
                    otherController.proximityFactor = proximityFactor;
                    //imageTransform.position = new Vector3(imageTransform.position.x, imageTransform.position.y,
                    //                                imageTransform.position.z - 4 * Time.deltaTime);
                }
                // default proximityFactor is 1.5
                float zPos = 0.2963f * Mathf.Pow(proximityFactor, 3) - 29;
                imageTransform.localPosition = new Vector3(imageTransform.localPosition.x, imageTransform.localPosition.y,
                                                           zPos);
            }
        }

        if (controller.GetPressDown(gripButton))
        {
            //dirScriptObject.SendMessage("LoadText");
            fileMode = !fileMode;
            loadManager.SetActive(fileMode);
        }
        if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, modeLayer))
        {
            HighlightPanel hp = hit.collider.gameObject.GetComponent <HighlightPanel>();
            hp.isHighlighted = true;
        }
        if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, quitLayer))
        {
            HighlightPanel hp = hit.collider.gameObject.GetComponent <HighlightPanel>();
            hp.isHighlighted = true;
        }
        if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, loadLayer))
        {
            HighlightPanel hp = hit.collider.gameObject.GetComponent <HighlightPanel>();
            hp.isHighlighted = true;
        }
        if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, vFileLayer))
        {
            ImageFilePanel ifp = hit.collider.gameObject.GetComponent <ImageFilePanel>();
            ifp.isHighlighted = true;
            ifp.text.color    = Color.white;
        }
        if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, proportionLayer))
        {
            HighlightButton hb = hit.collider.gameObject.GetComponent <HighlightButton>();
            hb.isHighlighted = true;
        }
        if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, arrangementLayer))
        {
            HighlightButton hb = hit.collider.gameObject.GetComponent <HighlightButton>();
            hb.isHighlighted = true;
        }
        if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, centerLayer))
        {
            HighlightButton hb = hit.collider.gameObject.GetComponent <HighlightButton>();
            hb.isHighlighted = true;
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Null Controller!");
            return;
        }
        vScript.progHover = false;
        fileMode          = vScript.fileMode;

        //print("Axis0: " + controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0)); // axis0 is 2D, has (x,y) on D-pad
        triggerPressed = controller.GetPress(triggerButton);

        // pos coordinates are local
        //print("RController Coords" + controller.transform.pos); // .6 to 1.4 vert(y), -.1 to .4 forward (z), -.3 to .7 sideways (x)

        // Both have multiple values change during tilting
        //print("RController Tilts" + controller.transform.rot.eulerAngles);
        //print("RController QTilts" + controller.transform.rot);
        //print("RController XTilts" + controller.transform.rot.eulerAngles.x); // Never seems to go beyond 270 to 50
        //print("RController YTilts" + controller.transform.rot.eulerAngles.y); // Changed by motion on all 3 axes
        //print("RController ZTilts" + controller.transform.rot.eulerAngles.z); // Ranges from 270 to 90 on desired axis when normal
        // ranges from 90 to 270 when pulled back

        // Controller default rotation is laying flat
        //print("RController Angle:" + Quaternion.Angle(Quaternion.identity, controller.transform.rot));
        //Quaternion rotFrame = Quaternion.AngleAxis(90, Vector3.right) * controller.transform.rot;
        //print("RController FrameAngle:" + Quaternion.Angle(Quaternion.identity, rotFrame));
        // y ranges consitently from 270 to 90 for rotation on correct axis
        //print("RController FrameTilts" + rotFrame.eulerAngles);

        if (controller.GetPressDown(menuButton))
        {
            zoomMode = !zoomMode;
        }
        if (fileMode)
        {
            zoomModeMat.SetColor("_TintColor", new Color(1, 0.4f, 0));
        }
        else if (zoomMode)
        {
            zoomModeMat.SetColor("_TintColor", Color.magenta);
        }
        else
        {
            zoomModeMat.SetColor("_TintColor", Color.blue);
        }
        RaycastHit hit;

        // Need to replace "forward" with neg. "up"
        if (controller.GetPressDown(triggerButton))
        {
            //print("GotPress, Looking Forward: " + (transform.rotation * -Vector3.up));
            if (fileMode)
            {
                if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, vFileLayer))
                {
                    VideoFilePanel vfp = hit.collider.gameObject.GetComponent <VideoFilePanel>();
                    vfp.Select();
                    string fileDir = vfp.filePath;
                    vScript.file = fileDir;
                    vScript.LoadVideo();
                    startupOverlay.SetActive(false);
                }
                else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, modeLayer))
                {
                    UnityEngine.Application.LoadLevel(0);
                }
                else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, quitLayer))
                {
                    UnityEngine.Application.Quit();
                }
                else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, loopLayer))
                {
                    HighlightButton hb = hit.collider.gameObject.GetComponent <HighlightButton>();
                    hb.EngageModeCommand();
                }
                else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, centerLayer))
                {
                    vScript.ResetPosition();
                    proximityFactor = 2;
                    otherController.proximityFactor = 2;
                }
                else
                {
                    castOffset = Vector3.zero;
                    if (Clipboard.ContainsText())
                    {
                        string text = Clipboard.GetText();
                        loadText.text = text;
                        print("Text: " + text);
                        if (text.Length > 0)
                        {
                            vScript.text = text;
                            vScript.LoadVideoDir();
                        }
                    }
                }
            }
            else if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000))
            {
                if (hit.collider.gameObject.layer == 5) // Plane is in UI layer
                {
                    castOffset = hit.point - imageTransform.position;
                }
                else
                {
                    castOffset = Vector3.zero;
                }
                //print("Offset: " + castOffset);
            }
            else
            {
                castOffset = Vector3.zero;
            }
        }
        if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, progLayer))
        {
            vScript.progHover = true;
            vScript.ProgBarHover(hit.point);
        }
        if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, vFileLayer))
        {
            VideoFilePanel vfp = hit.collider.gameObject.GetComponent <VideoFilePanel>();
            vfp.isHighlighted = true;
            vfp.text.color    = Color.white;
        }
        if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, modeLayer))
        {
            HighlightPanel hp = hit.collider.gameObject.GetComponent <HighlightPanel>();
            hp.isHighlighted = true;
        }
        if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, quitLayer))
        {
            HighlightPanel hp = hit.collider.gameObject.GetComponent <HighlightPanel>();
            hp.isHighlighted = true;
        }

        if (triggerPressed && castOffset.magnitude > 0)
        {
            if (!vScript.progHover && Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, uiLayer))
            {
                //castOffset = hit.point - imageTransform.position;
                //print("Offset: " + castOffset);
                imageTransform.position = hit.point - castOffset;
            }
        }
        else if (triggerPressed && vScript.progHover)
        {
            vScript.ProgBarClick(hit.point);
        }
        if (controller.GetPressDown(dButton))
        {
            // nothing
        }
        if (controller.GetPress(dButton))
        {
            Vector2 padDir = controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);
            if (padDir.x > 0.7f)
            {
                //vScriptObject.SendMessage("IndexUp");
                vScript.timeShifting = 1;
            }
            else if (padDir.x < -0.7f)
            {
                //vScriptObject.SendMessage("IndexDown");
                vScript.timeShifting = -1;
            }
            //Vector2 padDir = controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);
            if (fileMode)
            {
                if (padDir.y > 0.7f)
                {
                    volumeBar.fillAmount += 0.33f * Time.deltaTime;
                    //vScript.vPlayer.SetDirectAudioVolume(0, volumeBar.fillAmount); // NO EFFECT
                    vScript.umPlayer.Volume = 100 * volumeBar.fillAmount;
                }
                else if (padDir.y < -0.7f)
                {
                    volumeBar.fillAmount -= 0.33f * Time.deltaTime;
                    //vScript.vPlayer.SetDirectAudioVolume(0, volumeBar.fillAmount); // NO EFFECT
                    vScript.umPlayer.Volume = 100 * volumeBar.fillAmount;
                }
            }
            else if (zoomMode)
            {
                Vector3 hitPass = imageTransform.position;
                if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000))
                {
                    hitPass = hit.point;
                }
                if (padDir.y > 0.7f)
                {
                    vScript.Zoom(true, hitPass);
                }
                else if (padDir.y < -0.7f)
                {
                    vScript.Zoom(false, hitPass);
                }
            }
            else
            {
                // Next to player at -29
                if (padDir.y > 0.7f)
                {
                    proximityFactor += 1.25f * Time.deltaTime;
                    otherController.proximityFactor = proximityFactor;
                    //imageTransform.position = new Vector3(imageTransform.position.x, imageTransform.position.y,
                    //                                imageTransform.position.z + 4 * Time.deltaTime);
                }
                else if (padDir.y < -0.7f)
                {
                    proximityFactor -= 1.25f * Time.deltaTime;
                    otherController.proximityFactor = proximityFactor;
                    //imageTransform.position = new Vector3(imageTransform.position.x, imageTransform.position.y,
                    //                                imageTransform.position.z - 4 * Time.deltaTime);
                }
                // default proximityFactor is 1
                float zPos = 0.5f * Mathf.Pow(proximityFactor, 3) + 0.5f;
                imageTransform.localPosition = new Vector3(imageTransform.localPosition.x, imageTransform.localPosition.y,
                                                           zPos);
            }
        }

        if (controller.GetPressDown(gripButton))
        {
            //vScript.LoadVideo();
            fileMode         = !fileMode;
            vScript.fileMode = fileMode;
            loadManager.SetActive(fileMode);
            if (fileMode)
            {
                vScript.umPlayer.Pause();
            }
            else
            {
                if (!vScript.umPlayer.IsPlaying)
                {
                    vScript.umPlayer.Play();
                }
                vScript.overlayBlocker.SetActive(false);
                print("W: " + vScript.umPlayer.VideoWidth + ", H: " + vScript.umPlayer.VideoHeight);
                vScript.umPlayer.RenderingObjects[0].transform.localScale
                    = new Vector3(1, (float)vScript.umPlayer.VideoHeight / vScript.umPlayer.VideoWidth, 1);
                vScript.LoadLengthString();
                //vScript.umPlayer.RenderingObjects[0].transform.localScale = new Vector3(1, 0.1f, 4);
            }
        }


        if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, loopLayer))
        {
            HighlightButton hb = hit.collider.gameObject.GetComponent <HighlightButton>();
            hb.isHighlighted = true;
        }
        if (Physics.Raycast(transform.position, transform.rotation * castDir, out hit, 10000, centerLayer))
        {
            HighlightButton hb = hit.collider.gameObject.GetComponent <HighlightButton>();
            hb.isHighlighted = true;
        }
    }