/// <inheritdoc/>
        public override ScenarioAgent GetAgentInstance(AgentVariant variant)
        {
            if (variant.Prefab == null)
            {
                Debug.LogWarning("Variant has to be prepared before getting it's instance.");
                return(null);
            }

            var agentsManager = ScenarioManager.Instance.GetExtension <ScenarioAgentsManager>();
            var newGameObject = new GameObject(ElementTypeName);

            newGameObject.transform.SetParent(transform);
            var scenarioAgent = newGameObject.AddComponent <ScenarioAgent>();

            scenarioAgent.Setup(this, variant);
            scenarioAgent.GetOrAddExtension <AgentSensorsConfiguration>();
            scenarioAgent.GetOrAddExtension <AgentDestinationPoint>();
            //Add destination point
            var destinationPointObject = ScenarioManager.Instance.prefabsPools
                                         .GetInstance(agentsManager.destinationPoint);
            var destinationPoint = destinationPointObject.GetComponent <ScenarioDestinationPoint>();

            destinationPoint.AttachToAgent(scenarioAgent, true);
            destinationPoint.SetActive(false);
            destinationPoint.SetVisibility(false);
            return(scenarioAgent);
        }
Esempio n. 2
0
        /// <inheritdoc/>
        public override Task Initialize(IProgress <float> progress)
        {
            inputManager = ScenarioManager.Instance.GetExtension <InputManager>();
            var npcVehiclesInSimulation = Config.NPCVehicles;
            var npcsCount = npcVehiclesInSimulation.Count;
            var i         = 0;

            foreach (var npcAssetData in npcVehiclesInSimulation)
            {
                var sb = new StringBuilder();
                Debug.Log($"Loading NPC {npcAssetData.Value.Name} from the config.");
                sb.Append("NPC type: ");
                sb.Append(npcAssetData.Value.NPCType);
                var npcVariant = new AgentVariant(this, npcAssetData.Value.Name, npcAssetData.Value.Prefab,
                                                  sb.ToString());
                Variants.Add(npcVariant);
                progress.Report((float)++i / npcsCount);
            }

            Behaviours = new List <string>();
            var npcsManager = ScenarioManager.Instance.GetExtension <ScenarioNPCsManager>();

            Behaviours.AddRange(npcsManager.AvailableBehaviourTypes.Select(t => t.Name));
            return(Task.CompletedTask);
        }
Esempio n. 3
0
 /// <inheritdoc/>
 public override void OnVariantSelected(SourceVariant variant)
 {
     selectedVariant = variant as AgentVariant;
     if (selectedVariant != null)
     {
         DragNewAgent();
     }
 }
        /// <inheritdoc/>
        public override ScenarioAgent GetAgentInstance(AgentVariant variant)
        {
            var newGameObject = new GameObject(ElementTypeName);

            newGameObject.transform.SetParent(transform);
            var scenarioAgent = newGameObject.AddComponent <ScenarioAgent>();

            scenarioAgent.GetOrAddExtension <AgentWaypoints>();
            scenarioAgent.Setup(this, variant);
            return(scenarioAgent);
        }
        /// <inheritdoc/>
        public override Task Initialize(IProgress <float> progress)
        {
            var pedestriansInSimulation = Config.Pedestrians;
            var i = 0;

            foreach (var pedestrian in pedestriansInSimulation)
            {
                Debug.Log($"Loading pedestrian {pedestrian.Value.Name} from the pedestrian manager.");
                var variant = new AgentVariant(this, pedestrian.Value.Name, pedestrian.Value.Prefab, string.Empty);
                Variants.Add(variant);
                progress.Report((float)(++i) / pedestriansInSimulation.Count);
            }

            return(Task.CompletedTask);
        }
        /// <inheritdoc/>
        public override Task Initialize(IProgress <float> progress)
        {
            inputManager = ScenarioManager.Instance.GetExtension <InputManager>();
            var pedestrianManager       = Loader.Instance.SimulatorManagerPrefab.pedestrianManagerPrefab;
            var pedestriansInSimulation = pedestrianManager.pedModels;

            for (var i = 0; i < pedestriansInSimulation.Count; i++)
            {
                var pedestrian = pedestriansInSimulation[i];
                Debug.Log($"Loading pedestrian {pedestrian.name} from the pedestrian manager.");
                var variant = new AgentVariant(this, pedestrian.name, pedestrian, string.Empty);
                Variants.Add(variant);
                progress.Report((float)(i + 1) / pedestriansInSimulation.Count);
            }
            return(Task.CompletedTask);
        }
Esempio n. 7
0
 /// <summary>
 /// Method that instantiates new <see cref="ScenarioAgent"/> and initializes it with selected variant
 /// </summary>
 /// <param name="variant">Agent variant which model should be instantiated</param>
 /// <returns><see cref="ScenarioAgent"/> initialized with selected variant</returns>
 public abstract ScenarioAgent GetAgentInstance(AgentVariant variant);