示例#1
0
    private void OnTriggerExit(Collider collider)
    {
        Debug.Log("Trigger exit");
        InteractableItem collidedItem = collider.GetComponent <InteractableItem> ();

        if (collidedItem)
        {
            objectsHoveringOver.Remove(collidedItem);
        }
        //pickup = null;
    }
示例#2
0
    private void OnTriggerEnter(Collider collider)
    {
        //   pickup = collider.gameObject;
        //  Debug.Log("Trigger Entered");

        InteractableItem collidedItem = collider.GetComponent <InteractableItem>();

        if (collidedItem)
        {
            objectsHoveringOver.Add(collidedItem);
        }
    }
示例#3
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))
        {
        }
    }
        public bool TryGetItem(out ItemEntityTag tag)
        {
            InteractableItem component = Internal.GetComponent <InteractableItem>();

            if (component != null)
            {
                tag = new ItemEntityTag(component);
                return(true);
            }
            tag = null;
            return(false);
        }
示例#5
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Interactable"))
     {
         var interact = other.GetComponent <InteractableItem>();
         if (interact != null)
         {
             interact.ShowInfo();
             _itemInteract = interact;
         }
     }
 }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Interactable"))
        {
            currentItem = other.gameObject.GetComponent <InteractableItem>();
        }

        if (other.CompareTag("NPC"))
        {
            currentNPC = other.gameObject.GetComponent <DialogueTrigger>();
        }
    }
    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.CompareTag("Interactable") && currentItem != null)
        {
            onItem      = false;
            currentItem = null;
        }

        if (other.CompareTag("NPC") && currentNPC != null)
        {
            currentNPC = null;
        }
    }
示例#8
0
 protected void OnTriggerEnter(Collider collider)
 {
     //Debug.Log("Collided with : " + collider.gameObject.name);
     if (!isAttached)
     {
         collidedItem       = collider.GetComponent <InteractableItem>();
         collisionTriggered = true;
         if (collidedItem)
         {
             objectsHoveringOver.Add(collidedItem);
         }
     }
 }
示例#9
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;
 *      } */
    }
示例#10
0
    public void DroppedObject(GameObject droppedObject)
    {
        if (!droppedObject.CompareTag("Interactable"))
        {
            return;
        }

        InteractableItem newInteractable = new InteractableItem(droppedObject, droppedObject.GetComponent <IInteractable>());

        selectableInteractables.Add(droppedObject.GetInstanceID(), newInteractable);
        newInteractable.indexInList = selectableInteractables.Count - 1;         // Store our index for fast removal

        Debug.Log("Found an interactable item! " + droppedObject.name + " Current Count: " + selectableInteractables.Count);
    }
示例#11
0
    private void OnTriggerEnter(Collider other)
    {
        if (!other.CompareTag("Interactable"))
        {
            return;
        }

        InteractableItem newInteractable = new InteractableItem(other.gameObject, other.gameObject.GetComponent <IInteractable>());

        selectableInteractables.Add(other.gameObject.GetInstanceID(), newInteractable);
        newInteractable.indexInList = selectableInteractables.Count - 1;       // Store our index for fast removal

        Debug.Log("Found an interactable item! " + other.gameObject.name + " Current Count: " + selectableInteractables.Count);
    }
示例#12
0
        private InteractableItem[] getItems()
        {
            Collider[] array = Physics.OverlapSphere(Information.player.look.aim.position, 10f, RayMasks.ITEM);
            List <InteractableItem> items = new List <InteractableItem>();

            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] != null && array[i].gameObject != null)
                {
                    InteractableItem item = array[i].GetComponent <InteractableItem>();
                    if (item != null && (Tool.isObscured(item.transform) || ignoreWalls))
                    {
                        if (pickupAll)
                        {
                            if (ignoreFilter && ComponentManager.hack_ItemSelection.uTp.Contains(item.asset.useable))
                            {
                                continue;
                            }
                            if (ignoreID && ComponentManager.itemid_manager.exists(item.asset.id))
                            {
                                continue;
                            }
                            items.Add(item);
                            continue;
                        }

                        if (pickupFilter && !ignoreFilter)
                        {
                            if (ComponentManager.hack_ItemSelection.uTp.Contains(item.asset.useable) && (!ignoreID || !ComponentManager.itemid_manager.exists(item.asset.id)))
                            {
                                items.Add(item);
                                continue;
                            }
                        }

                        if (pickupID && !ignoreID)
                        {
                            if (ComponentManager.itemid_manager.exists(item.asset.id) && (!ignoreFilter || !ComponentManager.hack_ItemSelection.uTp.Contains(item.asset.useable)))
                            {
                                items.Add(item);
                                continue;
                            }
                        }
                    }
                }
            }

            return(items.ToArray());
        }
示例#13
0
    // 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);
        }
    }
示例#14
0
    /// <summary>
    /// Adds a interactable item to the hashmap if collision happens between itself and the controller
    /// </summary>
    private void OnTriggerEnter(Collider collider)
    {
        InteractableItem item = collider.GetComponent <InteractableItem>();

        if (item)
        {
            m_objectsHoveringOver.Add(item);
            if (m_interactionItem != item)
            {
                item.GetComponent <Renderer>().material.SetColor("_Color", Color.cyan);
            }

            //Debug.Log("Adding gameobject: " + item.gameObject.name);
        }
    }
示例#15
0
    void OnTriggerStay(Collider collider)
    {
        // If object is an interactable item
        InteractableItem interactable = collider.GetComponent <InteractableItem>();

        if (interactable != null)
        {
            if (device.GetPressDown(EVRButtonId.k_EButton_SteamVR_Trigger))
            {
                // Pick up object
                interactable.Pickup(this);
                heldObjects.Add(interactable);
            }
        }
    }
示例#16
0
    public bool AddItem(InteractableItem interactableItem)
    {
        bool status = false;

        if (_pickedItemsCount < InventorySize)
        {
            _items[GetFirstEmptyIndex()] = interactableItem;
            _pickedItemsCount++;
            status = true;
        }

        InventoryUI.UpdateUI(_items);
        StartCoroutine(InventoryUI.SetTitle(interactableItem.Name));
        return(status);
    }
示例#17
0
    // Update is called once per frame
    void Update()
    {
        //No Controllers
        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 = item;

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

                    //interactingItem.BeginInteraction(this);
                }

            }
        }

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

        if (controller.GetPressDown(menuButton))
        {
            string sceneName = (SceneManager.GetActiveScene().name);
            SceneManager.LoadScene(sceneName);
        }
    }
示例#18
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;
            }
        }
    }
示例#19
0
    public void startScaling(ControllerFunctions interactingWand, InteractableItem collidedItem)
    {
        Transform interactingPoint = interactingWand.transform;

        float currentDistance = (controllerTransform.position - interactingWand.transform.position).magnitude;
        float scalingFactor   = (currentDistance / oldDistance);

        Vector3 itemScale        = collidedItem.transform.localScale;
        Vector3 controllerToCube = collidedItem.transform.position - controllerTransform.position;

        if (scalingFactor - 1 > .1F || scalingFactor - 1 > -.1F)
        {
            collidedItem.transform.localScale = new Vector3(itemScale.x * scalingFactor, itemScale.y * scalingFactor, itemScale.z * scalingFactor);
        }
        oldDistance = currentDistance;
    }
示例#20
0
 private void OnTriggerExit2D(Collider2D other)
 {
     if (other.CompareTag("Interactable"))
     {
         currentInteraction = null;
         itemScript         = null;
     }
     if (other.CompareTag("Customer"))
     {
         nearCustomer    = false;
         closestCustomer = null;  //resets variable so that player can no longer interact after leaving trigger area
     }
     if (other.CompareTag("Counter"))
     {
         nearCheckout = false;
     }
 }
    void OnTriggerStay(Collider collider)
    {
        //If object is an interactable item
        InteractableItem interactable = collider.GetComponent <InteractableItem>();

        if (interactable != null)
        {
            Debug.Log("interac " + interactable + " " + Input.GetAxis(TriggerAxis));
            //If trigger button is down
            if (Input.GetAxis(TriggerAxis) > 0.9f)
            {
                //Pick up object
                interactable.Pickup(this);
                heldObjects.Add(interactable);
            }
        }
    }
    private void ShowInfoBox(GameObject obj)
    {
        if (!InfoCanvas.enabled)
        {
            //print("Showing Weapon Info Box");
            InfoCanvas.enabled = true;
            IsEnabled          = true;
        }
        InteractableItem item = obj.GetComponent <InteractableItem>();

        if (item == null)
        {
            print("NULL ITEM"); return;
        }
        _itemName.text = item.Name;
        _itemInfo.text = item.Info;
    }
示例#23
0
    private void OnTriggerExit(Collider collider)
    {
        InteractableItem collidedItem = collider.GetComponent <InteractableItem>();

        if (collidedItem)
        {
            collidedItem.Untouched(this);
            if (controller.GetPress(triggerButton))
            {
                objectsTriggering.Add(collidedItem);
            }
            else
            {
                objectsHoveringOver.Remove(collidedItem);
            }
        }
    }
示例#24
0
        public static InteractableItem GetNearestItem(int?pixelfov = null)
        {
            // end item
            InteractableItem returnitem = null;

            Collider[] array = Physics.OverlapSphere(Player.player.transform.position, 19f, RayMasks.ITEM);
            for (int i = 0; i < array.Length; i++)
            {
                Collider collider = array[i];
                if (collider == null || collider.GetComponent <InteractableItem>() == null || collider.GetComponent <InteractableItem>().asset == null)
                {
                    continue;
                }
                InteractableItem item = collider.GetComponent <InteractableItem>();

                Vector3 ScreenPoint1 = G.MainCamera.WorldToScreenPoint(item.transform.position);
                if (ScreenPoint1.z <= 0)
                {
                    continue;
                }

                int ToLoopPlayerPixels = (int)Vector2.Distance(new Vector2(Screen.width / 2, Screen.height / 2), new Vector2(ScreenPoint1.x, ScreenPoint1.y));
                if (pixelfov != null && ToLoopPlayerPixels > pixelfov)
                {
                    continue;
                }

                if (returnitem == null)
                {
                    returnitem = item; continue;
                }
                Vector3 ScreenPoint2         = G.MainCamera.WorldToScreenPoint(returnitem.transform.position);
                int     ToReturnPlayerPixels = (int)Vector2.Distance(new Vector2(Screen.width / 2, Screen.height / 2), new Vector2(ScreenPoint2.x, ScreenPoint2.y));

                if (pixelfov != null && ToReturnPlayerPixels > pixelfov)
                {
                    returnitem = null;
                }

                if (ToLoopPlayerPixels < ToReturnPlayerPixels)
                {
                    returnitem = item;
                }
            }
            return(returnitem);
        }
示例#25
0
    private InteractableItem RayCastFromCamera()
    {
        RaycastHit hit;
        Ray        ray = PlayerCamera.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit))
        {
            GameObject       hitObject = hit.collider.gameObject;
            InteractableItem hitItem   = hitObject.GetComponentInParent <InteractableItem>();
            if (hitItem != null)
            {
                lastDepthDistance = Vector3.Distance(transform.position, hitItem.transform.position);
                return(hitItem);
            }
        }
        return(null);
    }
示例#26
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);
        }
    }
示例#27
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;
            }
        }
    }
示例#28
0
    private void OnTriggerEnterEvent(Collider2D col)
    {
        if (col.gameObject.CompareTag("Item"))
        {
            InteractableItem item = col.gameObject.GetComponent <InteractableItem>();

            if (item != null)
            {
                item.HandleItem();
            }
        }

        else if (col.gameObject.CompareTag("Laser"))
        {
            Vector2 direction = transform.position - col.transform.position;
            Knockback(direction, knockbackDuration, knockbackDecreaseOverTime, true);
            player.TakeDamage(2f);
        }

        else if (col.gameObject.CompareTag("Platform"))
        {
            transform.parent = col.transform;
        }

        else if (col.gameObject.CompareTag("Enemy"))
        {
            Vector2 direction = transform.position - col.transform.position;
            Knockback(direction, knockbackDuration, knockbackDecreaseOverTime, true);
            player.TakeDamage(2f);
        }

        else if (col.gameObject.CompareTag("Bullet"))
        {
            Vector2 direction = transform.position - col.transform.position;
            Knockback(direction, knockbackDuration, knockbackDecreaseOverTime, true);
            player.TakeDamage(1f);
            Destroy(col.gameObject);
        }

        else if (col.gameObject.CompareTag("EnemyHead"))
        {
            Knockback(Vector2.up, 0.7f, knockbackDecreaseOverTime, false);
            BaseEnemy enemyHit = col.gameObject.GetComponentInParent <BaseEnemy>();
            enemyHit.Kill();
        }
    }
示例#29
0
 /// <summary>
 /// Removes a game object from the list if it is no longer within the hand's range of focus
 /// </summary>
 /// <param name="col">Col.</param>
 void OnTriggerExit(Collider col)
 {
     _currentItem = null;
     _availableItems.Remove(col.gameObject);
     if (col.gameObject.GetComponent <TwoHandedItem>() && joint.connectedBody == col.transform.root.gameObject.GetComponent <Rigidbody>())
     {
         col.gameObject.GetComponent <TwoHandedItem> ().OnObjectInteractRelease(this.gameObject, anim);
     }
     if (_availableItems.Count > 0)
     {
         _currentItem = _availableItems [0].GetComponent <InteractableItem> ();
     }
     else
     {
         anim.SetBool("Reach", false);
     }
 }
示例#30
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);
        }
    }
 public static ItemEntityTag For(int instanceID)
 {
     for (byte x = 0; x < Regions.WORLD_SIZE; x++)
     {
         for (byte y = 0; y < Regions.WORLD_SIZE; y++)
         {
             foreach (ItemDrop drop in ItemManager.regions[x, y].drops)
             {
                 InteractableItem item = drop.interactableItem;
                 if (instanceID == item.gameObject.GetInstanceID())
                 {
                     return(new ItemEntityTag(item));
                 }
             }
         }
     }
     return(null);
 }
 public ItemEntityTag(InteractableItem item)
 {
     Internal = item;
 }