void Update()
        {
            if (controller == null)
            {
                Debug.Log("Controller not initialized");
                return;
            }

            if (controller.GetPressDown(gripButton))
            {
                interactingItem = GetClosestItem();

                if (interactingItem)
                {
                    //if object is allready interacting with something else then drop it
                    if (interactingItem.IsInteracting())
                    {
                        interactingItem.EndInteraction(this);
                    }

                    interactingItem.BeginInteraction(this);
                }
            }
            else if (controller.GetPressUp(gripButton) && interactingItem != null)
            {
                interactingItem.EndInteraction(this);
            }
        }
    public void pickUp()
    {
        float minDistance = float.MaxValue;
        float distance;

        closestItem = null;
        foreach (InteractableItem item in objectsHoveringOver)
        {
            distance = (item.transform.position - transform.position).sqrMagnitude;
            if (distance < minDistance)
            {
                minDistance = distance;
                closestItem = item;
            }
        }
        interactingItem = closestItem;

        if (interactingItem)
        {
            makeVisible(false);

            if (interactingItem.IsInteracting())
            {
                interactingItem.OnExitInteraction(this);
            }
            interactingItem.OnEnterInteraction(this);
        }
    }
Exemple #3
0
    private void DetectObjectHitLabel()
    {
        InteractableItem currentHitObject = hitInteractable.GetComponent <InteractableItem>();

        //Detect what is hit with the ray, Can be a menu, arrows or an item.
        if (currentHitObject != null)
        {
            if (currentHitObject.isMenuItem)
            {
                prefab          = (GameObject)Instantiate(currentHitObject.worldPrefab, transform.position, Quaternion.Euler(0, 0, 0)); //Spawn it at the controllers pos and with 0 rotation (facing upwards)
                interactingItem = prefab.GetComponent <InteractableItem>();                                                             //Is only used for letting an object go again in this case
                interactingItem.BeginInteraction(this);
                Debug.Log(interactingItem);
            }
            else if (currentHitObject.isArrow)
            {
                currentHitObject.GetComponent <Arrows>().pressed = true;
                interactingItem = null;
            }
            else
            {
                interactingItem = currentHitObject;
            }

            if (interactingItem)                     //Starts interacting with the chosen item
            {
                if (interactingItem.IsInteracting()) //this statement is used in order to grap an item in the other hand
                {
                    interactingItem.EndInteraction(this, false);
                }

                interactingItem.BeginInteraction(this);
            }
        }
    }
    void Update()
    {
        if (controller.GetPressDown(triggerButton))
        {
            float min = float.MaxValue;
            float distance;

            foreach (InteractableItem obj in objects)
            {
                distance = (obj.transform.position - transform.position).sqrMagnitude;

                if (distance < min)
                {
                    min         = distance;
                    closestItem = obj;
                }

                inHandItem = closestItem;

                if (inHandItem)
                {
                    if (inHandItem.IsInteracting())
                    {
                        inHandItem.EndInteraction(this);
                    }

                    inHandItem.BeginInteraction(this);
                }
            }
        }
        if (controller.GetPressUp(triggerButton) && inHandItem != null)
        {
            inHandItem.EndInteraction(this);
        }
    }
Exemple #5
0
    void Update()
    {
        if (publishtf)
        {
            _tfmsg.transforms[0].header.stamp           = ROS.GetTime();
            _tfmsg.transforms[0].header.stamp.data.sec += 18000; //windows time is dumb
            //Debug.Log("Current time" + ROS.GetTime().data.sec);
            tfPub.publish(_tfmsg);
        }
        if (hj == null)
        {
            hj = GameObject.Find(frame_id);
        }
        else if (!interactableItem.IsInteracting())
        {
            if (!startedInteracting)
            {
                //Debug.Log("Not interacting!");
                Vector3    t = hj.transform.position;
                Quaternion q = hj.transform.rotation;
                transform.position = t;
                transform.rotation = q;
            }
            if (startedInteracting)
            {
                Messages.tf.tfMessage tfmsg = new Messages.tf.tfMessage();

                Messages.geometry_msgs.TransformStamped[] arr = new Messages.geometry_msgs.TransformStamped[1];
                arr[0] = new Messages.geometry_msgs.TransformStamped();

                tfmsg.transforms = arr;
                //Transform trans = trackedObj.transform;
                emTransform ta = new emTransform(transform, ROS.GetTime(), "/world", "/look_at_frame");

                Messages.std_msgs.Header hdr = new Messages.std_msgs.Header();
                hdr.frame_id = "/world";

                hdr.stamp           = ROS.GetTime();
                hdr.stamp.data.sec += 18000;

                tfmsg.transforms[0].header                = hdr;
                tfmsg.transforms[0].child_frame_id        = "/look_at_frame";
                tfmsg.transforms[0].transform             = new Messages.geometry_msgs.Transform();
                tfmsg.transforms[0].transform.translation = ta.origin.ToMsg();
                tfmsg.transforms[0].transform.rotation    = ta.basis.ToMsg();
                tfmsg.Serialized = null;

                tfPub.publish(tfmsg);
                _tfmsg             = tfmsg;
                publishtf          = true;
                startedInteracting = false;
            }
        }
        else
        {
            startedInteracting = true;
        }
    }
Exemple #6
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not yet initialized");
            return;
        }

        if (controller.GetPressDown(gripButton))
        {
            Debug.Log("gripButtonDown detected");
            float minDistance = float.MaxValue;

            float distance;
            foreach (InteractableItem item in objectsHoveringOver)
            {
                distance = (item.transform.position - transform.position).sqrMagnitude;

                if (distance < minDistance)
                {
                    minDistance = distance;
                    closestItem = item;
                }
            }

            interactingItem = closestItem;
            closestItem     = null;

            if (interactingItem)
            {
                if (interactingItem.IsInteracting())
                {
                    interactingItem.EndInteraction(this);
                }

                interactingItem.BeginInteraction(this);
            }
        }

        if (controller.GetPressUp(gripButton) && interactingItem != null)
        {
            Debug.Log("gripButtonUp detected");
            interactingItem.EndInteraction(this);
        }

        if (controller.GetPressDown(triggerButton))
        {
            Debug.Log("triggerButtonDown detected");
        }

        if (controller.GetPressUp(triggerButton))
        {
            Debug.Log("triggerButtonUp detected");
        }
    }
Exemple #7
0
    // Update is called once per frame
    void Update()
    {
        if (m_Controller == null)
        {
            Debug.Log("Wheres yo controller my dude");
            return;
        }

        if (m_Controller.GetPressDown(m_TriggerButton))
        {
            float minDistance = float.MaxValue;
            float distance;
            foreach (InteractableItem item in m_ObjectsHoveringOver)
            {
                distance = (item.transform.position - transform.position).sqrMagnitude;
                if (distance < minDistance)
                {
                    minDistance   = distance;
                    m_ClosestItem = item;
                }
            }
            m_InteractingItem = m_ClosestItem;

            if (m_InteractingItem)
            {
                if (m_InteractingItem.IsInteracting())
                {
                    m_InteractingItem.EndInteraction(this);
                }
                m_InteractingItem.BeginInteraction(this);
            }
        }
        if (m_Controller.GetPressUp(m_TriggerButton))
        {
            m_InteractingItem.EndInteraction(this);
        }

        if (m_Controller.GetPressDown(m_GripButton))
        {
        }
        if (m_Controller.GetPressUp(m_GripButton))
        {
        }


        if (m_Controller.GetPressDown(m_TouchpadButton))
        {
            FindObjectOfType <CrateBehaviour>().m_CheckWhatPassed();
        }
        if (m_Controller.GetPressUp(m_TouchpadButton))
        {
        }
    }
Exemple #8
0
    private void HandleGripClicked(object sender, ClickedEventArgs e)
    {
        Debug.Log(" Grip button down.");

        float minDistance = float.MaxValue;

        float distance;

        foreach (InteractableItem item in objectsHoveringOver)
        {
            distance = (item.transform.position - transform.position).sqrMagnitude;

            if (distance < minDistance)
            {
                minDistance = distance;
                closestItem = item;
            }
        }

        interactingItem = closestItem;
        if (interactingItem)
        {
            if (interactingItem.IsInteracting())
            {
                interactingItem.EndInteraction(this);
            }
            interactingItem.BeginInteraction(this);
        }

/*         RaycastHit hit;
 *      Ray ray = camera.ScreenPointToRay(Input.mousePosition);
 *      if (Physics.Raycast(ray, out hit))
 *      {
 *          print("Hit: " + hit.transform.gameObject.tag);
 *          Transform objectHit = hit.transform;
 *          if (objectHit.gameObject.tag.Equals("TriggerBall"))
 *          {
 *              pickup = objectHit.gameObject;
 *              pickup.GetComponent<Renderer>().material.shader = Shader.Find("Self-Illumin/Outlined Diffuse");
 *                              pickup.GetComponent<Rigidbody> ().useGravity = false;
 *                              pickup.GetComponent<Rigidbody> ().isKinematic = true;
 *          }
 *      }
 *      if (pickup != null)
 *      {
 *                      Debug.Log ("Pickup not null");
 *
 *              pickup.transform.parent = this.transform;
 *          //pickup.GetComponent<Rigidbody>().useGravity = true;
 *      } */
    }
Exemple #9
0
    // Update is called once per frame
    void Update()
    {
        if (hj == null)
        {
            hj = GameObject.Find(frame_id);
        }
        else if (!interactableItem.IsInteracting())
        {
            if (!startedInteracting)
            {
                //Debug.Log("Not interacting!");
                Vector3    t = hj.transform.position;
                Quaternion q = hj.transform.rotation;
                transform.position = t;
                transform.rotation = q;
            }
            if (startedInteracting)
            {
                //Debug.Log("Stopped Interacting!");
                emTransform ta = new emTransform(transform);
                //ta.UnityPosition += new Vector3(0.1f,0.1f,0.1f);

                Messages.ihmc_msgs.HandTrajectoryRosMessage msg = new Messages.ihmc_msgs.HandTrajectoryRosMessage();
                msg.unique_id        = 1;
                msg.robot_side       = (byte)side;
                msg.base_for_control = 0;


                Messages.ihmc_msgs.SE3TrajectoryPointRosMessage trajectory = new Messages.ihmc_msgs.SE3TrajectoryPointRosMessage();
                trajectory.position = ta.origin.ToMsg();
                //trajectory.position.z += 1.0;
                trajectory.orientation = ta.basis.ToMsg();
                trajectory.time        = 2.0;
                Debug.Log("Sending X: " + ta.origin.ToMsg().x + " Y: " + ta.origin.ToMsg().y + " Z: " + ta.origin.ToMsg().z);

                Messages.ihmc_msgs.SE3TrajectoryPointRosMessage[] trajectorys = { trajectory };

                msg.taskspace_trajectory_points = trajectorys;
                msg.Serialize(true);

                pub.publish(msg);
                startedInteracting = false;
            }
        }
        else
        {
            startedInteracting = true;
        }
    }
Exemple #10
0
    // Update is called once per frame
    //Fixed update is based on time, better for rigidbody manipulation
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }


        // If the trigger button is pressed and the controller is touching/colliding with an object, the object moves with the hand.
        if (controller.GetPressDown(triggerButton))
        {
            float minDistance = float.MaxValue;

            float distance;
            foreach (InteractableItem item in objectsHoveringOver)
            {
                distance = (item.transform.position - transform.position).sqrMagnitude;

                if (distance < minDistance)
                {
                    minDistance = distance;
                    closestItem = item;
                }
            }

            interactingItem = closestItem;
            closestItem     = null;
            if (interactingItem)
            {
                if (interactingItem.IsInteracting())
                {
                    //Ends interaction between the object and the first remote that was interacting
                    interactingItem.EndInteraction(this);
                }

                interactingItem.BeginInteraction(this);
            }
        }

        // If you let go of the object, it no longer moves with the handset
        if (controller.GetPressUp(triggerButton) && interactingItem != null)
        {
            interactingItem.EndInteraction(this);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }

        if (controller.GetPressDown(gripButton))
        {
            // Find the closest item to the hand in case there are multiple and interact with it
            Debug.Log("Pressed");
            float minDistance = float.MaxValue;

            float distance;
            foreach (InteractableItem item in objectsHoveringOver)
            {
                distance = (item.transform.position - transform.position).sqrMagnitude;

                if (distance < minDistance)
                {
                    minDistance = distance;
                    closestItem = item;
                }
            }

            interactingItem = closestItem;
            closestItem     = null;

            if (interactingItem)
            {
                if (interactingItem.IsInteracting())
                {
                    interactingItem.EndInteraction(this);
                }

                interactingItem.BeginInteraction(this);
            }
        }

        if (controller.GetPressUp(gripButton) && interactingItem != null)
        {
            Debug.Log("Released");
            interactingItem.EndInteraction(this);
        }
    }
Exemple #12
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }

        else
        {
            if (controller.GetPressDown(triggerButton))
            {
                float minDistance = float.MaxValue;

                float distance;
                foreach (InteractableItem item in objectsHoveringOver) //Goes through all the objects and detects which is closest to the controller
                {
                    distance = (item.transform.position - transform.position).sqrMagnitude;

                    if (distance < minDistance)
                    {
                        minDistance = distance;
                        closestItem = item;
                    }
                }
                interactingItem = closestItem;
                closestItem     = null;

                if (interactingItem)                     //Starts interacting with the chosen item
                {
                    if (interactingItem.IsInteracting()) //this statement is used in order to grap an item in the other hand
                    {
                        interactingItem.EndInteraction(this);
                    }

                    interactingItem.BeginInteraction(this);
                }
            }

            if (controller.GetPressUp(triggerButton) && interactingItem != null)
            {
                interactingItem.EndInteraction(this); //Stops interaction with the item held
                interactingItem = null;
            }
        }
    }
Exemple #13
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }
        if (controller.GetPressDown(triggerButton))
        {
            float minDistance = float.MaxValue;

            float distance;
            foreach (InteractableItem item in ObjectsHoveringOver)
            {
                distance = (item.transform.position - transform.position).sqrMagnitude;
                if (distance < minDistance)
                {
                    minDistance = distance;
                    closestItem = item;
                }
                interactingItem = closestItem;
                if (interactingItem)
                {
                    if (interactingItem.IsInteracting())
                    {
                        interactingItem.EndInteraction(this);
                    }
                    interactingItem.BeginInteraction(this);
                }
            }
        }
        if (controller.GetPressUp(gripButton) && interactingItem != null)
        {
            interactingItem.EndInteraction(this);
        }
        if (controller.GetPressDown(touchPad))
        {
            GameObject.Find("[CameraRig]").SendMessage("Moveforward");
        }
    }
Exemple #14
0
    //Update called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }

        /*
         * if (controller.GetPressDown(gripButton) && pickup != null)
         * {
         *  pickup.transform.parent = this.transform; //setting the cube's parent to be the wand. cube will follow wand.
         *  pickup.GetComponent<Rigidbody>().isKinematic = true;
         * }
         * if (controller.GetPressUp(gripButton) && pickup != null)
         * {
         *  pickup.transform.parent = null;
         *  pickup.GetComponent<Rigidbody>().isKinematic = false;
         * }
         */

        if (controller.GetPressDown(gripButton) || controller.GetPressDown(triggerButton))
        {
            float minDistance = float.MaxValue;

            float distance;
            foreach (InteractableItem item in objectsHoveringOver)
            {
                //protecting against a problem where destroyed items still existed in this array
                if (item != null)
                {
                    distance = (item.transform.position - transform.position).sqrMagnitude;
                    //using sqrMagnitude bc distance can be negative. we just want magnitude

                    if (distance < minDistance)
                    {
                        minDistance = distance;
                        closestItem = item;
                    }
                }
            }

            interactingItem = closestItem;

            if (interactingItem)  //check that there is an item to interact with

            //check that the item isn't already being iteracted with -- if the other controller is holding it
            {
                if (interactingItem.IsInteracting())
                {
                    interactingItem.EndInteraction(this);
                }

                interactingItem.BeginInteraction(this);
            }
        }

        if ((controller.GetPressUp(gripButton) || controller.GetPressUp(triggerButton)) && interactingItem != null)
        {
            interactingItem.EndInteraction(this);
        }

        //restart scene with menu
        if (controller.GetPressDown(menuButton))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }
    } //end update
Exemple #15
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }

        else
        {
            if (controller.GetPressDown(triggerButton))
            {
                float minDistance = float.MaxValue;

                float distance;
                foreach (InteractableItem item in objectsHoveringOver) //Goes through all the objects and detects which is closest to the controller
                {
                    distance = (item.transform.position - transform.position).sqrMagnitude;

                    if (distance < minDistance)
                    {
                        minDistance = distance;
                        closestItem = item;
                    }
                }

                if (closestItem != null && closestItem.isMenuItem)                                                                     //If the item pressed is something on the menu, then instantiate an object corresponding to the one on the menu
                {
                    prefab          = (GameObject)Instantiate(closestItem.worldPrefab, transform.position, Quaternion.Euler(0, 0, 0)); //Spawn it at the controllers pos and with 0 rotation (facing upwards)
                    interactingItem = prefab.GetComponent <InteractableItem>();                                                        //Is only used for letting an object go again in this case
                    closestItem     = null;
                    interactingItem.BeginInteraction(this);
                }
                else if (closestItem != null && closestItem.isArrow) //If an arrow is pressed. simply tell the arrow and make it change menu page
                {
                    closestItem.GetComponent <Arrows>().pressed = true;
                    interactingItem = null;
                    closestItem     = null;
                }
                else
                {
                    interactingItem = closestItem;
                    closestItem     = null;
                }

                if (interactingItem)                     //Starts interacting with the chosen item
                {
                    if (interactingItem.IsInteracting()) //this statement is used in order to grap an item in the other hand
                    {
                        interactingItem.EndInteraction(this, false);
                    }

                    interactingItem.BeginInteraction(this);
                }
            }

            if (controller.GetPressUp(triggerButton) && interactingItem != null)
            {
                interactingItem.EndInteraction(this, false); //Stops interaction with the item held
                interactingItem = null;
            }
        }
        if (interactingItem != null)
        {
            if (controller.GetPressDown(menuButton) && !interactingItem.isMenuItem && !interactingItem.isArrow)
            {
                objectsHoveringOver.Clear();
                closestItem = null;
                interactingItem.EndInteraction(this, true);
                interactingItem = null;
            }
        }

        //if the controller has the menu attached then we can disable/enable the menu with that controller by pressing the Touch Pad
        if (controller.GetPressDown(padButton) && changeMenu == false && controller.index == 2)
        {
            isMenuActive = !isMenuActive;
            changeMenu   = true;
            Menu(isMenuActive);
        }
    }
    // Update is called once per frame
    private void Update()
    {
        if (Controller == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }

        if (Controller.GetPress(_padPutton))
        {
            foreach (var obj in _objectsHoveringOver)
            {
                Object.Destroy(obj.gameObject);
            }

            _objectsHoveringOver.Clear();
            _isDeleting = true;
        }
        else
        {
            _isDeleting = false;
        }

        if (Controller.GetPressDown(_triggerButton))
        {
            var minDist = float.MaxValue;
            var dist    = 0.0f;
            _closestItem = null;

            foreach (var item in _objectsHoveringOver)
            {
                dist = (item.transform.position - transform.position).sqrMagnitude;

                if (dist < minDist)
                {
                    minDist      = dist;
                    _closestItem = item;
                }
            }

            _interactingItem = _closestItem;
            if (_interactingItem != null)
            {
                if (_interactingItem.IsInteracting())
                {
                    _interactingItem.EndInteraction(this);
                }

                _interactingItem.BeginInteraction(this);
            }
        }

        if (Controller.GetPressUp(_triggerButton))
        {
            if (_interactingItem != null)
            {
                _interactingItem.EndInteraction(this);
                _interactingItem = null;
            }
        }

        if (Controller.GetPressUp(_gripButton))
        {
            _isSolid = !_isSolid;

            Sphere.GetComponent <Collider>().enabled = _isSolid;
        }



        Sphere.GetComponent <Renderer>().material.color = GetCurrentColor();
    }
Exemple #17
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not initializad");
            return;
        }

        //if controller.triggerPulled, then attach
        if (this.triggerPulled)
        {
            //if(objectsHoveringOver.Count > 0)
            //Debug.Log("#Interactable items = " + objectsHoveringOver.Count);
            float minDistance = float.MaxValue;
            float distance;
            //Determine which object to pickup
            foreach (InteractableItem item in objectsHoveringOver)
            {
                distance = (item.transform.position - transform.position).sqrMagnitude;
                if (distance < minDistance)
                {
                    minDistance = distance;
                    closestItem = item;
                }
                interactingItem = closestItem;
            }

            if (interactingItem)
            {
                if (!interactingItem.IsInteracting())
                {
                    interactingItem.BeginInteraction(this);
                    isAttached = true;

                    if (isOffhand)
                    {
                        handOff();
                    }
                }
            }

            //Prepare for single handed grab
            if (interactingItem && this == interactingItem.GetInteractingController() && !offsetLocked)
            {
                calculateOffset();
                offsetLocked = true;
                interactingItem.gameObject.GetComponent <Rigidbody>().isKinematic = true;
                Debug.Log("preparation finished");
            }
            //Grab object
            if (interactingItem && this == interactingItem.GetInteractingController() && offsetLocked && !interactingItem.activeBimanualInteraction)
            {
                if (collidedItem.fromBiManualScaling)
                {
                    calculateOffset();
                    collidedItem.fromBiManualScaling = false;
                }
                Matrix4x4 controllerMatrix = transform.localToWorldMatrix;
                Matrix4x4 newObjectMatrix  = controllerMatrix * objectOffsetMatrix;

                collidedItem.transform.position = extractPosition(newObjectMatrix);
                collidedItem.transform.rotation = extractRotation(newObjectMatrix);
            }
        }

        //Force exit when TriggerOnExit isn't called
        if (delayedExit)
        {
            if (isOffhand && !isScaling && !isRotating)
            {
                collisionTriggered = false;
                objectsHoveringOver.Remove(collidedItem);
                interactingItem = null;
                delayedExit     = false;
            }

            if (isAttached)
            {
                delayedExit        = false;
                collisionTriggered = false;
            }

            if (!isAttached && !isOffhand)
            {
                collisionTriggered = false;
                objectsHoveringOver.Remove(collidedItem);
                interactingItem = null;
                delayedExit     = false;
            }
        }

        //All requirements met for scaling & rotating to begin, set initial scaling parameters
        if (triggerPulled && collisionTriggered && collidedItem != null && !originalParamatersSet &&
            collidedItem.GetInteractingController() && (collidedItem.GetInteractingController() != this))
        {
            setOriginalParameters();
            isScaling             = true;
            isRotating            = true;
            originalParamatersSet = true;
            isOffhand             = true;
            collidedItem.activeBimanualInteraction = true;
        }
        //Begin scaling & rotation
        if (triggerPulled && isScaling && isRotating && collisionTriggered && (collidedItem != null) &&
            collidedItem.GetInteractingController())
        {
            updatePosition();
            startScaling(collidedItem.GetInteractingController(), collidedItem);
            startRotating(collidedItem.GetInteractingController(), collidedItem);
        }
        //cleanup gameobjects used for rotating
        if (centerPoint && !isRotating)
        {
            Destroy(centerPoint);
        }
    }
Exemple #18
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }


        if (controller.GetPressDown(triggerButton))
        {
            triggerDown = true;
        }
        if (controller.GetPressUp(triggerButton))
        {
            triggerDown = false;
        }
        if (controller.GetPressDown(menuButton))
        {
            AR.toggleAR();
        }
        if (controller.GetPressDown(triggerButton))
        {
            float minDistance = float.MaxValue;
            float distance;

            foreach (InteractableItem item in objectsHoveringOver)
            {
                if (item == null)
                {
                    objectsHoveringOver.Remove(item);
                }
                else
                {
                    distance = (item.transform.position - transform.position).sqrMagnitude;

                    if (distance < minDistance)
                    {
                        minDistance = distance;
                        closestItem = item;
                    }
                }
            }
            interactingItem = closestItem;

            if (interactingItem)
            {
                if (interactingItem.IsInteracting())
                {
                    interactingItem.EndInteraction(this);
                }

                interactingItem.BeginInteraction(this);
            }
        }

        if (controller.GetPress(triggerButton) && interactingItem != null)
        {
            if (controller.GetPressDown(gripButton) && interactingItem.GetComponent <ProductController>() != null)
            {
                interactingItem.EndInteraction(this);
                objectsHoveringOver.Remove(interactingItem);
                cart.fastAddToCart(interactingItem.GetComponent <ProductController>());
                interactingItem = null;
            }
        }

        if (controller.GetPressUp(triggerButton) && interactingItem != null)
        {
            if (ARobjGrabbed)
            {
                interactingItem.GetComponent <BoxCollider>().isTrigger = true;
                ARobjGrabbed = false;
            }
            interactingItem.EndInteraction(this);
            objectsHoveringOver.Remove(interactingItem);
            interactingItem = null;
        }


        if (controller.GetPressDown(gripButton))
        {
            if (AR.getActiveStatus())
            {
                AR.setWand(this);
                AR.gripButtonPressed(true);
            }
        }

        if (controller.GetPressUp(gripButton))
        {
            AR.gripButtonPressed(false);
        }
    }
Exemple #19
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }

        gripButtonDown    = controller.GetPressDown(gripButton);
        gripButtonUp      = controller.GetPressUp(gripButton);
        gripButtonPressed = controller.GetPress(gripButton);

        triggerButtonDown    = controller.GetPressDown(triggerButton);
        triggerButtonUp      = controller.GetPressUp(triggerButton);
        triggerButtonPressed = controller.GetPress(triggerButton);

        if (gripButtonDown)
        {
            Debug.Log("Grip Button was just pressed");
        }
        if (gripButtonUp)
        {
            Debug.Log("Grip Button was just unpressed");
        }
        if (triggerButtonDown)
        {
            Debug.Log("Trigger Button was just pressed");
            float minDistance = float.MaxValue;
            float distance;
            foreach (InteractableItem item in objectsHoveringOver)
            {
                distance = (item.transform.position - transform.position).sqrMagnitude;

                if (distance < minDistance)
                {
                    minDistance = distance;
                    closestItem = item;
                }
            }

            interactingItem = closestItem;

            if (interactingItem)
            {
                if (interactingItem.IsInteracting())
                {
                    interactingItem.EndInteraction(this);
                }
                interactingItem.BeginInteraction(this);
            }
            //pickup.transform.parent = this.transform;
            //pickup.GetComponent<Rigidbody> ().useGravity = false;
        }
        if (triggerButtonUp && interactingItem != null)
        {
            Debug.Log("Trigger Button was just unpressed");
            interactingItem.EndInteraction(this);
            //pickup.transform.parent = null;
            //pickup.GetComponent<Rigidbody> ().useGravity = true;
        }
    }