Example #1
0
    public Interactible instantiateInteractible(Interactible interactible, Vector3 position)
    {
        int x = (int)position.x;
        int y = (int)position.y;
        int z = (int)position.z;

        if (interactible is Item)
        {
            //Interactible is of the item class
            Item          curItem          = (Item)interactible;
            GameObject    itemObject       = Instantiate(dungeonEntityPrefab, new Vector3(x, y + 0.5f, (z) - 1), Quaternion.Euler(0, 0, 0));
            DungeonEntity newDungeonEntity = itemObject.GetComponent <DungeonEntity>();
            curItem.gameObjectScript = newDungeonEntity;
            curItem.initGameObject();


            return(curItem);
        }
        else
        {
            //Interactible is just an interactible (lever or door, etc)

            return(null);
        }
    }
Example #2
0
    //Checks for presence of interactible object
    private void CheckForInteractible()
    {
        //Check for interactible
        if (Physics.Raycast(_camera.transform.position,
                            _camera.transform.forward, out _raycastHit,
                            maxInteractionDistance))
        {
            //Set found interactible to current interactible to interact with
            Interactible newInteractible = _raycastHit.collider.GetComponent <Interactible>();

            //Set interactible if interactible property is on
            if (newInteractible != null && newInteractible.isInteractive)
            {
                SetInteractible(newInteractible);
            }
            else
            {
                //Clear current interactible
                ClearInteractible();
            }
        }
        else
        {
            //Clear current interactible
            ClearInteractible();
        }
    }
Example #3
0
    public void Pickup()
    {
        // get nearest
        m_curentInteractible = GetNearestInteractible();

        // null check
        if (!m_curentInteractible)
        {
            return;
        }

        //already held check
        if (m_curentInteractible.m_activeHand)
        {
            m_curentInteractible.m_activeHand.Drop();
        }

        // attach
        Rigidbody targetBody = m_curentInteractible.GetComponent <Rigidbody>();

        m_joint.connectedBody = targetBody;

        //set active hand
        m_curentInteractible.m_activeHand = this;
        controllerModel.gameObject.SetActive(false);
    }
Example #4
0
 void Update()
 {
     for (int i = 0; i < points.Length; i++)
     {
         if ((leverTransform.position - worldPoints[i]).magnitude <= activateDistance)
         {
             if (current != interactibles[i])
             {
                 if (!leverHoldable.IsGrabbed)
                 {
                     SnapToPosition(worldPoints[i]);
                 }
                 current = interactibles[i];
                 current.InteractStart();
             }
         }
         else
         {
             if (current == interactibles[i])
             {
                 current.InteractEnd();
                 current = null;
             }
         }
     }
 }
Example #5
0
 //Clear the current interactible variable
 private void ClearInteractible()
 {
     //Set the current interactible to null
     _currentInteractible = null;
     //Hide interactible interaction panel
     _canvasManager.HideInteractionPanel();
 }
Example #6
0
    IEnumerator ChangeItem(GameObject _newItem)
    {
        if (item != null)
        {
            item.SetPosition(-2.0f * Vector3.up);
            item.CancelActivation();
            SoundManager.instance.StopSound(item.source);
            yield return(new WaitForSeconds(0.2f));

            Destroy(item.gameObject);
            item = null;
        }
        if (_newItem != null)
        {
            if (DataManager.instance.isMulti)
            {
                if (!isServer)
                {
                    yield break;
                }
                item = Instantiate(_newItem, transform).GetComponent <Interactible>();
                NetworkServer.Spawn(item.gameObject);
                RpcChangeItem(item.gameObject, gameObject);
            }
            else
            {
                item = Instantiate(_newItem, transform).GetComponent <Interactible>();
                item.gameObject.SetActive(true);
                item.transform.localPosition = -2.0f * Vector3.up;
                item.SetPosition(Vector3.zero);
            }
        }
    }
Example #7
0
    /// <summary>
    /// Method that will set the new interactibles
    /// </summary>
    /// <param name="newInteractible"></param>
    private void SetInteractible(Interactible newInteractible)
    {
        _currentInteractible = newInteractible;

        // Will show the interaction panel
        _canvasManager.ShowInteractionPanel(_currentInteractible.interactionText);
    }
Example #8
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;

        // Prepare raycast
        Ray ray = new Ray(transform.position, transform.forward);

        // Do the raycast and get the object hitted
        if (Physics.Raycast(ray, out hit, interactibleRange))
        {
            // Try to get the Interactible component
            Interactible hitted = hit.transform.GetComponent <Interactible>();

            // If it exists, get the object
            if (hitted != null)
            {
                actionableObject = hitted;
            }
        }
        else
        {
            actionableObject = null;
        }

        // Do the action of the interactible object
        if (Input.GetKeyDown(KeyCode.E) && actionableObject != null && scoreValues.actualScore >= scoreValues.scoreNeeded)
        {
            CmdAction();

            actionableObject = null;
        }
    }
Example #9
0
 /// <summary>
 /// Trigger the OnItemPlacedInCart event
 /// </summary>
 /// <param name="action">The item that triggered it</param>
 public void TriggerOnItemPlacedInCart(Interactible item)
 {
     if (onItemPlacedInCart != null)
     {
         onItemPlacedInCart.Invoke(item);
     }
 }
Example #10
0
    private void Awake()
    {
        if (defaultPosition == null)
        {
            defaultPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z);
        }
        player            = GameObject.FindGameObjectWithTag("Player");
        pC                = player.GetComponent <PlayerChased>();
        destinationSetter = GetComponent <AIDestinationSetter>();
        aiPath            = GetComponent <AIPath>();

        aiPath.maxSpeed          = speed;
        destinationSetter.target = player.transform;

        if (instantChase)
        {
            AngerTrigger();
        }
        else
        {
            Idle();
        }

        Interactible interactible = GetComponent <Interactible>();

        if (interactible)
        {
            interactible.interacted += AngerTrigger;
        }
    }
Example #11
0
    void Update()
    {
        if (CheckObjectForward() && CheckObjectForward() != GrabbedObject)
        {
            InteractionText.text = "Press [F] to grab " + TypeToString[CheckObjectForward().Type];

            if (Input.GetKeyDown(KeyCode.F))
            {
                Interactible newGrabbedObject = CheckObjectForward();

                if (GrabbedObject)
                {
                    GrabbedObject.transform.parent = null;
                    GrabbedObject.IsGrabbed        = false;
                }

                GrabbedObject = newGrabbedObject;
                newGrabbedObject.IsGrabbed = true;

                GrabbedObject.transform.parent = Hand;
            }
        }

        else if (Input.GetKeyDown(KeyCode.F) && GrabbedObject)
        {
            GrabbedObject.transform.parent = null;
            GrabbedObject.IsGrabbed        = false;
            GrabbedObject = null;
        }

        else if (CheckObjectForward() == null)
        {
            InteractionText.text = "";
        }
    }
    private void CheckInteraction()
    {
        RaycastHit hit;

        ray = mainCamera.ViewportPointToRay(Vector3.one / 2f);

        bool hasFoundValidItem = (Physics.Raycast(ray, out hit, interactibleDetectionDistance, layerMask));

        if (hasFoundValidItem)
        {
            viewedItem = hit.transform.gameObject.GetComponent <Interactible> ();
            if (viewedItem)
            {
                if (!viewedItem.enabled || viewedItem.hasExternalTrigger)
                {
                    viewedItem = null;
                }
            }
            hasFoundValidItem = (viewedItem && Vector3.Distance(hit.transform.position, playerCamera.transform.position) <= viewedItem.interactionDistance);

            if (hasFoundValidItem && Input.GetMouseButtonDown(0))
            {
                activatedItem = viewedItem;
                activatedItem.TriggerInteraction();
            }
        }

        interactionText.text = (hasFoundValidItem && !viewedItem.getForceRemoveLabel()) ? viewedItem.getPublicName() : "";

        if (activatedItem && (!hasFoundValidItem || Input.GetMouseButtonUp(0)))
        {
            activatedItem.EndInteraction();
            activatedItem = null;
        }
    }
Example #13
0
    private Interactible GetClosestInteractible(out bool present)
    {
        if (_interactibles.Count > 0)
        {
            var myPos = transform.position;

            var          shortestDist = Mathf.Infinity;
            Interactible closest      = null;
            foreach (var i in _interactibles)
            {
                var dist = (i.transform.position - myPos).magnitude;
                if (dist < shortestDist && i.CanInteract())
                {
                    shortestDist = dist;
                    closest      = i;
                }
            }

            present = closest != null;
            return(closest);
        }

        present = false;
        return(null);
    }
Example #14
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = m_camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100, movementMask))
            {
                m_motor.MoveToPoint(hit.point);
                RemoveFocus();
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            Ray        ray = m_camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 100))
            {
                Interactible interactible = hit.collider.GetComponent <Interactible>();
                if (interactible != null)
                {
                    SetFocus(interactible);
                }
            }
        }
    }
Example #15
0
 public void AddToInventory(Interactible pickable)
 {
     if (_inventory.Count < inventorySize)
     {
         _inventory.Add(pickable);
         pickable.gameObject.SetActive(false);
         Debug.Log("Adds objects to inventory");
     }
     if (pickable == pickableHeart)
     {
         balance.State = 1;
     }
     if (pickable == PegaPickable)
     {
         Debug.Log("Pegaste na pega!");
     }
     if (pickable == MeioPickable)
     {
         Debug.Log("Pegaste no meio!");
     }
     if (pickable == LaminaPickable)
     {
         Debug.Log("Pegaste na lamina!");
     }
 }
Example #16
0
 /// <summary>
 /// Trigger the OnPickupDropped event
 /// </summary>
 /// <param name="action">The item that triggered it</param>
 public void TriggerOnPickupDropped(Interactible item)
 {
     if (onPickupDropped != null)
     {
         onPickupDropped.Invoke(item);
     }
 }
Example #17
0
    private void SetInteractible(Interactible newInteractible)
    {
        _currentInteractible = newInteractible;
        if (_currentInteractible.tag == "Teacher")
        {
            if (HasAtLeastOneRequirement(_currentInteractible))
            {
                _currentInteractible.requirementText = "Bring me more Hieroglyphs !";
            }
        }
        if (_currentInteractible.tag == "Puzzle2")
        {
            if (HasInInventory(pickableHeart))
            {
                _currentInteractible.interactionText = "Place Heart of Osiris";
            }
        }

        if (HasRequirements(_currentInteractible))
        {
            _canvasManager.ShowInteractionPanel(_currentInteractible.interactionText);
        }
        else
        {
            _canvasManager.ShowInteractionPanel(_currentInteractible.requirementText);
        }
    }
Example #18
0
 /// <summary>
 /// Trigger the OnInteractibleUsed event
 /// </summary>
 /// <param name="item">The item that triggered it</param>
 public void TriggerOnInteractibleUsed(Interactible item)
 {
     if (onInteractibleUsed != null)
     {
         onInteractibleUsed.Invoke(item);
     }
 }
Example #19
0
 void RpcChangeItem(GameObject _item, GameObject _parent)
 {
     item = _item.GetComponent <Interactible>();
     item.transform.parent        = _parent.transform;
     item.transform.localPosition = -2.0f * Vector3.up;
     item.GetComponent <Interactible>().SetPosition(Vector3.zero);
 }
Example #20
0
 /// <summary>
 /// Trigger the OnItemTakenFromCart event
 /// </summary>
 /// <param name="item">The item that triggered it</param>
 public void TriggerOnItemTakenFromCart(Interactible item)
 {
     if (onItemTakenFromCart != null)
     {
         onItemTakenFromCart.Invoke(item);
     }
 }
Example #21
0
 void Interact(InputAction.CallbackContext context)
 {
     if (context.phase == InputActionPhase.Performed)
     {
         //Debug.Log("cam");
         //Debug.Log(cam.transform.position.x);
         var mousePOS = Input.mousePosition;
         mousePOS.z = 10;
         Vector3 worldPoint = cam.ScreenToWorldPoint(mousePOS);
         Vector2 wp2d       = new Vector2(worldPoint.x, worldPoint.y);
         Debug.Log("WP");
         Debug.Log(wp2d.x);
         Debug.Log(wp2d.y);
         RaycastHit2D hit = Physics2D.Raycast(wp2d, Vector2.zero, 1.0f, layer);
         if (hit)
         {
             Debug.Log(hit.transform.gameObject);
             if (hit.transform.tag == "Interactible")
             {
                 if (!hit.transform.GetChild(0).gameObject.activeInHierarchy)
                 {
                     return;
                 }
                 Interactible inter = hit.transform.GetComponent <Interactible>();
                 inter.Play(thisPlayer);
                 myPlayer = false;
                 Debug.Log("Played!");
             }
         }
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetButton("Fire3") /*GetKeyDown(KeyCode.Space)*/ == true)
     {
         Collider2D[] interactInRange = Physics2D.OverlapBoxAll(transform.position, Vector2.one, 0, LayerMask.GetMask("Interact"));
         if (interactInRange.Length > 0)
         {
             for (int i = 0; i < interactInRange.Length; i++)
             {
                 Interactible myInteract = interactInRange[i].GetComponent <Interactible>();
                 if (myInteract != null)
                 {
                     //myInteract.StartExecute(this);
                     Debug.Log("Get GameObject = " + interactInRange[i].gameObject.name);
                 }
             }
             Debug.Log("Fin");
         }
     }
     else if (Input.GetButtonUp("Fire3"))
     {
         Collider2D[] interactInRange = Physics2D.OverlapBoxAll(transform.position, Vector2.one, 0, LayerMask.GetMask("Interact"));
         if (interactInRange.Length > 0)
         {
             for (int i = 0; i < interactInRange.Length; i++)
             {
                 Interactible myInteract = interactInRange[i].GetComponent <Interactible>();
                 if (myInteract != null)
                 {
                     myInteract.EndExecute();
                 }
             }
         }
     }
 }
Example #23
0
    // Detect in the map the interactible objects containing the given action
    private GameObject[] ScanInteractibleObjects(Action action)
    {
        if (interactibleObjects.Items == null)
        {
            return(null);
        }
        List <GameObject> gameObjects = new List <GameObject>();

        foreach (GameObject obj in interactibleObjects.Items)
        {
            Interactible interactible = obj.GetComponent <Interactible>();
            if (interactible != null)
            {
                foreach (Action actionItem in interactible.actions)
                {
                    if (actionItem.GetType().Equals(action.GetType()))
                    {
                        gameObjects.Add(obj);
                        break;
                    }
                }
            }
            else
            {
                Debug.Log("Error: non interactible detected in the interactible object list.");
            }
        }
        return(gameObjects.ToArray());
    }
Example #24
0
    private void Update()
    {
        RaycastHit hit;

        if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, 3))
        {
            reticle.localPosition = new Vector3(0, 0, hit.distance - 0.01f);
            Interactible focus = hit.transform.GetComponent <Interactible>();
            if (focus != null)
            {
                if (Controls.Interact)
                {
                    focus.Interact();
                }
                mat.SetColor("_Color", Color.green);
            }
            else
            {
                mat.SetColor("_Color", neutral);
            }
        }
        else
        {
            reticle.localPosition = new Vector3(0, 0, 3);
            mat.SetColor("_Color", neutral);
        }
    }
Example #25
0
 //Remove items from inventory
 private void RemoveFromInventory(Interactible pickable)
 {
     //Remove pickable from inventory
     _inventory.Remove(pickable);
     //Update Inventory Icons(need fix)
     UpdateInventoryIcons();
 }
Example #26
0
    void Interact()
    {
        GameObject[] mesInteractibles  = GameObject.FindGameObjectsWithTag("Interactible");
        int          nbInteractibles   = mesInteractibles.Length;
        bool         interactibleFound = false;
        int          i = 0;

        while ((!interactibleFound) && (nbInteractibles != 0) && (i < nbInteractibles))
        {
            Interactible myComponent = mesInteractibles[i].GetComponent <Interactible>();
            i++;
            if (myComponent != null)
            {
                if (myComponent.interactionPossible)
                {
                    interactibleFound = true;
                    Debug.Log(myComponent.gameObject.transform.name + "interactible found");

                    myComponent.Interaction();

                    Debug.Log("interaction done");
                }
            }
        }
    }
Example #27
0
 void Awake()
 {
     _squareCollider    = Button.gameObject.GetComponent <BoxCollider>();
     _circleCollider    = Button.gameObject.GetComponent <MeshCollider>();
     _restingScaleSize  = Button.gameObject.transform.localScale;
     _squareImage       = Button.gameObject.GetComponent <Image>();
     _buttonCanvas      = Button.gameObject.GetComponent <Canvas>();
     _buttonCanvasGroup = Button.gameObject.GetComponent <CanvasGroup>();
     _interactible      = Button.gameObject.GetComponent <Interactible>();
     _iconText          = Button.gameObject.GetComponentsInChildren <TextMeshProUGUI>(true).ToList()[0];
     if (GazeTimerImage != null)
     {
         _gazeTimerColor = GazeTimerImage.color;
     }
     if (CircleImage != null)
     {
         _circleColor = CircleImage.color;
     }
     if (RingImage != null)
     {
         _ringColor = RingImage.color;
     }
     if (IconImage != null)
     {
         _iconColor = IconImage.color;
     }
     if (ActiveHighlight != null)
     {
         ActiveHighlight.SetActive(false);
     }
     //_audioController = Extensions.GetRequired<AudioController>();
     SetGazeTime(_gazeTimeInSeconds);
     //SetDropdownColors();
 }
Example #28
0
    private void Interact(Interactible interactible)
    {
        if (interactible.consumesRequirements)
        {
            for (int i = 0; i < interactible.inventoryRequirements.Length; ++i)
            {
                RemoveFromInventory(interactible.inventoryRequirements[i]);
            }

            if (_currentInteractible.State == 1)
            {
                heart.gameObject.SetActive(true);
                heart.isInteractive = false;
                AddToInventory(jewel);
            }
            else if (_currentInteractible.isPuzzle2)
            {
                jewel.gameObject.SetActive(true);
            }
        }

        interactible.Interact();
        if (_currentInteractible.tag == "Teacher")
        {
            Mark.SetActive(false);
        }
    }
Example #29
0
 public void Interact(Interactible obj)
 {
     if (obj.IsInteractible())
     {
         obj.Dialogue();
     }
 }
Example #30
0
    //build all the game objects from new mapSpaces array
    public void buildWorldFromMapSpaces()
    {
        for (int y = 0; y < map.getYLength(); y++)
        {
            for (int z = 0; z < map.getZLength(); z++)
            {
                for (int x = 0; x < map.getXLength(); x++)
                {
                    Interactible curInteractible = map.GetInteractible(new Vector3(x, y, z));
                    if (curInteractible != null && curInteractible.gameObjectScript == null)
                    {
                        instantiateInteractible(curInteractible, new Vector3(x, y, z));
                    }

                    MapSpace space = map.getMapSpace(new Vector3(x, y, z));

                    instantiateFloor(space.floorType, new Vector3(x, y, z));
                    instantiateWall(space.leftWall, new Vector3(x, y, z), WallOrientation.left);
                    instantiateWall(space.rightWall, new Vector3(x, y, z), WallOrientation.right);
                    instantiateWall(space.frontWall, new Vector3(x, y, z), WallOrientation.front);
                    instantiateWall(space.backWall, new Vector3(x, y, z), WallOrientation.back);
                }
            }
        }
    }