/// <summary>
 /// Unsubscribes a pedestrian from the informer system.
 /// </summary>
 /// <param name="ped">Pedestrian to unsubscribe.</param>
 public void UnsuscribePedestrian(FlashPedestriansController ped)
 {
     if (activePedestrians.ContainsKey(ped.uniqueId))
     {
         activePedestrians.Remove(ped.uniqueId);
     }
 }
Exemplo n.º 2
0
    /// <summary>
    /// Spawns a Flash Pedestrian given its profile and its routing objects.
    /// </summary>
    /// <param name="profile">Profile object that will be used by the pedestrian.</param>
    /// <param name="routing">Routing object that will be used by the pedestrian.</param>
    private void SpawnPedestrian(Vector3 spawningPoint, FlashPedestriansProfile profile, FlashPedestriansDestination destination, Itinerary itinerary)
    {
        GameObject newAgent;

        spawningPoint += new Vector3(Random.Range(-1.0f, 1.0f), 0.0f, Random.Range(-1.0f, 1.0f));

        if (pedestrianCache.Count > 0)
        {
            newAgent = (GameObject)pedestrianCache.Dequeue();
            newAgent.transform.position = spawningPoint;
        }
        else
        {
            newAgent = Instantiate(pedGlobalParameters.pedestrianObject, spawningPoint, Quaternion.identity) as GameObject;
            newAgent.transform.SetParent(this.transform, true);
        }

        if (pedGlobalParameters.rumoursEnabled || pedGlobalParameters.bikesEnabled)
        {
            BoxCollider col = newAgent.GetComponent <BoxCollider>();

            if (col != null)
            {
                col.enabled = true;
            }
            else
            {
                newAgent.AddComponent <BoxCollider>();
            }
        }

        FlashPedestriansController controller = newAgent.GetComponent <FlashPedestriansController>();

        controller.uniqueId      = nextIdForPedestrian++;
        controller.profile       = profile;
        controller.routing       = new FlashPedestriansRouting(destination, itinerary);
        controller.flashInformer = flashInformer;

        // Subscribe pedestrian to the itinerary informer
        flashInformer.SubscribePedestrian(controller);

        newAgent.name = "flashPedestrian_" + this.name + "_" + "_" + controller.uniqueId;

        newAgent.SetActive(true);

        // Atomic increment of the KPI property
        Interlocked.Increment(ref pedGlobalParameters.numberOfPedestriansOnScenario);

        if (++numberOfPedestriansGenerated >= maxNumberOfPedestriansToSpawn && !spawnPedestriansInInfiniteLoop)
        {
            CancelInvoke();
        }
    }
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        FlashPedestriansController fpc = animator.GetComponent <FlashPedestriansController>();

        if (fpc.targetedBikeStation.capacityNumber > 0)
        {
            fpc.targetedBikeStation.PickBike();
            fpc.GoBikingToDestination();
        }
        else
        {
            fpc.BikeStationIsEmpty();
        }
    }
 /// <summary>
 /// Subscribes a pedestrian into the informer system.
 /// </summary>
 /// <param name="ped">Pedestrian to subscribe.</param>
 public void SubscribePedestrian(FlashPedestriansController ped)
 {
     activePedestrians.Add(ped.uniqueId, ped);
 }