/// <summary>
    /// Awakes the script.
    /// </summary>
    void Awake()
    {
        heatmapCtrl = FindObjectOfType <HeatmapLayer.HeatmapController>();

        trafficContr = FindObjectOfType <TrafficIntegrationController>();
        timeContr    = FindObjectOfType <TimeController>();

        if (trafficContr != null)
        {
            simulationIntegrated     = (trafficContr.typeOfIntegration != TrafficIntegrationController.TypeOfIntegration.NoTrafficIntegration);
            UseFrustumForUpdate      = trafficContr.useFrustumForUpdate;
            UseCoordinateConversion  = trafficContr.useCoordinateConversion;
            brakingActive            = trafficContr.vehicleBrakingActive;
            timeToBrakeInSeconds     = trafficContr.timeToBrakeInSeconds;
            driversPatienceInSeconds = trafficContr.driversPatientInSeconds;
            angleOfView             = trafficContr.driversAngleOfView;
            visualizeTrafficHeatmap = trafficContr.visualizeTrafficInHeatmap;
        }
    }
示例#2
0
    /// <summary>
    /// Awakes the script.
    /// </summary>
    void Awake()
    {
        Debug.Log("Initializing pedestrian spawner...");

        // Get the time controller
        timeCtrl = FindObjectOfType <TimeController>();

        // Get the camera controller
        cameraCtrl = FindObjectOfType <CameraControl>();

        // Get the global parameters of Flash Pedestrians
        pedGlobalParameters = GetComponentInParent <FlashPedestriansGlobalParameters>();

        // Get the heatmap controller
        heatmapCtrl = FindObjectOfType <HeatmapLayer.HeatmapController>();

        // Fill the cache with pedestrians
        for (int i = 0; i < initialNumberOfPedestriansInCache; i++)
        {
            //Random.Range(0, pedGlobalParameters.pedestrianObject.Length)
            GameObject newAgent = Instantiate(pedGlobalParameters.pedestrianObject,
                                              Vector3.zero, Quaternion.identity) as GameObject;

            newAgent.transform.SetParent(this.transform, true);
            pedestrianCache.Enqueue(newAgent);
        }

        // Get the stations that are around the spawner
        Collider[] coll = Physics.OverlapSphere(this.transform.position, radiousToCheckStations, 1 << LayerMask.NameToLayer("Stations"));

        List <StationController> aux = new List <StationController>();

        foreach (Collider C in coll)
        {
            aux.Add(C.GetComponent <StationController>());
        }

        stationsNearThisSpawner = aux.ToArray();

        // Set the spawning points around the spawner
        spawningPoints = new Vector3[numberOfSpawningPoints];
        for (int i = 0; i < numberOfSpawningPoints; i++)
        {
            Vector3 point = new Vector3(
                this.transform.position.x + Random.Range(-radiousToPutSpawningPoints, radiousToPutSpawningPoints),
                0f,
                this.transform.position.z + Random.Range(-radiousToPutSpawningPoints, radiousToPutSpawningPoints));

            //Move the spawning point to the closest point in the walkable navmesh
            UnityEngine.AI.NavMeshHit hit;

            UnityEngine.AI.NavMesh.SamplePosition(point, out hit, 1000.0f,
                                                  1 << UnityEngine.AI.NavMesh.GetAreaFromName("footway") | 1 << UnityEngine.AI.NavMesh.GetAreaFromName("residential")
                                                  | 1 << UnityEngine.AI.NavMesh.GetAreaFromName("cycleway") | 1 << UnityEngine.AI.NavMesh.GetAreaFromName("Pedestrian")
                                                  | 1 << UnityEngine.AI.NavMesh.GetAreaFromName("step") | 1 << UnityEngine.AI.NavMesh.GetAreaFromName("TrafficRoads")
                                                  | 1 << UnityEngine.AI.NavMesh.GetAreaFromName("Walkable"));

            point = hit.position;

            spawningPoints[i] = point;

            //Visualize the spawner
            var spawner = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
            spawner.transform.parent     = this.transform;
            spawner.transform.localScale = new Vector3(2f, 0.1f, 2f);

            spawner.gameObject.name = "SpawningPoint" + i;

            if (spawningMaterial != null)
            {
                spawner.GetComponent <MeshRenderer>().material = spawningMaterial;
            }

            if (!visualizeSpawners)
            {
                spawner.GetComponent <MeshRenderer>().enabled = false;
            }

            spawner.transform.position = point;
        }

        //Debug.Log(this.gameObject.name +  " has found " + stationsNearThisSpawner.Length
        //    + " stations nearby");

        // Get the itinerary controller
        flashInformer = FindObjectOfType <FlashPedestriansInformer>();

        // Get the destinations
        destinations = FindObjectsOfType <FlashPedestriansDestination>();
    }