public AisleID GetTravelAisle(Vector3 position, AisleID currentAisle, bool stayInRow) { List <AisleID> candidates = new List <AisleID>(); if (stayInRow) { foreach (AisleID a in travelIDs) { if (a.row == currentAisle.row && a.aisleNo != currentAisle.aisleNo) { candidates.Add(a); } } } else { foreach (AisleID a in travelIDs) { if (a.row != currentAisle.row) { candidates.Add(a); } } } AisleID option = candidates[Random.Range(0, candidates.Count)]; return(option); }
void SpawnAisle(AisleID id, int density) { aisleDCounter += density; // Debug.Log("AD: " + density); Row r = id.row; int aisle = id.aisleNo; switch (r) { case Row.Left: SpawnAisle(leftRow[aisle], density); // SpawnAisle(leftRow,aisle,density); break; case Row.Middle: SpawnAisle(middleRow[aisle], density); // SpawnAisle(middleRow,aisle,density); break; case Row.Right: SpawnAisle(rightRow[aisle], density); // SpawnAisle(rightRow,aisle,density); break; default: Debug.LogError("Not a recognised Row"); break; } }
public AisleID GetNearestAisleID(Vector3 position) { float minDistance = Mathf.Infinity; AisleID chosenID = new AisleID(Row.Left, 0); foreach (AisleID aID in travelIDs) { Vector3 nearestNode = aID.GetNearestNode(position, AisleSide.Left | AisleSide.Right); float distance = Vector3.Distance(nearestNode, position); if (distance < minDistance) { chosenID = aID; minDistance = distance; // Debug.Log("Pos: " + position + " nearestNode: " + nearestNode); } } if (minDistance == Mathf.Infinity) { Debug.LogError("No close Aisle found for input position: " + position); } return(chosenID); }
public CustomerInfo(int _key, GameObject _go, NavMeshAgent _agent, AnimationNavigationMatch _script, AisleID _currentAisle, CustomerStates _currentState) { key = _key; go = _go; agent = _agent; script = _script; currentAisle = _currentAisle; currentState = _currentState; }
AisleID GetFreeAisle(Row r) { GameObject[] tempRow = new GameObject[0]; switch (r) { case Row.Left: tempRow = leftRow; break; case Row.Middle: tempRow = middleRow; break; case Row.Right: tempRow = rightRow; break; default: Debug.LogError("Not a recognised Row"); break; } List <int> freeI = new List <int>(); for (int i = 0; i < tempRow.Length; i++) { if (tempRow[i].activeSelf == false) { freeI.Add(i); } } AisleID id = new AisleID(r, freeI[Random.Range(0, freeI.Count)]); return(id); }
void Awake() { pool = GetComponent <ObjectPooler>(); travelIDs = new List <AisleID>(); for (int i = 0; i < leftRow.Length; i++) { AisleID current = new AisleID(Row.Left, i); current.leftNodes = GetNodes(leftRow[i], true); current.rightNodes = GetNodes(leftRow[i], false); travelIDs.Add(current); } for (int i = 0; i < middleRow.Length; i++) { AisleID current = new AisleID(Row.Middle, i); current.leftNodes = GetNodes(middleRow[i], true); current.rightNodes = GetNodes(middleRow[i], false); travelIDs.Add(current); } for (int i = 0; i < rightRow.Length; i++) { AisleID current = new AisleID(Row.Right, i); current.leftNodes = GetNodes(rightRow[i], true); current.rightNodes = GetNodes(rightRow[i], false); travelIDs.Add(current); } }
AisleID GetFreeAisle() { List <Row> bag = new List <Row>(); for (int i = 0; i < leftRow.Length; i++) { if (leftRow[i].activeSelf == false) { bag.Add(Row.Left); } } for (int i = 0; i < middleRow.Length; i++) { if (middleRow[i].activeSelf == false) { bag.Add(Row.Middle); } } for (int i = 0; i < rightRow.Length; i++) { if (rightRow[i].activeSelf == false) { bag.Add(Row.Right); } } int result = Random.Range(0, bag.Count); Row r = bag[result]; AisleID id = GetFreeAisle(r); return(id); }
void changeState(CustomerInfo customer, CustomerStates newState) { customer.currentState = newState; //Debug.Log(customer.go.name + " has begun " + newState.ToString()); switch (newState) { case CustomerStates.Waiting: StartCoroutine(CustomerWaiting(customer.key)); break; case CustomerStates.Searching: AisleID nextAisle = sc_aisles.GetTravelAisle(customer.GetPosition(), customer.currentAisle, false); customer.currentAisle = nextAisle; customer.agent.destination = nextAisle.GetNearestNode(customer.GetPosition(), AisleSide.Left | AisleSide.Right); break; case CustomerStates.Perusing: Vector3 target = customer.currentAisle.GetFurthestAisleExit(customer.GetPosition()); customer.agent.destination = target; break; } }
public void GenerateStock(int day) { aisleDCounter = 0; ///Clear avaiable shelves currentDensity = 0; pool.Refresh(); for (int i = 0; i < leftRow.Length; i++) { leftRow[i].SetActive(false); } for (int i = 0; i < middleRow.Length; i++) { middleRow[i].SetActive(false); } for (int i = 0; i < rightRow.Length; i++) { rightRow[i].SetActive(false); } ///Fill Busy Aisles int busyCount = bulk[day].noOfBusyAisles; List <Row> bag = new List <Row>(); bag.Add(Row.Left); bag.Add(Row.Left); bag.Add(Row.Left); bag.Add(Row.Middle); bag.Add(Row.Middle); bag.Add(Row.Middle); bag.Add(Row.Middle); bag.Add(Row.Middle); bag.Add(Row.Middle); bag.Add(Row.Right); bag.Add(Row.Right); bag.Add(Row.Right); for (int i = 0; i < busyCount; i++) { int result = Random.Range(0, bag.Count); Row r = bag[i]; bag.RemoveAt(result); AisleID aisle = GetFreeAisle(r); int density = Random.Range(busyMM[0], busyMM[1]); SpawnAisle(aisle, density); } ///Fill Empty Aisles int emptyCount = bulk[day].noOfEmptyAisles; for (int i = 0; i < emptyCount; i++) { AisleID aisle = GetFreeAisle(); int density = Random.Range(emptyMM[0], emptyMM[1]); SpawnAisle(aisle, density); } ///Determine number of aisles left and density left int aislesLeft = leftRow.Length + middleRow.Length + rightRow.Length - busyCount - emptyCount; int varianceAmount = Random.Range(-variance, variance + 1); int remainingDensity = bulk[day].baseDensity + varianceAmount - currentDensity; // Debug.Log("variance amount: " + varianceAmount + " remaining density: " + remainingDensity + " current density: " + currentDensity); int ABCounter = 0; ///Half remaining aisles get 2/3 int alphaA = Mathf.FloorToInt((float)aislesLeft / 2f); int densityAlpha = Mathf.CeilToInt(2f * (float)remainingDensity / 3f); int totalAlpha = densityAlpha; int densityPerAAisle = Mathf.CeilToInt((float)densityAlpha / (float)alphaA); for (int i = 0; i < alphaA; i++) { AisleID aisle = GetFreeAisle(); if (densityAlpha > densityPerAAisle) { SpawnAisle(aisle, densityPerAAisle); ABCounter += densityPerAAisle; densityAlpha -= densityPerAAisle; } else { SpawnAisle(aisle, densityAlpha); ABCounter += densityAlpha; } } // Debug.Log("requested alphas: " + ABCounter); ABCounter = 0; ///Other half gets 1/3 int betaA = aislesLeft - alphaA; int densityBeta = remainingDensity - totalAlpha; int densityPerBAisle = Mathf.CeilToInt((float)densityBeta / (float)betaA); for (int i = 0; i < betaA; i++) { AisleID aisle = GetFreeAisle(); if (densityBeta > densityPerBAisle) { SpawnAisle(aisle, densityPerBAisle); ABCounter += densityPerBAisle; densityBeta -= densityPerBAisle; } else { SpawnAisle(aisle, densityBeta); ABCounter += densityBeta; } } Debug.Log(bulk[day].baseDensity + varianceAmount + " planned density. " + aisleDCounter + " sum of requested densities. " + currentDensity + " items spawned. Planned to spawned Diff: " + (bulk[day].baseDensity + varianceAmount - currentDensity)); // Debug.Log("requested betas: " + ABCounter); }
public void GenerateCustomers(int amount) { nextUniqueKey = 0; foreach (CustomerInfo customer in spawnedCustomers) { customer.Destroy(); } spawnedCustomers.Clear(); ///make existing customers for (int i = 0; i < amount; i++) { float xRand = Random.Range(minBounds.x, maxBounds.x); float yRand = Random.Range(minBounds.y, maxBounds.y); float zRand = Random.Range(minBounds.z, maxBounds.z); Vector3 spawnAttempt = new Vector3(xRand, yRand, zRand); NavMeshHit nmh = new NavMeshHit(); if (NavMesh.SamplePosition(spawnAttempt, out nmh, maxNavDistance, NavMesh.AllAreas)) { //determine spawn position Vector3 position = new Vector3(nmh.position.x, yRand, nmh.position.z); //choose a prefab GameObject prefab = customerPrefabs[Random.Range(0, customerPrefabs.Length)]; //get aisle they will spawn in AisleID aID = sc_aisles.GetNearestAisleID(position); //set the customer state on start CustomerStates state = CustomerStates.Start; //Instantiate the GameObject GameObject g = (GameObject)Instantiate(prefab, position, Quaternion.identity, customerHolder.transform); //Get agent NavMeshAgent agent = g.GetComponent <NavMeshAgent>(); AnimationNavigationMatch script = g.GetComponent <AnimationNavigationMatch>(); script.SetManager(this); script.uniqueKey = nextUniqueKey; //Finally create a Customerinfo and add it to the list spawnedCustomers.Add(new CustomerInfo(nextUniqueKey, g, agent, script, aID, state)); Finished(nextUniqueKey); nextUniqueKey++; } else { Debug.LogError("No point found on the NavMesh close enoguh to the randomly chosen position: " + spawnAttempt.ToString()); i--; } } ///set off a coroutine to have more customers enter }