private void SpawnNextCustomer() { int randomStartIndex = Random.Range(0, customerServingAreas.Count); CustomerServingArea nextCustomerServeArea = null; for (int i = 0; i < customerServingAreas.Count; i++) { if (randomStartIndex >= customerServingAreas.Count) { randomStartIndex = 0; } if (customerServingAreas[randomStartIndex].ServingAreaOccupied == false) { nextCustomerServeArea = customerServingAreas[randomStartIndex]; break; } randomStartIndex++; } if (nextCustomerServeArea != null) { SpawnCustomer(nextCustomerServeArea); } }
private void SpawnCustomer(CustomerServingArea servingArea) { if (servingArea.ServingAreaOccupied) { return; } Transform spawnEntranceRef = servingArea.GetComponent <ServeAreaPositions>().CustomerEntrance; Customer spawnedCustomer = Instantiate(customerPrefab, spawnEntranceRef.position, spawnEntranceRef.rotation, transform.parent); spawnedCustomer.StartCustomerCoroutine(servingArea, logicHandler); spawnedCustomer.OnCustomerLeaving.AddListener(OnCustomerLeaving); activeCustomers.Add(spawnedCustomer); GiveUIToCustomer(spawnedCustomer); }
/// <summary> /// Assigns the customer's serving area; this also starts the customer coroutine /// </summary> /// <param name="customerServingArea"></param> public void StartCustomerCoroutine(CustomerServingArea customerServingArea, ICustomerLogicHandler customerLogicHandler) { this.customerLogicHandler = customerLogicHandler; // If the serving area isn't already null, then debug a log error if (servingArea != null) { Debug.LogError("AssignServingArea was called but this customer already has a serving area assigned", this.gameObject); return; } // Otherwise, assign the customer serving area servingArea = customerServingArea; servingArea.ServingAreaOccupied = true; // Start the customer coroutine customerCoroutine = StartCoroutine(CustomerCoroutine()); }