/// <inheritdoc/> void IAddElementsHandler.AddingStarted(Vector3 addPosition) { var mapWaypointPrefab = ScenarioManager.Instance.GetExtension <ScenarioWaypointsManager>().waypointPrefab; newWaypointInstance = ScenarioManager.Instance.prefabsPools .GetInstance(mapWaypointPrefab).GetComponent <ScenarioWaypoint>(); if (newWaypointInstance == null) { Debug.LogWarning( $"Cannot add waypoints. Add {nameof(ScenarioWaypoint)} component to the prefab."); ScenarioManager.Instance.GetExtension <InputManager>().CancelAddingElements(this); return; } newWaypointInstance.ForceMove(addPosition); agentWaypoints.AddWaypoint(newWaypointInstance, true); isAddingWaypoints = true; }
/// <inheritdoc/> void IAddElementsHandler.AddingStarted(Vector3 addPosition) { if (selectedAgent == null) { Debug.LogWarning("Cannot add waypoints if no agent or waypoint is selected."); ScenarioManager.Instance.GetExtension <InputManager>().CancelAddingElements(this); return; } isAddingWaypoints = true; var mapWaypointPrefab = ScenarioManager.Instance.GetExtension <ScenarioWaypointsManager>().waypointPrefab; waypointInstance = ScenarioManager.Instance.prefabsPools.GetInstance(mapWaypointPrefab) .GetComponent <ScenarioWaypoint>(); if (waypointInstance == null) { Debug.LogWarning("Cannot add waypoints. Add waypoint component to the prefab."); ScenarioManager.Instance.GetExtension <InputManager>().CancelAddingElements(this); ScenarioManager.Instance.prefabsPools.ReturnInstance(waypointInstance.gameObject); return; } waypointInstance.transform.position = addPosition; var mapManager = ScenarioManager.Instance.GetExtension <ScenarioMapManager>(); switch (selectedAgent.Type) { case AgentType.Ego: case AgentType.Npc: mapManager.LaneSnapping.SnapToLane(LaneSnappingHandler.LaneType.Traffic, waypointInstance.transform); break; case AgentType.Pedestrian: mapManager.LaneSnapping.SnapToLane(LaneSnappingHandler.LaneType.Pedestrian, waypointInstance.transform); break; } selectedAgentWaypoints.AddWaypoint(waypointInstance, true, selectedWaypoint); }