public override void OnInspectorGUI() { DrawDefaultInspector(); PedestrianKTHKnowledge script = (PedestrianKTHKnowledge)target; if (GUILayout.Button("Print current knowledge")) { script.PrintKnowledge(); } }
/// <summary> /// Initializes the script. /// </summary> /// /// public override void Init() { steering = gameObject.GetComponent <PedestrianKTHSteering>(); knowledge = gameObject.GetComponent <PedestrianKTHKnowledge>(); pedestrianCache = gameObject.transform.parent.GetComponent <PedestrianKTHSpawner>().pedestrianCache; floatingBalloon = transform.FindChild("ThinkingBalloon"); onStateEnterEvent += onStateEnter; onStateExitEvent += onStateExit; onStateStayEvent += onStateStay; InvokeRepeating("CheckMyKnowledge", 1, 1); }
/// <summary> /// Auxiliar private method. Spawns a pedestrian in the given spawning point. /// </summary> /// <param name="spawningPoint">Vector3 that determines the spawning point.</param> private void SpawnPedestrian(Vector3 spawningPoint) { GameObject newAgent; if (pedestrianCache.Count > 0) { newAgent = (GameObject)pedestrianCache.Dequeue(); newAgent.transform.position = spawningPoint; newAgent.GetComponent <PedestrianKTHController>().Reset(); } else { if (spawnOnlyDefaultModel) { newAgent = (GameObject)Instantiate(pedestrianObjects[0], spawningPoint, Quaternion.identity); } else { newAgent = (GameObject)Instantiate(pedestrianObjects[Random.Range(1, pedestrianObjects.Length)], spawningPoint, Quaternion.identity); } newAgent.transform.SetParent(this.transform, true); newAgent.name = "student" + NumberOfPedestriansGenerated; } PedestrianKTHKnowledge pedKnowledge = newAgent.GetComponent <PedestrianKTHKnowledge>(); PedestrianKTHSteering pedSteering = newAgent.GetComponent <PedestrianKTHSteering>(); //Customize the parameters of the pedestrian according to the global variances pedKnowledge.studyInterest = Random.Range(0.5f - (studyInterestVariability / 2.0f), 0.5f + (studyInterestVariability / 2.0f)); pedKnowledge.delayTolerance = Random.Range(0.5f - (delayToleranceVariability / 2.0f), 0.5f + (delayToleranceVariability / 2.0f)); pedKnowledge.rumourSusceptibility = Random.Range(0.5f - (rumourSusceptibilityVariability / 2.0f), 0.5f + (rumourSusceptibilityVariability / 2.0f)); pedKnowledge.suscribedToModeDB = Random.value <= subscriptionProbability; pedSteering.speedVariation = Random.Range(0.5f - (speedVariability / 2.0f), 0.5f + (speedVariability / 2.0f)); //According to o/d matrix data (TODO := automatize this with parameters) float modeChoice = Random.value; //modeChoice = 2; //Walk if (modeChoice < 0.1128) { pedKnowledge.mode = 0; pedKnowledge.animationStateName = "Walk"; } //Bicycle else if (modeChoice < 0.1402) { pedKnowledge.mode = 3; newAgent.transform.FindChild("bike").gameObject.SetActive(true); pedKnowledge.animationStateName = "Bicycle"; } //Public transport else { if (Random.value < 0.5) { pedKnowledge.mode = 1; pedKnowledge.animationStateName = "Bus"; } else { pedKnowledge.mode = 2; pedKnowledge.animationStateName = "Metro"; } } newAgent.SetActive(true); if (NumberOfPedestriansGenerated++ >= numberOfPedestrians) { CancelInvoke(); } }