public IEnumerator PedestrianAllowCrossingMaskTest() { DisableLoops(); DisableVehicles(); int roadAreaMask = 1 << NavMesh.GetAreaFromName(PedestrianManager.ROAD_AREA); int walkableAreaMask = 1 << NavMesh.GetAreaFromName(PedestrianManager.WALKABLE_AREA); int pedestrianCrossingAreaMask = 1 << NavMesh.GetAreaFromName(PedestrianManager.PEDESTRIAN_CROSSING_AREA); PedestrianFactory pedestrianFactory = GameObject.FindObjectOfType <PedestrianFactory>(); pedestrianFactory.SpawnPedestrian(); yield return(new WaitForSeconds(1)); Pedestrian pedestrian = GameObject.FindObjectOfType <Pedestrian>(); pedestrian.SetAllowCrossing(true); NavMeshAgent navMeshAgent = pedestrian.GetComponent <NavMeshAgent>(); navMeshAgent.speed = 0; yield return(new WaitForSeconds(1)); Assert.IsTrue(navMeshAgent.areaMask == (walkableAreaMask | pedestrianCrossingAreaMask) || navMeshAgent.areaMask == (roadAreaMask | walkableAreaMask | pedestrianCrossingAreaMask)); pedestrian.SetAllowCrossing(false); yield return(new WaitForSeconds(1)); Assert.IsTrue(navMeshAgent.areaMask == (walkableAreaMask) || navMeshAgent.areaMask == (roadAreaMask | walkableAreaMask)); }
public IEnumerator PedestrianFullWalkTest() { DisableLoops(); DisableVehicles(); foreach (Pedestrian p in GameObject.FindObjectsOfType <Pedestrian>()) { GameObject.Destroy(p); } foreach (PedestrianCrossing pedestrianCrossing in PedestrianManager.GetInstance().GetPedestrianCrossings()) { pedestrianCrossing.SetAllowCrossing(true); } PedestrianFactory pedestrianFactory = GameObject.FindObjectOfType <PedestrianFactory>(); pedestrianFactory.SpawnPedestrian(); yield return(new WaitForSeconds(1)); Pedestrian pedestrian = GameObject.FindObjectOfType <Pedestrian>(); pedestrian.GetComponent <NavMeshAgent>().speed = 5; pedestrian.SetAllowCrossing(true); while (true) { yield return(new WaitForSeconds(1)); if (pedestrian == null) { break; } else { pedestrian.GetComponent <NavMeshAgent>().speed = 5; } } }
private void OnTriggerEnter(Collider collider) { Pedestrian pedestrian = collider.gameObject.GetComponent <Pedestrian>(); if (pedestrian != null) { pedestriansCurrentlyInCrossingArea.Add(pedestrian); pedestrian.SetAllowCrossing(allowCrossing); } }
private void OnTriggerExit(Collider collider) { Pedestrian pedestrian = collider.gameObject.GetComponent <Pedestrian>(); if (pedestrian != null) { pedestriansCurrentlyInCrossingArea.Remove(pedestrian); if (FindObjectsOfType <PedestrianCrossing>().Count(p => p.pedestriansCurrentlyInCrossingArea.Contains(pedestrian)) == 0) { pedestrian.SetAllowCrossing(true); } } }