コード例 #1
0
        private void Update()
        {
            if (currentInteractible != null)
            {
                if (closestIndicatorSprite != null)
                {
                    closestIndicatorSprite.enabled = false;
                }

                return;
            }

            if (interactibles.Count > 0)
            {
                PhysicalInteractible interactible = GetClosest();

                if (closestInteractible != interactible)
                {
                    UpdateCurrentInteractible(interactible);
                    UpdateCurrentIndicator();
                }

                UpdateIndicatorVisibility();
            }
        }
コード例 #2
0
 public static void AddInteractible(PhysicalInteractible interactible)
 {
     if (!interactibles.Contains(interactible))
     {
         interactibles.Add(interactible);
     }
 }
コード例 #3
0
 /// <summary>
 /// Remove the current interactible.
 /// </summary>
 private static void RemoveCurrentInteractible()
 {
     if (closestIndicator != null)
     {
         closestInteractible       = null;
         closestInteractibleSprite = null;
     }
 }
コード例 #4
0
 public static void RemoveInteractible(PhysicalInteractible interactible)
 {
     interactibles.Remove(interactible);
     if (interactibles.Count == 0)
     {
         RemoveCurrentInteractible();
         RemoveCurrentIndicator();
     }
 }
コード例 #5
0
        /// <summary>
        /// Retrieves the closest interactible object that the player is close enough to interact with.
        /// </summary>
        /// <returns>The closest interactible object.</returns>
        private PhysicalInteractible GetClosest()
        {
            if (interactibles.Count == 0)
            {
                return(null);
            }

            PhysicalInteractible closest = interactibles[0];
            float closestDist            = DistanceFromPlayer(closest);

            foreach (PhysicalInteractible next in interactibles)
            {
                float dist = DistanceFromPlayer(next);
                if (dist < closestDist)
                {
                    closest     = next;
                    closestDist = dist;
                }
            }

            return(closest);
        }
コード例 #6
0
 /// <summary>
 /// Remove an object from the list of objects the player is close enough to interact with.
 /// </summary>
 /// <param name="interactible">The object to remove.</param>
 void IInteractionComponent.RemoveInteractible(PhysicalInteractible interactible) => InteractionComponent.RemoveInteractible(interactible);
コード例 #7
0
 /// <summary>
 /// Add an object to the list of objects the player is close enough to interact with.
 /// </summary>
 /// <param name="interactible">The object to add.</param>
 void IInteractionComponent.AddInteractible(PhysicalInteractible interactible) => InteractionComponent.AddInteractible(interactible);
コード例 #8
0
 /// <summary>
 /// Set information about the current interactible.
 /// </summary>
 /// <param name="interactible">The interactible to set.</param>
 private void SetCurrentInteractible(PhysicalInteractible interactible)
 {
     closestInteractible       = interactible;
     closestInteractibleSprite = closestInteractible.GetComponent <SpriteRenderer>();
 }
コード例 #9
0
 /// <summary>
 /// Update the current interactible information.
 /// </summary>
 /// <param name="interactible">The interactible to set.</param>
 private void UpdateCurrentInteractible(PhysicalInteractible interactible)
 {
     RemoveCurrentInteractible();
     SetCurrentInteractible(interactible);
 }
コード例 #10
0
 /// <summary>
 /// How far away an interactible is from the player.
 /// </summary>
 /// <param name="interactible">The interactible to check.</param>
 /// <returns>The distance from the center of the player to the center of the
 /// interactible.</returns>
 private float DistanceFromPlayer(PhysicalInteractible interactible)
 {
     return((interactible.Center - (Vector2)playerCollider.bounds.center).magnitude);
 }
コード例 #11
0
        /// <summary>
        /// Whether or not the player can carry this game object.
        /// </summary>
        /// <param name="obj">The object to check.</param>
        /// <returns>True if the object can be carried. False otherwise.</returns>
        public bool CanCarry(GameObject obj)
        {
            PhysicalInteractible interactible = obj.GetComponent <PhysicalInteractible>();

            return((interactible != null) && (interactible is Carriable));
        }
コード例 #12
0
 /// <summary>
 /// Remove an object from the list of objects the player is close enough to interact with.
 /// </summary>
 /// <param name="interactible">The object to remove.</param>
 public void RemoveInteractible(PhysicalInteractible interactible) => Interaction.RemoveInteractible(interactible);
コード例 #13
0
 /// <summary>
 /// Add an object to the list of objects the player is close enough to interact with.
 /// </summary>
 /// <param name="interactible">The object to add.</param>
 public void AddInteractible(PhysicalInteractible interactible) => Interaction.AddInteractible(interactible);