Esempio n. 1
0
 public void StopInteraction()
 {
     if (m_interactionItem)
     {
         m_objectsHoveringOver.Remove(m_interactionItem);
         m_interactionItem.EndInteraction(this);
         m_interactionItem = null;
     }
 }
Esempio n. 2
0
    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);
        }
    }
        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);
            }
        }
Esempio n. 4
0
    private void grabBrick()
    {
        // Check if flystick is inside a brick
        GameObject[] bricks       = GameObject.FindGameObjectsWithTag("Brick");
        GameObject   selectedItem = null;

        foreach (GameObject brick in bricks)
        {
            if (brick.GetComponent <Collider>().bounds.Contains(flyStickInteraction.transform.position))
            {
                selectedItem = brick;
                break;
            }
        }

        // Check if flystick points on a brick
        if (selectedItem == null)
        {
            flyStickInteraction.sendRayForBlocks();
            selectedItem = flyStickInteraction.SelectedPart;
        }

        if (selectedItem)
        {
            interactingItem = selectedItem.GetComponent <InteractableItem>();
            if (interactingItem)
            {
                GameObject towerObject = GameObject.Find("DynamicTower");
                if (towerObject)
                {
                    TowerInteractivity tower = towerObject.GetComponent <TowerInteractivity>();

                    if (interactingItem.name.Contains(TowerInteractivity.MaxRow.ToString()) && interactingItem.GetComponent <Renderer>().material.color != Color.green)
                    {
                        //return;
                    }
                    if (interactingItem.GetComponent <Renderer>().material.color != Color.green)
                    {
                        if (tower.FirstSelected == null)
                        {
                            tower.select(interactingItem.transform.gameObject);
                            Debug.Log("select: " + interactingItem.transform.gameObject.name);
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                if (interactingItem.isInteracting())
                {
                    interactingItem.EndInteraction(flyStickInteraction);
                    interactingItem = null;
                    Debug.Log("endInteraction");
                }
                interactingItem.BeginInteraction(flyStickInteraction);
            }
        }
    }
Esempio n. 5
0
    private void Update()
    {
        if (enable)
        {
            if (InputSynchronizer.GetKeyDown("space"))
            {
                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;

                GameObject towerObject = GameObject.Find("DynamicTower");
                if (towerObject != null && interactingItem != null)
                {
                    TowerInteractivity tower = towerObject.GetComponent <TowerInteractivity>();

                    if (interactingItem.name.Contains(TowerInteractivity.MaxRow.ToString()) && interactingItem.GetComponent <Renderer>().material.color != Color.green)
                    {
                        return;
                    }
                    if (interactingItem.GetComponent <Renderer>().material.color != Color.green)
                    {
                        if (tower.FirstSelected == null)
                        {
                            tower.select(interactingItem.transform.gameObject);
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                if (interactingItem)
                {
                    if (interactingItem.isInteracting())
                    {
                        interactingItem.EndInteraction(this);
                    }
                    interactingItem.BeginInteraction(this);
                }
            }
            if (InputSynchronizer.GetKeyUp("space") && interactingItem != null)
            {
                interactingItem.EndInteraction(this);
            }
        }
    }
Esempio n. 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");
        }
    }
Esempio n. 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))
        {
        }
    }
Esempio n. 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;
 *      } */
    }
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not inizialised");
            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) // wenn durch den trigger bereits collided
        {
            float minDistance = float.MaxValue;
            float distance;
            foreach (InteractableItem i in objectsHoveringOver)
            {
                distance = (i.transform.position - transform.position).sqrMagnitude;
                if (distance < minDistance)
                {
                    minDistance = distance;
                    closestItem = i;
                }
            }

            interactingItem = closestItem;

            if (interactingItem)
            {
                if (interactingItem.IsInteraction())
                {
                    interactingItem.EndInteraction(this);
                }
                interactingItem.BeginInteraction(this);
            }
        }

        if (gripButtonUp && interactingItem != null)
        {
            interactingItem.EndInteraction(this);
        }
    }
Esempio n. 10
0
    public void dropObject()
    {
        if (isAttached)
        {
            isAttached = false;
            collidedItem.EndInteraction(this);
            interactingItem = null;
            objectsHoveringOver.Remove(collidedItem);

            //If dropping a snapKey, turn off collision rerouting from Key object
            if (collisionFromKey)
            {
                collisionFromKey = false;
            }
        }
    }
Esempio n. 11
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);
        }
    }
Esempio n. 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;
            }
        }
    }
Esempio n. 13
0
    // 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);
        }
    }
Esempio n. 14
0
    private void HandleGripUnclicked(object sender, ClickedEventArgs e)
    {
        Debug.Log("Grip button up");

        if (interactingItem != null)
        {
            interactingItem.EndInteraction(this);
        }

/*      if (pickup != null) {
 *                      Debug.Log ("Grip button up | " + pickup.tag);
 *                      pickup.GetComponent<Renderer> ().material.shader = null;
 *                      pickup.GetComponent<Rigidbody> ().useGravity = true;
 *                      pickup.GetComponent<Rigidbody> ().isKinematic = false;
 *
 *                      pickup = null;
 *              } */
    }
Esempio n. 15
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");
        }
    }
Esempio n. 16
0
    // Update is called once per frame
    void Update()
    {
        if (flyStickInteraction == null)
        {
            initFlyStickEvents();
        }

        if (InputSynchronizer.GetFlyStickButtonDown(0))
        {
            grabBrick();
        }

        if (InputSynchronizer.GetFlyStickButtonUp(0))
        {
            if (interactingItem)
            {
                interactingItem.EndInteraction(flyStickInteraction);
                interactingItem = null;
            }
        }

        if (InputSynchronizer.GetKey("o") || InputSynchronizer.GetFlyStickButtonDown(1))
        {
            if (state == State.BlockCorrectlyPlaced)
            {
                state = State.BlockPlacing;
                deselect();
                Player.changeActivePlayer();
                Debug.Log("Player " + (Player.ActivePlayer + 1) + " is on the move and has " + Players[Player.ActivePlayer].Score + " Points");
            }
        }
        if (Input.GetKeyDown(KeyCode.E))
        {
            addRow();
        }

        maxRow = transform.childCount;

        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hitInfo = new RaycastHit();
            cam = GameObject.Find("Camera").GetComponent <Camera>();
            bool hit = Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hitInfo);
            if (hit)
            {
                if (hitInfo.transform.gameObject.tag == "Brick")
                {
                    rows = hitInfo.transform.parent.parent.childCount;
                    if (hitInfo.transform.gameObject != SelectedObj && hitInfo.transform.parent.name != "Row#" + rows)
                    {
                        select(hitInfo.transform.gameObject);
                        Debug.Log("select");
                    }
                    else
                    {
                        deselect();
                        Debug.Log("deselect");
                    }
                }
            }
        }
    }
Esempio n. 17
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
Esempio n. 18
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }

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

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

        trackpadButtonDown    = controller.GetPressDown(trackpadButtonId);
        trackpadButtonUp      = controller.GetPressUp(trackpadButtonId);
        trackpadButtonPressed = controller.GetPress(trackpadButtonId);

        if (gripButtonDown)
        {
        }
        if (trackpadButtonUp)
        {
            GameObject.Find("Button_StartRecord").GetComponent <Button>().onClick.Invoke();
            pressedRecord = true;
        }
        if (triggerButtonDown)
        {
            // Debug.Log("triggerbutton was just pressed");
            if (pointer)
            {
                pointer.PulledTrigger();
            }
        }

        if (triggerButtonUp)
        {
            //  Debug.Log("triggerbutton was just unpressed");
        }


        if (triggerButtonDown)
        {
            float minDistance = float.MaxValue;

            float distance;

            foreach (InteractableItem item in objectsHoveringOver)
            {
                distance = (item.transform.position - transform.position).sqrMagnitude;     // sqr because it could also be negative
                if (distance < minDistance)
                {
                    minDistance = distance;
                    closestItem = item;
                }
            }

            interactingItem = closestItem;
            closestItem     = null;

            if (interactingItem)
            {
                if (interactingItem.isInteracting())     // this shouldn't happen that often...
                {
                    interactingItem.EndInteraction(this);
                }

                interactingItem.BeginInteraction(this);
            }
        }


        if (triggerButtonUp && interactingItem != null)
        {
            interactingItem.EndInteraction(this);
        }
    }
Esempio n. 19
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }

        else
        {
            //Cast a ray, and use it to choose what to interact with.
            if (Physics.Raycast(transform.position, transform.forward, out hit))
            {
                DrawRay();
                if (hit.collider.CompareTag("Interactable"))
                {
                    //Debug.Log("I FOUND AN OBJECT TO INTERACT WITH WOOP WOOP!  " + hit.collider.name);
                    if (hit.collider.gameObject != hitInteractable)
                    {
                        hitInteractable = hit.collider.gameObject;
                        //Debug.Log("Found a new object to interact with");
                    }
                    if (controller.GetPressDown(triggerButton))
                    {
                        DetectObjectHitLabel();
                    }
                }
            }
            else if (hitInteractable != null)
            {
                hitInteractable = null;
                //Debug.Log("Didn't hit an object");
            }

            //Stop holding the object
            if (controller.GetPressUp(triggerButton) && interactingItem != null)
            {
                interactingItem.EndInteraction(this, false); //Stops interaction with the item held
                interactingItem = null;
            }

            //Delete the object held in hand by pressing the menu button on the controller
            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);
            }


            /*
             * 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);
             *  }
             * } */
        }
    }
Esempio n. 20
0
    // 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();
    }
Esempio n. 21
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);
        }
    }
Esempio n. 22
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);
        }
    }
Esempio n. 23
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;
        }
    }