Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        Collider hit = GetClosestHit();

        if (hit != null)
        {
            //print("Closest : " + hit.name);

            if (CurrentObject != hit.gameObject && ObjectInHand == null)
            {
                //MiddleVRTools.Log("Enter other : " + hit.name);
                HighlightObject(CurrentObject, false);
                CurrentObject = hit.gameObject;
                HighlightObject(CurrentObject, true);
                //MiddleVRTools.Log("Current : " + CurrentObject.name);
            }
        }
        // Else
        else
        {
            //MiddleVRTools.Log("No touch ! ");

            if (CurrentObject != null && CurrentObject != ObjectInHand)
            {
                HighlightObject(CurrentObject, false, HighlightColor);
                CurrentObject = null;
            }
        }

        //MiddleVRTools.Log("Current : " + CurrentObject);

        if (m_Buttons == null)
        {
            m_Buttons = MiddleVR.VRDeviceMgr.GetJoystick(JoystickName);
        }

        if (m_Buttons == null)
        {
            if (m_SearchedButtons == false)
            {
                //MiddleVRTools.Log("[~] VRWandInteraction: Wand buttons undefined. Please specify Wand Buttons in the configuration tool.");
                m_SearchedButtons = true;
            }
        }

        if (m_Buttons != null && CurrentObject != null)
        {
            VRActor script = CurrentObject.GetComponent <VRActor>();

            //MiddleVRTools.Log("Trying to take :" + CurrentObject.name);
            if (script != null)
            {
                // Grab
                if (m_Buttons.IsButtonToggled(m_MainButton))
                {
                    if (script.Grabable)
                    {
                        Grab(CurrentObject);
                    }
                }

                // Release
                if (m_Buttons.IsButtonToggled(m_MainButton, false) && ObjectInHand != null)
                {
                    Ungrab();
                }

                // Action
                if (((!RepeatAction && m_Buttons.IsButtonToggled(m_MainButton)) || (RepeatAction && m_Buttons.IsButtonPressed(m_MainButton))))
                {
                    CurrentObject.SendMessage("VRAction", SendMessageOptions.DontRequireReceiver);
                }
            }
        }
    }
Esempio n. 2
0
    void Update()
    {
        // keyboard
        //    this.transform.position += this.transform.forward * Input.GetAxis("Vertical") * keyboardSensitivity;
        //    this.transform.position += this.transform.right * Input.GetAxis("Horizontal") * keyboardSensitivity;


        if (MiddleVR.VRDeviceMgr != null)
        {
            if (onPressX)
            {
                if (r1.IsButtonPressed(0))
                {
                    deltax = tracker.transform.localRotation.y - oldx;
                    deltax = deltax * sensitivityX;

                    Debug.Log(deltax);
                    if (deltax < minimumX || deltax > maximumX)
                    {
                        deltax = 0;
                    }

                    //	obj.transform.Rotate(new Vector3(0,deltax,0) );
                    obj.transform.RotateAround(obj.transform.position, Vector3.up, deltax);


                    oldx = tracker.transform.localRotation.y;
                }
                else
                {
                    onPressX = false;
                }
            }
            if (r1.IsButtonToggled(0))
            {
                onPressX = true;
                oldx     = tracker.transform.localRotation.y;
            }



            if (onPressY)
            {
                if (r1.IsButtonPressed(6))
                {
                    deltay = tracker.transform.localRotation.x - oldy;

                    deltay = deltay * sensitivityY;

                    if (deltay < minimumY || deltay > maximumY)
                    {
                        deltay = 0;
                    }

                    //obj.transform.Rotate(new Vector3(deltay,0,0) );
                    obj.transform.RotateAround(obj.transform.position, Vector3.right, deltay);

                    oldy = tracker.transform.localRotation.x;
                }
                else
                {
                    onPressY = false;
                }
            }


            if (r1.IsButtonToggled(6))
            {
                onPressY = true;
                oldy     = tracker.transform.localRotation.x;
            }


            float translateX = r1.GetAxisValue(0) * sensitivityTranslateX;
            float translateY = r1.GetAxisValue(1) * sensitivitiyTranslateY;
            float translateZ = r2.GetAxisValue(1) * sensitivitiyTranslateZ;


            obj.transform.Translate(new Vector3(translateX, translateZ, translateY));
        }
    }