Esempio n. 1
0
 private void InteractableUI(AbstractInteractable obj, Vector3 pos, bool inRange)
 {
     interactableUi.gameObject.SetActive(true);
     interactableUi.sprite             = obj.interactionUI; //da cambiare nell'immagine
     interactableUi.transform.position = pos;
     notInRangeImage.enabled           = !inRange;
 }
Esempio n. 2
0
 public void SetCursor(AbstractInteractable abstractInteractable)
 {
     gameCursor.SetCursor(abstractInteractable.interactHand);
     if ((abstractInteractable.GetInteractType() & AbstractInteractable.InteractType.Inspect) != 0)
     {
         inspectIcon.SetActive(true);
         interactText.text = (abstractInteractable as ICanInspect)?.GetInspectText();
     }
 }
    // Update is called once per frame
    void Update()
    {
        // Remember the last interactable thing the player was looking at
        lastInteractable = interactable;

        // Look for the current interactable thing under the player's view
        interaction = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
        if(Physics.Raycast (interaction, out hitInfo, rayDistance)) {
            interactable = hitInfo.transform.gameObject.GetComponent<AbstractInteractable>();
            if(interactable) {
                // If we are looking at something for the first time call OnHover()
                if(lastInteractable != interactable) {
                    if(lastInteractable != null) {
                        lastInteractable.OnHoverStop();
                        if(interacting) {
                            interacting = false;
                            lastInteractable.OnInteractStop();
                        }
                    }
                    Debug.Log("OnHover()");
                    interactable.OnHover();
                }

                // If we are looking at something and we're not pressing E, clear interacting
                if(!Input.GetKey(KeyCode.E)) {
                    Debug.Log("OnInteractStop()");
                    lastInteractable.OnInteractStop();
                    interactable.OnInteractStop();
                }

                // If we are looking at something and pressing the interaction button call OnInteract()
                if(Input.GetKey(KeyCode.E) && interacting) {
                    Debug.Log("OnInteract()");
                    interactable.OnInteract();
                } else if(Input.GetKey(KeyCode.E) && !interacting) {

                }
            } else {
                // If we found something non interactive set interactable to null
                interactable = null;
                Debug.Log("NonInteractable -> null");
            }
        } else {
            // If we didn't find anything in our view at all set interactable to null
            interactable = null;
            Debug.Log("Nothing Found -> null");
        }

        // If we were looking at an interactable and stopped call OnHoverStop
        if(lastInteractable && lastInteractable != interactable) {
            lastInteractable.OnHoverStop();

        }
    }
Esempio n. 4
0
 private bool isType(AbstractInteractable t)
 {
     if (t != null)
     {
         if (t.GetType().GetInterfaces().Contains(type))
         {
             return(true);
         }
     }
     return(false);
 }
    // Update is called once per frame
    void Update()
    {
        // Remember the last interactable thing the player was looking at
        lastInteractable = interactable;

        // Look for the current interactable thing under the player's view
        interaction = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
        if (Physics.Raycast(interaction, out hitInfo, rayDistance))
        {
            interactable = hitInfo.transform.gameObject.GetComponent <AbstractInteractable>();
            if (interactable)
            {
                // If we are looking at something for the first time call OnHover()
                if (lastInteractable != interactable)
                {
                    Debug.Log("OnHover()");
                    interactable.OnHover();
                }

                // If we are looking at something and pressing the interaction button call OnInteract()
                if (Input.GetKey(KeyCode.E))
                {
                    Debug.Log("OnInteract()");
                    interactable.OnInteract();
                }
            }
            else
            {
                // If we found something non interactive set interactable to null
                interactable = null;
                Debug.Log("NonInteractable -> null");
            }
        }
        else
        {
            // If we didn't find anything in our view at all set interactable to null
            interactable = null;
            Debug.Log("Nothing Found -> null");
        }

        // If we were looking at an interactable and stopped call OnHoverStop
        if (lastInteractable && lastInteractable != interactable)
        {
            lastInteractable.OnHoverStop();
        }
    }
Esempio n. 6
0
    private void CheckMouse()
    {
        _ray = _cam.ScreenPointToRay(Input.mousePosition);
        //Debug.DrawRay(_ray.origin, _ray.direction * 10, Color.blue);
        bool isInRange;

        if (Physics.Raycast(_ray, out _hit, Mathf.Infinity, interactableMask))
        {
            //Debug.Log("Hovering");
            if (_currentInteractableObj != _hit.collider.gameObject)
            {
                _currentInteractableObj = _hit.collider.gameObject;
                _currentInteractable    = _currentInteractableObj.GetComponent <AbstractInteractable>();
            }



            if (_currentInteractableObj.CompareTag("Crate") && _candleBehaviour.HasCandle())
            {
                isInRange = false;
            }
            else
            {
                Vector3 vec = new Vector3(_hit.point.x, _hit.point.y, 0);
                isInRange = CheckDistanceToInteractable(_currentInteractableObj.transform.position,
                                                        transform.position);
            }

            var temp1 = _currentInteractableObj.GetComponent <NextRoom>();
            if (temp1 && temp1.needKey)
            {
                if (!_hasKey)
                {
                    isInRange = false;
                    if (!_inCoroutine)
                    {
                        StartCoroutine(MissingItemText(temp1.interactionText));
                    }
                }
            }

            var temp2 = _currentInteractableObj.GetComponent <WindowNext>();
            if (temp2 && temp2.needKey)
            {
                if (!_hasWindowKey)
                {
                    isInRange = false; if (!_inCoroutine)
                    {
                        StartCoroutine(MissingItemText(temp2.interactionText));
                    }
                }
            }

            var temp4 = _currentInteractableObj.GetComponent <RopeNext>();
            if (temp4 && temp4.needKey)
            {
                if (!_hasRope)
                {
                    isInRange = false;
                    if (!_inCoroutine)
                    {
                        StartCoroutine(MissingItemText(temp4.interactionText));
                    }
                }
            }

            OnHover(_currentInteractable, Input.mousePosition, isInRange);


            if (Input.GetMouseButtonDown(0) && isInRange)
            {
                var temp = _currentInteractableObj.GetComponent <KeyDrawer>();
                if (temp)
                {
                    bool tempKey = temp.Clicked();
                    if (!_hasKey)
                    {
                        _hasKey = tempKey;
                    }
                }

                var temp3 = _currentInteractableObj.GetComponent <WindowKeyDrawer>();
                if (temp3)
                {
                    bool tempKey = temp3.Clicked();
                    if (!_hasWindowKey)
                    {
                        _hasWindowKey = tempKey;
                    }
                }

                if (temp1 && temp1.needKey && _hasKey)
                {
                    temp1.needKey = false;
                    _hasKey       = false;
                }

                if (temp2 && temp2.needKey && _hasWindowKey)
                {
                    temp2.needKey = false;
                    _hasWindowKey = false;
                }

                if (temp4 && temp4.needKey && _hasRope)
                {
                    temp4.needKey = false;
                    _hasRope      = false;
                }

                if (_currentInteractable.CompareTag("Rope"))
                {
                    _hasRope = true;
                }

                if (_currentInteractable.CompareTag("HideSpot"))
                {
                    GetComponent <PlayerMovement>().Hide();
                }

                if (_currentInteractableObj.CompareTag("Candle"))
                {
                    _candleBehaviour.PickUpOrDropCandle();
                }

                if (_currentInteractableObj.CompareTag("CandleDrawer") && !_candleBehaviour._droppedCandle)
                {
                    _candleBehaviour.CandleReset();
                    if (!_candleBehaviour._hasCandle)
                    {
                        _candleBehaviour.PickUpOrDropCandle();
                    }
                }

                _currentInteractable.Click();
            }
        }
        else
        {
            OnHoverOff();
        }

        if (Input.GetMouseButtonDown(1) && _candleBehaviour.HasCandle())
        {
            _candleBehaviour.PickUpOrDropCandle();
        }
    }
Esempio n. 7
0
 protected virtual void OnHover(AbstractInteractable obj, Vector3 pos, bool isInRange)
 {
     Hover?.Invoke(obj, pos, isInRange);
 }