コード例 #1
0
    public SteamVR_LaserPointer pointer;              //!< pointer to the laser pointer at end of controller

    /*!
     * \brief initializes variables
     * \details This function initializes the pointers to the scene such as controllers,
     */
    void Awake()
    {
        GameObject controllerObject = GameObject.FindGameObjectWithTag("Right Controller") as GameObject;

        if (controllerObject != null & controller == null)
        {
            controller = controllerObject.GetComponent <SteamVR_TrackedObject>();
        }
        else
        {
            Debug.Log("controllerObject returned null");
        }
        if (controller != null)
        {
            try
            {
                pointer         = controller.GetComponent <SteamVR_LaserPointer>();
                controllerInput = controller.GetComponent <SteamVR_TrackedController>();
            }
            catch
            {
                Debug.LogError(this.name + ": Could not find LaserPointer");
            }
        }
    }
コード例 #2
0
ファイル: ListenSwap.cs プロジェクト: ryougi1/virtual_reality
    // Update is called once per frame
    void Update()
    {
        if (SteamVR_Controller.Input((int)leftHandController.index).GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            leftHandController.GetComponent <Pull>().enabled    = !leftHandController.GetComponent <Pull>().enabled;
            leftHandController.GetComponent <Running>().enabled = !leftHandController.GetComponent <Running>().enabled;

            //modelHandLeft.GetComponent<Collider>().isTrigger = !modelHandLeft.GetComponent<Collider>().isTrigger;

            isLeftFoot = !isLeftFoot;
            modelHandLeft.SetActive(!modelHandLeft.activeSelf);
            modelFootLeft.SetActive(!modelFootLeft.activeSelf);
            if (isLeftFoot == false)
            {
                leftHandController.GetComponent <Running>().canWalk = false;
            }

            /*
             * if (isLeftFoot)
             * {
             *  modelHandLeft.layer = LayerMask.NameToLayer("ControllerFoot");
             *  modelHandLeft.transform.parent.gameObject.layer = LayerMask.NameToLayer("ControllerFoot");
             * } else
             * {
             *  modelHandLeft.layer = LayerMask.NameToLayer("ControllerHand");
             *  modelHandLeft.transform.parent.gameObject.layer = LayerMask.NameToLayer("ControllerHand");
             * }
             */
        }
        if (SteamVR_Controller.Input((int)rightHandController.index).GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            rightHandController.GetComponent <Pull>().enabled    = !rightHandController.GetComponent <Pull>().enabled;
            rightHandController.GetComponent <Running>().enabled = !rightHandController.GetComponent <Running>().enabled;

            //modelHandRight.GetComponent<Collider>().isTrigger = !modelHandRight.GetComponent<Collider>().isTrigger;


            isRightFoot = !isRightFoot;
            modelHandRight.SetActive(!modelHandRight.activeSelf);
            modelFootRight.SetActive(!modelFootRight.activeSelf);
            if (isRightFoot == false)
            {
                rightHandController.GetComponent <Running>().canWalk = false;
            }

            /*
             * if (isRightFoot)
             * {
             *  modelHandRight.layer = LayerMask.NameToLayer("ControllerFoot");
             *  modelHandRight.transform.parent.gameObject.layer = LayerMask.NameToLayer("ControllerFoot");
             * }
             * else
             * {
             *  modelHandRight.layer = LayerMask.NameToLayer("ControllerHand");
             *  modelHandRight.transform.parent.gameObject.layer = LayerMask.NameToLayer("ControllerHand");
             * }
             */
        }
    }
コード例 #3
0
 private void Start()
 {
     // Consider why our models are neither meshRenderers on the network avatars, nor child objects of them.
     // How come we have to use joints?
     laser         = trackedObject.GetComponent <LineRenderer>();
     laser.enabled = false;
     maxDistLaser  = 100.0f;
     input         = SteamVR_Controller.Input((int)trackedObject.index);
     controller    = trackedObject.GetComponent <SteamVR_TrackedController>();
     model         = transform.parent.FindChild(this.name + "Model").gameObject;
 }
コード例 #4
0
    void NewspaperManager()
    {
        // Grab
        if (SteamVR_Controller.Input((int)m_controllerLeft.index).GetPress(SteamVR_Controller.ButtonMask.Trigger) &&
            !m_newspaperInHand)
        {
            m_newspaperInHand = Instantiate(m_newspaperPrefab);
            m_newspaperInHand.transform.position = m_controllerLeft.transform.position;
            m_newspaperInHand.transform.rotation = m_controllerLeft.transform.rotation;
            FixedJoint joint = m_controllerLeft.gameObject.AddComponent <FixedJoint>();
            joint.breakForce    = 20000;
            joint.breakTorque   = 20000;
            joint.connectedBody = m_newspaperInHand.GetComponent <Rigidbody>();
        }
        // Release
        else if (!SteamVR_Controller.Input((int)m_controllerLeft.index).GetPress(SteamVR_Controller.ButtonMask.Trigger) &&
                 m_newspaperInHand)
        {
            FixedJoint joint = m_controllerLeft.gameObject.GetComponent <FixedJoint>();
            if (joint)
            {
                joint.connectedBody = null;
                Destroy(joint);

                m_newspaperInHand.GetComponent <Rigidbody>().velocity        = SteamVR_Controller.Input((int)m_controllerLeft.index).velocity;
                m_newspaperInHand.GetComponent <Rigidbody>().angularVelocity = SteamVR_Controller.Input((int)m_controllerLeft.index).angularVelocity;
            }
            m_newspaperInHand.transform.parent = m_newspaperPool.transform;
            m_newspaperInHand = null;
        }

        if (SteamVR_Controller.Input((int)m_controllerRight.index).GetPress(SteamVR_Controller.ButtonMask.Trigger))
        {
            /*m_newspaperInHand = Instantiate(m_newspaperPrefab);
             * m_newspaperInHand.transform.position = m_controllerRight.transform.position;
             * m_newspaperInHand.transform.rotation = m_controllerRight.transform.rotation;
             * FixedJoint joint = m_controllerRight.gameObject.AddComponent<FixedJoint>();
             * joint.breakForce = 20000;
             * joint.breakTorque = 20000;
             * joint.connectedBody = m_newspaperInHand.GetComponent<Rigidbody>();*/
            DrawBallisticCurve();
            m_throwNewspaper    = true;
            m_timeElapsedForce += Time.deltaTime;
        }
        else if (m_throwNewspaper && !SteamVR_Controller.Input((int)m_controllerRight.index).GetPress(SteamVR_Controller.ButtonMask.Trigger))
        {
            m_controllerRight.GetComponent <LineRenderer>().enabled = false;
            ThrowNewspaper();
            m_throwNewspaper   = false;
            m_timeElapsedForce = 0;
        }
    }
コード例 #5
0
    void Update()
    {
        input.RightTriggerDown();
        Transform  controller = input.controllerPosition();// Get position of the controller
        RaycastHit hit;

        if (Physics.Raycast(controller.position, controller.forward, out hit, 100)) // Cast a ray and saves the hit point and object
        {
            this.gameObject.GetComponent <Canvas>().enabled = true;
            hitpoint           = hit.point;
            transform.position = hitpoint;                                       // Change the position of the reticle to the hit point
            Vector3.MoveTowards(transform.position, controller.position, 0.05f); // Push the point just a little closer to the controller to make sure it is not hidden by the target

            // Check if the user shoots
            if (input.RightTriggerDown())
            {
                GameObject hitObj = hit.transform.gameObject;
                if (hitObj.tag == "target")
                {
                    rightHand.GetComponent <AudioSource>().Play();
                    Destroy(hitObj);
                    score += pointsPerTarget;
                }
            }
        }
        else
        {
            this.gameObject.GetComponent <Canvas>().enabled = false;
        }
    }
コード例 #6
0
    private void ReleaseObject()
    {
        if (trackedObj.GetComponent <FixedJoint>())
        {
            trackedObj.GetComponent <FixedJoint>().connectedBody = null;
            Destroy(trackedObj.GetComponent <FixedJoint>());
            objectInHand.GetComponent <Rigidbody>().useGravity = true;
#if SteamVR_Legacy
            objectInHand.GetComponent <Rigidbody>().velocity        = Controller.velocity;
            objectInHand.GetComponent <Rigidbody>().angularVelocity = Controller.angularVelocity;
#elif SteamVR_2
            objectInHand.GetComponent <Rigidbody>().velocity        = trackedObj.GetVelocity();
            objectInHand.GetComponent <Rigidbody>().angularVelocity = trackedObj.GetAngularVelocity();
#endif
        }
        objectInHand = null;
    }
コード例 #7
0
 private void OnTriggerEnter(Collider obj)
 {
     if (controller.GetComponent <Pull>().enabled == false)
     {
         return;
     }
     canGrip = true;
 }
コード例 #8
0
    private void HandleTriggerUp(SteamVR_TrackedObject hand)
    {
        HandController handController = hand.GetComponent <HandController> ();

        handController.ClearEvents();
//		handController.triggerUpEvents = s.triggerUpEvents;
        ShootGameController.Instance.StartGame();
    }
コード例 #9
0
    private int id;                                          //!< unique id of a furniture peice

    //[DontSaveMember]
    //Material thisShader;


    /*!
     * \brief Runs upon start and initializes variables
     * \details This function initializes the controller listeners and SteamVr laser pointer
     */
    void Awake()
    {
        //Can't be completed on furniture in the room at start


        if (controller != null)
        {
            try
            {
                pointer         = controller.GetComponent <SteamVR_LaserPointer>();
                controllerInput = controller.GetComponent <SteamVR_TrackedController>();
            }
            catch
            {
                Debug.LogError(this.name + ": Could not find LaserPointer");
            }
        }
    }
コード例 #10
0
 private void OnTriggerEnter(Collider obj)
 //void OnCollisionEnter(Collision col)
 {
     if (controller.GetComponent <Running>().enabled == false)
     {
         return;
     }
     canWalk = true;
 }
コード例 #11
0
    //private Transform cameraRigTransform;

    void Start()
    {
        leftController      = leftTrackedObject.GetComponent <ViveInputController>();
        mainCameraTransform = Camera.main.GetComponent <Transform>();
        //cameraRigTransform = mainCameraTransform.parent;

        laser                    = Instantiate(laserPrefab);
        laserTransform           = laser.transform;
        reticle                  = Instantiate(teleportReticlePrefab);
        teleportReticleTransform = reticle.transform;
    }
コード例 #12
0
        void FixedUpdate()
        {
            if (currentController == null)
            {
                return;
            }
            var device = SteamVR_Controller.Input((int)currentController.index);

            //
            // End interation if the object is pulled too fast
            var rigidBody               = GetComponent <Rigidbody>();
            var controllerVelocitySq    = device.velocity.sqrMagnitude;
            var maxControllerVelocitySq = Mathf.Pow(10f / rigidBody.mass, 2);
            var forceAmout              = Math.Min(controllerVelocitySq / maxControllerVelocitySq, 1f);
            var controllerGauge         = currentController.GetComponent <IForceGauge>();

            // Update gauge based on interaction
            if (controllerGauge != null && ShowGauge)
            {
                controllerGauge.ForceValue = forceAmout;
            }

            // Trigger haptics
            if (HapticsOnDrag)
            {
                var hapticsAmout = Math.Max(forceAmout - 0.2f, 0f);
                SteamVR_Controller.Input((int)currentController.index).TriggerHapticPulse((ushort)(hapticsAmout * 5000));
            }

            // Drop object when moving faster than allowed
            if (controllerVelocitySq > maxControllerVelocitySq)
            {
                EndInteraction(currentController);

                // Dropped by releasing the trigger
            }
            else if (currentJoint != null && device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
            {
                EndInteraction(currentController);
            }
        }
コード例 #13
0
ファイル: Furniture_new.cs プロジェクト: nschue/RoomView
    // Use this for initialization
    void Awake()
    {
        //Can't be completed on furniture in the room at start

        //controller is empty do this

        /*GameObject controllerObject = GameObject.FindGameObjectWithTag("Right Controller") as GameObject;
         * //controller = controllerObject.GetComponent<SteamVR_TrackedObject>();*/


        if (controller != null)
        {
            try
            {
                pointer         = controller.GetComponent <SteamVR_LaserPointer>();
                controllerInput = controller.GetComponent <SteamVR_TrackedController>();
            }
            catch
            {
                Debug.LogError(this.name + ": Could not find LaserPointer");
            }
        }
    }
コード例 #14
0
    private void OnEnable()
    {
        controllerManager = rightHandControl.GetComponent <ControllerManager>();

        developerDefined = new AirSigManager.OnDeveloperDefinedMatch(HandleOnDeveloperDefinedMatch);
        airsigManager.onDeveloperDefinedMatch += developerDefined;
        airsigManager.SetDeveloperDefinedTarget(new List <string> {
            "BOTRN", "DOWN"
        });
        airsigManager.SetClassifier("FrostGestureProfile", "");

        airsigManager.SetTriggerStartKeys(
            AirSigManager.Controller.RIGHT_HAND,
            SteamVR_Controller.ButtonMask.Trigger,
            AirSigManager.PressOrTouch.PRESS);

        trackedObj = GetComponent <SteamVR_TrackedObject>();
    }
コード例 #15
0
    // Update is called once per frame
    void Update()
    {
        transform.rotation = Quaternion.Lerp(transform.rotation, tracker.transform.rotation, 20 * Time.deltaTime);
        transform.position = tracker.transform.position + tracker.transform.forward * 0.2f;
        // Check if a ranged attribute is powered
        if (Ranged_Power_Button != null)
        {
            ranged_On = Ranged_Power_Button.ActiveQuery;
        }

        if (queryButton.ActiveQuery == true && sendQuery == false)
        {
            Query        = "";
            queryStrings = new ArrayList();
            ageStrings   = new ArrayList();

            for (int i = 0; i < labels.Length; i++)
            {
                if (pwr_btns[i].ActiveQuery)
                {
                    // maybe should be arrayList? instead of string
                    Query += labels[i].ToString() + " ";
                    queryStrings.Add(labels[i].ToString());
                }
            }
            if (ranged_On)
            {
                int min = Ranged_Attribute.A;
                int max = Ranged_Attribute.B;
                for (int i = min; i <= max; i++)
                {
                    ageStrings.Add("age-" + i);
                }
            }
            SendQuery();
            sendQuery = true;
        }
        if (queryButton.ActiveQuery == false)
        {
            sendQuery = false;
        }
        SteamVR_Controller.Device device = SteamVR_Controller.Input((int)tracker.index);
        cont = tracker.GetComponent <SteamVR_TrackedController>();
    }
コード例 #16
0
        public override void OnTriggerDownColliding(SteamVR_TrackedObject controller)
        {
            // Clean previous interaction
            if (currentController != null)
            {
                EndInteraction(currentController);
            }

            // Try to acquire a lock for this controller
            if (!InputController.Instance.Lock(controller))
            {
                return;                                             // Stop if someone already has it
            }
            // Disable colisions that would push this object
            foreach (Collider collider in controller.GetComponents <Collider>())
            {
                if (collider.isTrigger)
                {
                    continue;
                }
                foreach (Collider objectCollider in GetComponents <Collider>())
                {
                    Debug.Log("Collision disabled" + collider + " " + objectCollider);
                    Physics.IgnoreCollision(collider, objectCollider, true);
                }
            }

            // Attach
            currentController = controller;
            var joint = gameObject.AddComponent <ConfigurableJoint>();

            joint.xMotion        = ConfigurableJointMotion.Locked;
            joint.yMotion        = ConfigurableJointMotion.Locked;
            joint.zMotion        = ConfigurableJointMotion.Locked;
            joint.angularXMotion = ConfigurableJointMotion.Locked;
            joint.angularYMotion = ConfigurableJointMotion.Locked;
            joint.angularZMotion = ConfigurableJointMotion.Locked;
            joint.connectedBody  = currentController.GetComponent <Rigidbody>();
            joint.breakForce     = breakForce;

            currentJoint = joint;
        }
コード例 #17
0
    // Update is called once per frame
    void Update()
    {
        if (Controller.GetHairTriggerDown()) // When the player squeezes the trigger and there’s a potential grab target, this grabs it
        {
            //this 'if statement' is needed to avoid issues while creating and moving measurement points
            if (canvasOnController != null)
            {
                if (canvasOnController.activeSelf == true & trackedObj.GetComponent <VR_Measurement_tool>().isActiveAndEnabled)
                {
                    collidingObjInfo.text = "Please, hide the Canvas on this" + "\n" + "controller by pressing the 'Menu Button'" + "\n" + "before moving and creating new points";
                    return;
                }
            }

            if (collidingObject) //if there is a collidingObject
            {
                GrabObject();
                grabbing = true;
            }
        }

        if (Controller.GetHairTriggerUp()) // If the player releases the trigger and there’s an object attached to the controller, this releases it
        {
            if (objectInHand)
            {
                ReleaseObject();
                grabbing = false;
            }
        }

        if (collidingObject)
        {
            if (collidingObject.activeSelf == false) //if the collidingObject gets destroyed (ex. when you destroy the points that you don't need anymore for measurement) the 'collidingObj' and 'originalMat'
            {                                        //are set to "null"; you also need to set the 'grabbing' bool to false for the 'VR_Measurement_tool' script to work as expected
                collidingObject = null;
                originalMat     = null;
                grabbing        = false;
            }
        }
    }
    // Use this for initialization
    void Start()
    {
        pointer                       = controllerRightObject.GetComponent <SteamVR_LaserPointer>();
        pointer.PointerIn            += PointerInDelegate;
        pointer.PointerOut           += PointerOutDelegate;
        controller                    = pointer.GetComponent <SteamVR_TrackedController>();
        controller.TriggerClicked    += TriggerDelegate;
        controller.MenuButtonClicked += MenuButtonDelegate;
        infoTextMesh                  = textView.GetComponent <TextMesh>();
        string     configJson = System.IO.File.ReadAllText("config.cfg");
        JSONObject json       = new JSONObject(configJson);

        json.GetField(out useFolder, "useFolder", false);
        print("got useFolder: " + useFolder);
        if (useFolder)
        {
            string path;
            json.GetField(out path, "folder", null);
            print("got folder: " + path);
            WebList webList = listView.GetComponent <WebList>();
            listLocation = path;
            webList.SetupFolder(path);
        }
        else
        {
            string dlLocation;
            json.GetField(out listLocation, "listLocation", "");
            json.GetField(out dlLocation, "dlLocation", "");
            print("got listLocation: " + listLocation);
            print("got dlLocation: " + dlLocation);

            WebList webList = listView.GetComponent <WebList>();
            webList.Setup(listLocation);
            WEB_DL_LOCATION = dlLocation;
        }
    }
コード例 #19
0
    void FixedUpdate()
    {
        SteamVR_Controller.Device device = SteamVR_Controller.Input((int)tObj.index);

        //Debug.Log("Fixed update, Controller is: " + device);
        //Debug.Log(device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger));
        if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            if (tObj != null)
            {
                joint.connectedBody = tObj.GetComponent <Rigidbody>();
            }
        }
        else
        {
            if (joint.connectedBody != null)
            {
                target.GetComponent <Rigidbody>().velocity           = device.velocity;
                target.GetComponent <Rigidbody>().angularVelocity    = device.angularVelocity;
                target.GetComponent <Rigidbody>().maxAngularVelocity = target.GetComponent <Rigidbody>().angularVelocity.magnitude;
                joint.connectedBody = null;
            }
        }
    }
コード例 #20
0
        // Update is called once per frame
        void Update()
        {
            if (selector_type != curr_selector_type)
            {
                {
                    Selector selector = left_controller.GetComponent <Selector>();
                    if (selector)
                    {
                        Destroy(selector);
                    }
                }
                {
                    Selector selector = right_controller.GetComponent <Selector>();
                    if (selector)
                    {
                        Destroy(selector);
                    }
                }
                {
                    Selector selector = head.GetComponent <Selector>();
                    if (selector)
                    {
                        Destroy(selector);
                    }
                }

                switch (selector_type)
                {
                case SelectorType.Direct:
                    left_controller.gameObject.AddComponent <DirectSelector>();
                    right_controller.gameObject.AddComponent <DirectSelector>();
                    break;

                case SelectorType.HandRay:
                    left_controller.gameObject.AddComponent <HandRaySelector>();
                    right_controller.gameObject.AddComponent <HandRaySelector>();
                    break;

                case SelectorType.EyeHandRay:
                    EyeHandRaySelector lselector = left_controller.gameObject.AddComponent <EyeHandRaySelector>();
                    EyeHandRaySelector rselector = right_controller.gameObject.AddComponent <EyeHandRaySelector>();
                    lselector.isRightEyeDominant = (dominant_eye == DominantEyeType.Righteye);
                    rselector.isRightEyeDominant = (dominant_eye == DominantEyeType.Righteye);
                    break;

                case SelectorType.HeadRay:
                    head.gameObject.AddComponent <HeadRaySelector>();
                    break;
                }

                curr_selector_type = selector_type;
            }

            if (curr_dominant_eye != dominant_eye && curr_selector_type == SelectorType.EyeHandRay)
            {
                EyeHandRaySelector lselector = left_controller.gameObject.GetComponent <EyeHandRaySelector>();
                EyeHandRaySelector rselector = right_controller.gameObject.GetComponent <EyeHandRaySelector>();
                if (lselector != null)
                {
                    lselector.isRightEyeDominant = (dominant_eye == DominantEyeType.Righteye);
                }
                if (rselector != null)
                {
                    rselector.isRightEyeDominant = (dominant_eye == DominantEyeType.Righteye);
                }

                curr_dominant_eye = dominant_eye;
            }
        }
コード例 #21
0
 void Awake()
 {
     rightTrackedObj = rightTrackedObj.GetComponent <SteamVR_TrackedObject>();
     leftTrackedObj  = leftTrackedObj.GetComponent <SteamVR_TrackedObject>();
 }
コード例 #22
0
 private void RightDeviceActive(SteamVR_TrackedObject obj)
 {
     DeviceActive(obj, rightIndex);
     RightHandInput = obj.GetComponent <DeviceInput>();
 }
コード例 #23
0
 private void LeftDeviceActive(SteamVR_TrackedObject obj)
 {
     DeviceActive(obj, leftIndex);
     LeftHandInput = obj.GetComponent <DeviceInput>();
 }
コード例 #24
0
 void OnEnable()
 {
     rightController.GetComponent <SteamVR_LaserPointer>().enabled = true;
 }
コード例 #25
0
 void Start()
 {
     //myItem.SetActive(false);
     hand = controller.GetComponent <SwapModels>();
 }
コード例 #26
0
ファイル: OMenuClick.cs プロジェクト: nschue/RoomView
    private SteamVR_LaserPointer pointer;               //!< pointer to the laser pointer


    /*!
     * \brief Runs upon gameobject spawn (at start) and initializes image GO and pointer
     */
    void Start()
    {
        activeImage = GetComponent <UnityEngine.UI.Image>();        // get the image component
        pointer     = controller.GetComponent <SteamVR_LaserPointer>();
    }
コード例 #27
0
        public void FixedUpdate()
        {
            // Not doing anything if not interacting
            if (trackedController == null)
            {
                return;
            }

            var device    = SteamVR_Controller.Input((int)trackedController.index);
            var rigidBody = GetComponent <Rigidbody>();

            // Line between object and controller
            var lineRenderer = trackedController.GetComponent <LineRenderer>();

            lineRenderer.enabled = currentJoint == null;

            // Move object towards you while there is no joint
            if (currentJoint == null)
            {
                // distance betwen where it is and where it should be
                var positionTarget       = trackedController.transform.position + trackedController.transform.forward * 0.06f;
                var attachPoint          = transform.TransformPoint(collisionOffset);
                var distanceDelta        = positionTarget - attachPoint;
                var distanceMassRelation = (float)Math.Sqrt((float)Math.Pow(rigidBody.mass, 2f) / distanceDelta.sqrMagnitude) / 1000f;

                // Increase amount of work done
                currentWork += distanceMassRelation;

                // Haptics
                if (hapticsOnDrag)
                {
                    SteamVR_Controller.Input((int)trackedController.index).TriggerHapticPulse((ushort)(distanceDelta.magnitude * 1000));
                }

                // Drop it if pulled too fast
                var lineTension = distanceDelta.magnitude * rigidBody.mass / 7f; // Constant for line tension strength

                // Set line initial and final position
                if (lineRenderer != null)
                {
                    lineRenderer.SetPosition(0, positionTarget);
                    lineRenderer.SetPosition(1, attachPoint);
                    var lineW = Math.Max((1 - lineTension) * 0.01f, 0.001f);
                    lineRenderer.SetWidth(lineW, lineW);
                    var c = Math.Max(Math.Min(1, lineTension), 0);
                    lineRenderer.material.color = new Color(c, 1 - c, 0);
                }

                // Break the line based on its tension
                if (lineTension > 1 && lineBreaks)
                {
                    EndInteraction(trackedController);
                    return;
                }

                // Create joint if too close
                var bounds = GetComponent <Renderer>().bounds;
                bounds.Expand(0.2f);
                if ((
                        (attachMode == AttachMode.Timer && interactionTime + attachTimer * rigidBody.mass < Time.time) ||
                        (attachMode == AttachMode.Work && currentWork > attachWork * rigidBody.mass)
                        ) && (
                        (attachCondition == AttachCondition.ProximityToBounds && bounds.Contains(positionTarget)) ||
                        (attachCondition == AttachCondition.CollisionWithObject && collidingWithController)
                        ))
                {
                    if (hideControllerOnSnap)
                    {
                        foreach (Renderer renderer in trackedController.GetComponentsInChildren <Renderer>())
                        {
                            renderer.enabled = false;
                        }
                        foreach (Collider collider in trackedController.GetComponents <Collider>())
                        {
                            if (!collider.isTrigger)
                            {
                                collider.enabled = false;
                            }
                        }
                        transform.position = trackedController.transform.position;
                    }

                    var createJoint = true;
                    if (snapPoint != null)
                    {
                        // Disable colliders
                        foreach (var collider in GetComponents <Collider>())
                        {
                            collider.enabled = false;
                        }

                        var finalTarget = positionTarget + (transform.position - snapPoint.position);
                        createJoint = (snapPoint.position - positionTarget).magnitude < 0.04;

                        rigidBody.transform.position = Vector3.Slerp(
                            transform.position,
                            finalTarget,
                            10f * Time.fixedDeltaTime
                            );
                        rigidBody.transform.rotation = Quaternion.Slerp(
                            rigidBody.transform.rotation,
                            Quaternion.LookRotation(trackedController.transform.forward * -1, snapPoint.up),
                            15f * Time.fixedDeltaTime
                            );

                        Debug.Log("snapping!" + finalTarget + " -> " + device.transform.pos);
                        Debug.DrawLine(transform.TransformPoint(snapPoint.localPosition), positionTarget, Color.green);
                    }

                    // Attach
                    if (createJoint)
                    {
                        // Re enable colliders
                        foreach (var collider in GetComponents <Collider>())
                        {
                            collider.enabled = true;
                        }

                        // Disable colisions that would push this object and break the joint
                        foreach (Collider collider in trackedController.GetComponents <Collider>())
                        {
                            if (collider.isTrigger)
                            {
                                continue;
                            }
                            foreach (Collider objectCollider in GetComponents <Collider>())
                            {
                                Physics.IgnoreCollision(collider, objectCollider, true);
                            }
                        }

                        var joint = gameObject.AddComponent <ConfigurableJoint>();
                        joint.xMotion        = ConfigurableJointMotion.Locked;
                        joint.yMotion        = ConfigurableJointMotion.Locked;
                        joint.zMotion        = ConfigurableJointMotion.Locked;
                        joint.angularXMotion = ConfigurableJointMotion.Locked;
                        joint.angularYMotion = ConfigurableJointMotion.Locked;
                        joint.angularZMotion = ConfigurableJointMotion.Locked;
                        joint.connectedBody  = trackedController.GetComponent <Rigidbody>();
                        joint.breakForce     = breakForce;

                        rigidBody.velocity        = new Vector3();
                        rigidBody.angularVelocity = new Vector3();

                        currentJoint = joint;
                    }
                }
                else
                {
                    // Disable gravity if it's being pulled
                    rigidBody.useGravity = false;

                    /**
                     * Move objects according to selected option
                     * */
                    if (moveBy == MoveBy.ApplyingForce)
                    {
                        var wCollisionOffset = transform.TransformPoint(collisionOffset);
                        rigidBody.AddForceAtPosition((positionTarget - wCollisionOffset).normalized / (rigidBody.mass * .01f), wCollisionOffset);
                        rigidBody.maxAngularVelocity = 2f;
                        //Debug.DrawRay(wCollisionOffset, (positionTarget - wCollisionOffset) / rigidBody.mass *10, Color.cyan);
                    }
                    else if (moveBy == MoveBy.ChangingVelocity)
                    {
                        var wCollisionOffset = transform.TransformPoint(collisionOffset);
                        rigidBody.velocity           = (positionTarget - wCollisionOffset) / (rigidBody.mass * 0.1f);
                        rigidBody.maxAngularVelocity = 2f;

                        // Throttle velocity when object is too light
                        if (rigidBody.velocity.sqrMagnitude > Mathf.Pow(MaxVelocity, 2))
                        {
                            rigidBody.velocity = rigidBody.velocity.normalized * MaxVelocity;
                        }
                        //Debug.DrawRay(wCollisionOffset, (positionTarget - wCollisionOffset) / rigidBody.mass *10, Color.cyan);
                    }
                    else if (moveBy == MoveBy.Slerp)
                    {
                        var interpolationAmount = 0.005f;                   // 10f / rigidBody.mass * Time.fixedDeltaTime;
                        rigidBody.velocity          *= Time.fixedDeltaTime; // Decrease physics velocity because we don't want other objecs interfearing with our pull
                        rigidBody.transform.position = Vector3.Slerp(rigidBody.transform.position, positionTarget, interpolationAmount);
                        rigidBody.transform.rotation = trackedController.transform.rotation * rotationOffset;
                    }
                }
            }

            if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
            {
                EndInteraction(trackedController);
            }
        }
コード例 #28
0
    public void SetGameState(SteamVR_TrackedObject hand, GameState state)
    {
        HandController handController = hand.GetComponent <HandController> ();

        handController.SetGameState(state);
    }
コード例 #29
0
 private void HandleHighlight(SteamVR_TrackedObject hand)
 {
     SoundManager.Instance.PlayHighlightSound();
     hand.GetComponent <HandController> ().SetGameState(GameState.UI);
     s.unHighlightEvents += HandleUnHighlight;
 }
コード例 #30
0
 private void HandleUnHighlight(SteamVR_TrackedObject hand)
 {
     hand.GetComponent <HandController> ().SetGameStateByPreGameState();
 }