/// <summary> /// Perform the next available Interaction. /// When no Interactions are available then busy gets set to false. /// </summary> private void PerformInteraction() { NavigationInteraction navigationInteraction = null; NavigationPoint navigationPoint = null; if (interactionQueue.Count > 0) { busy = true; navigationInteraction = interactionQueue[0]; navigationPoint = navigationInteraction.navigationPoint; } else { busy = false; return; } List <Vector2> route = new List <Vector2>(); if (currentPosition == navigationPoint.position) { route = new List <Vector2>() { currentPosition }; } else { Vector2 position = currentPosition; route = navigator.GetRoute(position, navigationPoint); } SetRoute(route, navigationInteraction); }
/// <summary> /// Add an Interaction to the queue. /// If the bellhop isn't busy then the first task will be performed. /// </summary> /// <param name="navigationInteraction">Interaction to add</param> public void AddInteractionToQueue(NavigationInteraction navigationInteraction) { if (navigationInteraction && interactionQueue.Count < maxQueue) { interactionQueue.Add(navigationInteraction); UpdateUI(); } if (!busy) { PerformInteraction(); } }
/// <summary> /// Bellhop gets the supply NavigationInteraction added to it's queue. /// Selected guest is set to null and rooms highlights will disappear. /// </summary> /// <param name="collider">Collider of touched GameObject.</param> /// <param name="moneyHandler">Reference to the moneyHandler.</param> /// <param name="objectiveHandler">Reference to the objectiveHandler.</param> /// <param name="selectedGuest">Actual Reference to the selectedGuest in the TouchInput Script.</param> /// <param name="bellhop">Actual Reference to the bellhop in the TouchInput Script.</param> public override void TouchInteract(Collider2D collider, MoneyHandler moneyHandler, ObjectiveHandler objectiveHandler, ref Guest selectedGuest, ref Bellhop bellhop) { if (bellhop) { NavigationInteraction supply = collider.GetComponent <NavigationInteraction>(); bellhop.AddInteractionToQueue(supply); if (selectedGuest) { selectedGuest.navigator.HighlightRooms(false); selectedGuest = null; } } }
/// <summary> /// Change Interaction Queue text to match the order of the interaction in the queue. /// </summary> private void SetInteractionText() { List <NavigationInteraction> alreadyReset = new List <NavigationInteraction>(); for (int i = 0; i < interactionQueue.Count; i++) { NavigationInteraction interaction = interactionQueue[i]; string text = string.Empty; TextMeshPro tmpObject = null; if (!interactionQueueText.ContainsKey(interaction)) { GameObject textObject = Instantiate(textPrefab, interaction.navigationPoint.position, Quaternion.Euler(Vector3.zero), textParent); interactionQueueText.Add(interaction, textObject); tmpObject = textObject.GetComponentInChildren <TextMeshPro>(); text = "("; } else { tmpObject = interactionQueueText[interaction].GetComponentInChildren <TextMeshPro>(); if (alreadyReset.Contains(interaction)) { text = tmpObject.text; text = text.Trim(')'); text += "+"; } else { text = "("; alreadyReset.Add(interaction); } } int queueCount = i + 1; text += queueCount + ")"; tmpObject.text = text; } }
/// <summary> /// Make the guest walk towards the given positions. /// Interact with the given interaction when the last position has been reached. /// </summary> /// <param name="positions">List of positions to move towards.</param> /// <param name="interaction">Interaciton to trigger.</param> public void SetRoute(List <Vector2> positions, NavigationInteraction interaction) { this.positions = positions; navigationInteraction = interaction; }
/// <summary> /// Set some variable references that the guest needs at the beginning of spawning. /// This method is called by the spawner. /// </summary> /// <param name="navigator">Reference to the navigator script.</param> /// <param name="exit">NavigationInteraction where the guest should exit.</param> /// <param name="guestSpawner">Reference to the spawner of the guests.</param> public void InitializedGuest(Navigator navigator, NavigationInteraction exit, GuestSpawner guestSpawner) { this.navigator = navigator; this.exit = exit; this.guestSpawner = guestSpawner; }