Пример #1
0
    private void OnTriggerEnter(Collider other)
    {
        Interactable interactable = GetInteractableFromTransform(other.transform);

        if (interactable != null && !interactableList.Contains(interactable) && interactable.CanInteract())
        {
            interactableList.Add(interactable);
        }
    }
Пример #2
0
    // Set closest interactable once we're in range
    void OnTriggerStay2D(Collider2D other)
    {
        Interactable otherInter = other.GetComponent <Interactable>();

        if (otherInter != null && otherInter.CanInteract(this))
        {
            closestInteractable = otherInter;
        }
    }
Пример #3
0
    public void Interact()
    {
        if (currentInteractable != null && currentInteractable.CanInteract())
        {
            currentInteractable.Interact(this);

            if (!currentInteractable.CanInteract())
            {
                interactableList.Remove(currentInteractable);
                if (interactableList.Count == 0)
                {
                    hideTooltipAction.Invoke();
                }
            }

            currentInteractable = null;
        }
    }
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.E) && interactable != null)
     {
         if (interactable.CanInteract(transform))
         {
             interactable.Interact();
         }
     }
 }
Пример #5
0
    private void OnTriggerEnter(Collider other)
    {
        Interactable interactable = other.GetComponent <Interactable>();

        if (interactable == null || !interactable.CanInteract())
        {
            return;
        }
        interactables.Add(interactable);
        UpdateClosestInteractable();
    }
Пример #6
0
    [ClientRpc] void RpcStartInteract(GameObject interactableObj)
    {
        Interactable interactable = interactableObj.GetComponent <Interactable>();

        if (interactable.CanInteract())
        {
            interactingType   = interactable.Interact(hero);
            interactingObject = interactable;
            isInteracting     = true;
        }
    }
Пример #7
0
 public void InteractWithInteractable()
 {
     if (InteractableObject != null)
     {
         var canInteract = InteractableObject.CanInteract(gameObject.transform);
         if (canInteract)
         {
             InteractableObject.Interact();
         }
     }
 }
Пример #8
0
    void Update()
    {
        Interactable newInteractable = null;

        // We can only interact with an item if the item is in reach and we are
        // not currently holding an item.
        newInteractable = character.HasItem() ? character.currentHeldItem : GetBestInteractable();
        // If we are able to interact with stuff
        if (newInteractable != null)
        {
            // Interactable newInteractable = raycastFocus.collider.transform.GetComponent<Interactable>();
            // If we are already interacting with something but we are now
            // trying to interact with something new, then we need to disable
            // the other interaction (turn off its glow).
            if (newInteractable != currentInteractable && currentInteractable != null)
            {
                currentInteractable.InteractionGlowOff();
            }
            currentInteractable = newInteractable;

            if (currentInteractable != null && currentInteractable.CanInteract(character))
            {
                // If we are able to interact with the new interactable then turn on its glow
                newInteractable.InteractionGlowOn();

                // If we are pressing mouse down then do the interaction
                if (Input.GetButtonDown("Fire1"))
                {
                    // Do whatever the primary interaction of this interactable is.
                    currentInteractable.PrimaryInteraction(character);
                    hasInteractedWithCurrentInteractble = true;
                }
            }
        }
        // If we cant interact with anything but we were previously
        // interacting with something or we were previously interacting with
        // something and we are now trying to do a mouse up.
        if (currentInteractable != null && (Input.GetButtonUp("Fire1") || newInteractable == null))
        {
            Debug.Log($"Dropping {newInteractable}");
            // Then turn off the glow of that thing and do the interaction off
            currentInteractable.InteractionGlowOff();

            // If we havent interacted with the thing then we cannot uninteract
            if (hasInteractedWithCurrentInteractble)
            {
                currentInteractable.PrimaryInteractionOff(character);
            }

            currentInteractable = null;
            hasInteractedWithCurrentInteractble = false;
        }
    }
Пример #9
0
    void InteractWithInteractable()
    {
        if (!activeInteractable)
        {
            return;
        }

        if (activeInteractable.CanInteract(transform.position))
        {
            activeInteractable.Interact();
        }
    }
Пример #10
0
    public IEnumerator FunctionalRequirements_PlayersShouldOnlyBeAbleToInteractWithObjectsOfTheirColour()
    {
        GameObject            magePlayer        = Object.Instantiate(TestResourceManager.Instance.GetResource("Mage Player"), Vector3.zero, Quaternion.identity);
        PlayerStatsController magePlayerStats   = magePlayer.GetComponent <PlayerStatsController>();
        GameObject            meleePlayer       = Object.Instantiate(TestResourceManager.Instance.GetResource("Melee Player"), Vector3.zero, Quaternion.identity);
        PlayerStatsController meleePlayerStats  = meleePlayer.GetComponent <PlayerStatsController>();
        GameObject            healerPlayer      = Object.Instantiate(TestResourceManager.Instance.GetResource("Healer Player"), Vector3.zero, Quaternion.identity);
        PlayerStatsController healerPlayerStats = healerPlayer.GetComponent <PlayerStatsController>();
        GameObject            rangedPlayer      = Object.Instantiate(TestResourceManager.Instance.GetResource("Ranged Player"), Vector3.zero, Quaternion.identity);
        PlayerStatsController rangedPlayerStats = rangedPlayer.GetComponent <PlayerStatsController>();

        magePlayerStats.characterColour   = CharacterColour.Green;
        meleePlayerStats.characterColour  = CharacterColour.Red;
        healerPlayerStats.characterColour = CharacterColour.Blue;
        rangedPlayerStats.characterColour = CharacterColour.Yellow;

        magePlayer.transform.position  = new Vector3(0, 0, -2);
        meleePlayer.transform.position = new Vector3(-2, 0, -2);

        GameObject lever = Object.Instantiate(TestResourceManager.Instance.GetResource("Lever"), Vector3.zero, Quaternion.identity);

        lever.transform.position = new Vector3(0, 0, 0);
        Interactable handle = lever.GetComponentInChildren <Interactable>();

        handle.colour = CharacterColour.Red;

        magePlayer.transform.position  = new Vector3(1, 0, 0);
        meleePlayer.transform.position = new Vector3(-1, 0, 0);

        yield return(new WaitForEndOfFrame());

        yield return(new WaitForEndOfFrame());

        Assert.IsFalse(handle.CanInteract(magePlayer.transform));
        Assert.IsTrue(handle.CanInteract(meleePlayer.transform));

        yield return(null);
    }
Пример #11
0
    public void Refresh()
    {
        if (guiCaptionHour != null && planetTime != null)
        {
            string hourUnit   = Mathf.RoundToInt(planetTime.GetCurrentHour(time)).ToString("00");
            string minuteUnit = Mathf.RoundToInt(planetTime.GetCurrentMinute(time)).ToString("00");
            string secondUnit = Mathf.RoundToInt(planetTime.GetCurrentSecond(time)).ToString("00");
            guiCaptionHour.text = string.Format(DEFAULT_STRING_GUICAPTION_TIME_FORMAT, hourUnit, minuteUnit, secondUnit);
        }

        if (guiCursorItemAimed != null && characterInteraction != null)
        {
            Interactable target = null;
            if (characterInteraction.triggerAimed != null)
            {
                target = characterInteraction.triggerAimed;
            }
            else if (characterInteraction.itemAimed != null)
            {
                target = characterInteraction.itemAimed;
            }

            if (target != null && target.CanInteract())
            {
                guiCursorItemAimed.gameObject.SetActive(true);
                guiCursorItemAimed.target = target.transform;
                guiCursorItemAimed.guiBackground.SetCaption(string.Format(DEFAULT_STRING_GUICAPTION_ITEM_FORMAT, target.title));
            }
            else
            {
                guiCursorItemAimed.gameObject.SetActive(false);
                guiCursorItemAimed.target = null;
            }
        }

        if (guiCaptionItemName != null && characterInteraction != null)
        {
            string name = (characterInteraction.itemGrabbed != null) ? characterInteraction.itemGrabbed.title : "";
            guiCaptionItemName.text = name;
        }

        if (guiCaptionItemMass != null && characterInteraction != null)
        {
            string mass = (characterInteraction.itemGrabbed != null) ? string.Format(DEFAULT_STRING_GUICAPTION_ITEMMASS_FORMAT, characterInteraction.itemGrabbed.mass) + "" : "<>";
            guiCaptionItemMass.text = mass;
        }
    }
Пример #12
0
        /// <summary>
        /// Called when the ablity is tried to be started. If false is returned then the ability will not be started.
        /// </summary>
        /// <returns>True if the ability can be started.</returns>
        public override bool CanStartAbility()
        {
            // The base class may prevent the ability from starting.
            if (!base.CanStartAbility())
            {
                m_Interactable = null;
                return(false);
            }

            // The ability can't start if the Interactable isn't ready.
            if (!m_Interactable.CanInteract(m_GameObject))
            {
                return(false);
            }

            return(true);
        }
Пример #13
0
 // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
 override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     //If get damage before animations ends, cannot interact!
     if (animator.GetNextAnimatorStateInfo(0).IsName("Damage") == false)
     {
         int          layerMask    = 1 << LayerMask.NameToLayer("Interactable");
         Collider[]   colliders    = Physics.OverlapSphere(playerController.transform.position, 1, layerMask);
         Interactable interactable = null;
         foreach (Collider col in colliders)
         {
             interactable = col.gameObject.GetComponent <Interactable>();
             if (interactable != null && interactable.CanInteract())
             {
                 interactable.Run();
                 playerController.canInteract = false;
                 break;
             }
         }
     }
 }
Пример #14
0
    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.CompareTag(interactTag) && Input.GetKeyDown(KeyCode.Space))
        {
            //Récupération de la référence du script Interactable attaché sur l'objet du collider
            Interactable interactableScript = other.gameObject.GetComponent <Interactable>();

            if (interactableScript.CanInteract() == true)
            {
                interactableScript.Interact();
            }


            if (interactableScript.isBooster)
            {
                MovementController movementScript = this.gameObject.GetComponent <MovementController>();
                movementScript.Boost();
            }
        }
    }
Пример #15
0
    // Handle movement and interaction input
    virtual protected void Update()
    {
        // Movement
        HandleMovement();

        // Interaction
        if (Input.GetButtonDown("Fire1") == true)
        {
            if (closestInteractable != null && closestInteractable.CanInteract(this))
            {
                closestInteractable.Interact(this);
            }
        }

        // Drop off current item
        if (Input.GetButtonDown("Fire2") == true && heldItem != null)
        {
            DropItem();
        }
    }
Пример #16
0
        public void Interactable_CanInteract_FalseIfOutOfRange()
        {
            GameObject gameObject = new GameObject();
            Transform  objPos     = gameObject.GetComponent <Transform>();

            objPos.position = Vector3.up; //position (0,1,0)
            Interactable interactable = gameObject.AddComponent <Interactable>();

            interactable.radius = 0f;                  //test range of 0 first, then range of 0.5, range of 1, and range of arbitrarily large.
            interactable.colour = CharacterColour.Red; //set target and 'player' colour to RED

            //variables for 'player'
            GameObject player    = new GameObject();
            Transform  playerPos = player.GetComponent <Transform>();

            playerPos.position = Vector3.zero; //position (0,0,0)
            EntityStatsController playerControl = player.AddComponent <EntityStatsController>();

            playerControl.characterColour = CharacterColour.Red;//set player colour to Red to start

            Assert.False(interactable.CanInteract(playerPos));

            interactable.radius = 0.5f;
            Assert.False(interactable.CanInteract(playerPos));

            interactable.radius = 0.9999f;
            Assert.False(interactable.CanInteract(playerPos));


            interactable.radius = 1.0f; // this should be interactible
            Assert.True(interactable.CanInteract(playerPos));

            objPos.position = new Vector3(0, 2, 0); //position (0,2,0)
            //interactible radius is still 1, test it is now out of range
            Assert.False(interactable.CanInteract(playerPos));

            //arbitrarily large number 235463

            interactable.radius = 235463.0f;
            objPos.position     = new Vector3(235463, 235463, 235463); //arbitrarily far
            //interactible radius is still 1, test it is now out of range
            Assert.False(interactable.CanInteract(playerPos));

            Object.DestroyImmediate(gameObject);
            //Object.Destroy(player);
        }
Пример #17
0
    public void OnInteractKeyDown()
    {
        if (!isInteracting)
        {
            if (!interactableDetector.CanInteract())
            {
                return;
            }

            Interactable interactable = interactableDetector.FindNearestObject();
            if (interactable != null && interactable.CanInteract())
            {
                CmdStartInteract(interactable.gameObject);
            }
        }
        else
        {
            if (interactingType == InteractType.TOGGLE)
            {
                CmdStopInteract();
            }
        }
    }
    private Interactable SetGoal()
    {
        if (interactables.Count == 0)
        {
            return(null);
        }

        System.Random r         = new System.Random(System.Guid.NewGuid().GetHashCode());
        int           randIndex = r.Next(interactables.Count);

        Interactable newInteractable = interactables[randIndex];

        if (!newInteractable.CanInteract(character))
        {
            return(null);
        }
        if (newInteractable.task != null)
        {
            Debug.Log("Found a task on an interactable");
            return(null);
        }
        return(newInteractable);
    }
Пример #19
0
    protected void Update()
    {
        // set the movement actions
        float movementX = Input.GetAxis("Horizontal");
        bool  jump      = Input.GetButtonDown("Jump");
        bool  duck      = Input.GetButton("Duck");
        bool  attack    = Input.GetButtonDown("Fire1");

        Controller.Move(movementX, jump, attack, duck);

        if (Controller.canAttack && attack)
        {
            Attack();
        }

        if (duck)
        {
            if (Interactable != null && Interactable.CanInteract(this))
            {
                StartCoroutine(Interact());
            }
        }
    }
Пример #20
0
 void Update()
 {
     if (CanInteract() && interactableObjects.Count > 0)
     {
         Interactable nearest = FindNearestObject();
         if (nearest != null)
         {
             if (!nearest.CanInteract())
             {
                 interactableObjects.Remove(nearest);
                 buttonRenderer.enabled = false;
             }
             else
             {
                 buttonRenderer.enabled = true;
                 buttonRenderer.gameObject.transform.position = nearest.gameObject.transform.position + new Vector3(0f, 0f, 0f);
             }
         }
     }
     else
     {
         buttonRenderer.enabled = false;
     }
 }
Пример #21
0
        public void Interactable_CanInteract_FalseIfInRangeAndWrongColour()
        {//set up testing variables for 'target'
            GameObject gameObject = new GameObject();
            Transform  objPos     = gameObject.GetComponent <Transform>();

            objPos.position = Vector3.one; //set both this and the 'player' to the same position
            Interactable interactable = gameObject.AddComponent <Interactable>();

            interactable.colour = CharacterColour.Red; //set target and 'player' colour to NOT MATCH

            //target.GetComponent<EntityStatsController>().characterColour

            //variables for 'player'
            GameObject player    = new GameObject();
            Transform  playerPos = player.GetComponent <Transform>();

            playerPos.position = Vector3.one;
            EntityStatsController playerControl = player.AddComponent <EntityStatsController>();

            playerControl.characterColour = CharacterColour.Green;//set player colour to Green to start

            //assert that we cannot pick up an object in the same position as us, if it doesn't match colour
            //Red object, Green Player
            Assert.False(interactable.CanInteract(playerPos));

            //Blue object, Green Player
            interactable.colour = CharacterColour.Blue;
            Assert.False(interactable.CanInteract(playerPos));

            //Yellow object, Green Player
            interactable.colour = CharacterColour.Yellow;
            Assert.False(interactable.CanInteract(playerPos));


            playerControl.characterColour = CharacterColour.Red;//set player colour to red now
            //Yellow object, Red player
            Assert.False(interactable.CanInteract(playerPos));

            //Blue object, Red Player
            interactable.colour = CharacterColour.Blue;
            Assert.False(interactable.CanInteract(playerPos));

            //Green object, Red Player
            interactable.colour = CharacterColour.Green;
            Assert.False(interactable.CanInteract(playerPos));


            playerControl.characterColour = CharacterColour.Blue;//set player colour to Blue now

            //Green object, Blue Player
            Assert.False(interactable.CanInteract(playerPos));

            //Yellow object, Blue Player
            interactable.colour = CharacterColour.Yellow;
            Assert.False(interactable.CanInteract(playerPos));

            //Red object, Blue Player
            interactable.colour = CharacterColour.Red;
            Assert.False(interactable.CanInteract(playerPos));


            playerControl.characterColour = CharacterColour.Yellow;//Finally set player colour to Yellow

            //Red object, Yellow Player
            Assert.False(interactable.CanInteract(playerPos));

            //Blue object, Yellow Player
            interactable.colour = CharacterColour.Blue;
            Assert.False(interactable.CanInteract(playerPos));

            //Green object, Yellow Player
            interactable.colour = CharacterColour.Green;
            Assert.False(interactable.CanInteract(playerPos));

            Object.DestroyImmediate(gameObject);
            Object.DestroyImmediate(player);
        }
Пример #22
0
    /// <summary>
    /// Toggle the interaction sequence
    /// </summary>
    /// <param name="value">Value of the input controller interact button state</param>
    private void OnInteract(InputValue value)
    {
        // Only trigger on button pressed down
        if (value.isPressed)
        {
            // If currently interacting with a "non-held" object, stop interacting
            if (_currentObject)
            {
                StopInteract();
                return;
            }

            // Ensure the player isn't currently attacking before attempting interaction
            if (_combat.AttackCooldown > 0)
            {
                return;
            }

            // Attempt to interact with the first interactable in the player's view
            if (Physics.Raycast(transform.position + Vector3.up, transform.TransformDirection(Vector3.forward), out RaycastHit hit, interactionRadius))
            {
                Interactable interactable = hit.transform.GetComponent <Interactable>();
                if (interactable is null)
                {
                    return;
                }

                if (!interactable.CanInteract(transform))
                {
                    return;
                }

                // Decide which animation to do
                if (interactable is Draggable)
                {
                    _anim.SetBool("PickedUp", true);
                }
                else if (interactable is Lever)
                {
                    _anim.SetTrigger("InteractStanding");
                }
                else if (interactable is Collectable)
                {
                    _anim.SetTrigger("InteractGround");
                }

                // Attempt interaction
                interactable.StartInteract(transform);

                if (!interactable.isTrigger)
                {
                    _currentObject = interactable;
                }
            }
        }
        else if (_currentObject && _currentObject.isHeld)
        {
            // Stop interacting with a "held" object
            StopInteract();
        }
    }
Пример #23
0
    void OnTriggerEnter(Collider other)
    {
        if (interactable == null)
        {
            interactable = transform.parent.GetComponent <Interactable>();
        }
        var pc = other.GetComponent <PlayerController>();

        if (pc != null && pc._interactSystem != null && pc._interactSystem.enabled && interactable.CanInteract(pc))
        {
            pc._interactSystem.TryActivateInteractable(interactable);
        }
    }
Пример #24
0
    protected override void Update()
    {
        var acceleration = Vector3.zero;

        if (CurrentTask == null && PropSlot == null)
        {
            acceleration = UpdateMovement();
            if (IsInputInState(eInput.Interact, eButtonState.Pressed))
            {
                float minDistance = float.MaxValue;
                Prop  closestProp = null;
                foreach (var prop in Prop.PropsList)
                {
                    var distance = DistanceUtility.Get2d(prop.transform, transform);
                    if (CanHoldProp(prop, distance:distance) &&
                        prop.CanMoveProp() &&
                        distance < minDistance)
                    {
                        closestProp = prop;
                        minDistance = distance;
                    }
                }

                if (closestProp != null)
                {
                    closestProp.PickUpProp(this);
                }


                if (PropSlot == null)
                {
                    foreach (var task in Interactable.Interactables)
                    {
                        var distance = (transform.position - task.transform.position).magnitude;
                        if (distance <= minDistance && task.CanInteract(transform.position))
                        {
                            CurrentTask = task;
                            minDistance = distance;
                            CurrentTask.StartInteraction(this);
                        }
                    }
                }
            }
        }
        else if (PropSlot != null)
        {
            acceleration = UpdateMovement();
            if (IsInputInState(eInput.Interact, eButtonState.Pressed))
            {
                PropSlot.DropProp();
            }
        }
        else if (CurrentTask != null)
        {
            Debug.DrawLine(transform.position, CurrentTask.transform.position, Color.green);

            var distance = (transform.position - CurrentTask.transform.position).magnitude;
            if (!CurrentTask.CanInteract(transform.position) ||
                IsInputInState(eInput.Interact, eButtonState.Pressed))
            {
                CurrentTask.EndInteraction();
                CurrentTask = null;
            }

            if (CurrentTask != null)
            {
                acceleration -= Velocity;
                Velocity      = Vector3.zero;
            }
        }
        UpdateVisuals(acceleration, Velocity);
        TryHideObjectsHiddingPlayer();
        base.Update();
    }
Пример #25
0
    public void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.layer == LayerMask.NameToLayer("Interactable"))
        {
            Interactable interactable = other.gameObject.GetComponent <Interactable>();
            if (interactable != null && interactable.CanInteract())
            {
                canInteract = true;
            }
        }
        else if (other.gameObject.layer == LayerMask.NameToLayer("EnemyAttack"))
        {
            EnemyTrash trashScript           = other.gameObject.GetComponentInParent <EnemyTrash>();
            Attack     currentAttackReceived = trashScript.GetAttack();
            if (currentAttackReceived != null)
            {
                if (anim.GetCurrentAnimatorStateInfo(0).IsName("Damaged") == false && anim.GetCurrentAnimatorStateInfo(0).IsName("Block") == false && anim.GetCurrentAnimatorStateInfo(0).IsName("Die") == false)
                {
                    SpawnHitParticles(other.gameObject.GetComponent <Collider>().ClosestPointOnBounds(transform.position));
                    AudioSources.instance.PlaySound((int)AudiosSoundFX.Enemy_Combat_AttackHit);
                    TakeDamage(currentAttackReceived.damage);
                    anim.SetTrigger("damaged");
                }
                else if (anim.GetCurrentAnimatorStateInfo(0).IsName("Block") == true)
                {
                    AudioSources.instance.PlaySound((int)AudiosSoundFX.Player_Combat_BlockAttack);
                }
            }
        }
        else if (other.gameObject.layer == LayerMask.NameToLayer("BossAttack"))
        {
            bool canReceiveBossAttack = true;

            if (anim.GetCurrentAnimatorStateInfo(0).IsName("Damaged") == true || anim.GetCurrentAnimatorStateInfo(0).IsName("Die") == true)
            {
                canReceiveBossAttack = false;;
            }

            else
            {
                if (other.name == "Ray")
                {
                    Vector3 playerLeftForward = transform.forward - transform.right;
                    if (anim.GetCurrentAnimatorStateInfo(0).IsName("Block") == true && Vector3.Dot(playerLeftForward, other.transform.parent.forward) < 0.2f)
                    {
                        AudioSources.instance.PlaySound((int)AudiosSoundFX.Player_Combat_BlockAttack);
                        canReceiveBossAttack = false;
                    }
                }
                if (other.name == "ArmCollider")
                {
                    //hurts you anyway
                }
            }

            if (canReceiveBossAttack)
            {
                blocking = false;
                SpawnHitParticles(other.gameObject.GetComponent <Collider>().ClosestPointOnBounds(transform.position));
                AudioSources.instance.PlaySound((int)AudiosSoundFX.Enemy_Combat_AttackHit);
                TakeDamage(30);
                anim.SetTrigger("damaged");
            }
        }
    }