/// <summary>
        /// Method called when another scenario element has been selected
        /// </summary>
        /// <param name="previousElement">Scenario element that has been deselected</param>
        /// <param name="selectedElement">Scenario element that has been selected</param>
        private void OnSelectedOtherElement(ScenarioElement previousElement, ScenarioElement selectedElement)
        {
            //Detach from current agent events
            if (destinationPointExtension != null && selectedAgent == previousElement)
            {
                //Hide destination point if something else than the destination point is selected
                if (!(selectedElement is ScenarioDestinationPoint ||
                      selectedElement is ScenarioDestinationPointWaypoint) &&
                    destinationPointExtension.DestinationPoint != null)
                {
                    destinationPointExtension.DestinationPoint.SetVisibility(false);
                }
                destinationPointExtension = null;
            }

            selectedAgent = selectedElement as ScenarioAgent;
            //Attach to selected agent events
            if (selectedAgent != null)
            {
                destinationPointExtension = selectedAgent.GetExtension <AgentDestinationPoint>();
                if (destinationPointExtension == null)
                {
                    Hide();
                }
                else
                {
                    Show();
                }
            }
            else
            {
                Hide();
            }
        }
Example #2
0
        /// <summary>
        /// Method called when another scenario element has been selected
        /// </summary>
        /// <param name="selectedElement">Scenario element that has been selected</param>
        private void OnSelectedOtherElement(ScenarioElement selectedElement)
        {
            //Detach from current agent events
            if (selectedAgent != null)
            {
                //Hide destination point if agent is deselected and something else is selected
                if (destinationPointExtension != null && selectedElement != destinationPointExtension.DestinationPoint)
                {
                    destinationPointExtension.DestinationPoint.SetVisibility(false);
                }
            }

            selectedAgent = selectedElement as ScenarioAgent;
            //Attach to selected agent events
            if (selectedAgent != null)
            {
                destinationPointExtension = selectedAgent.GetExtension <AgentDestinationPoint>();
                if (destinationPointExtension == null)
                {
                    Hide();
                }
                else
                {
                    Show();
                }
            }
            else
            {
                Hide();
            }
        }
Example #3
0
        /// <summary>
        /// Method called when another scenario element has been selected
        /// </summary>
        /// <param name="selectedElement">Scenario element that has been selected</param>
        private void OnSelectedOtherElement(ScenarioElement selectedElement)
        {
            //Detach from current agent events
            if (behaviourExtension != null)
            {
                behaviourExtension.BehaviourChanged -= BehaviourExtensionOnBehaviourChanged;
            }

            selectedAgent = selectedElement as ScenarioAgent;
            //Attach to selected agent events
            if (selectedAgent != null)
            {
                behaviourExtension = selectedAgent.GetExtension <AgentBehaviour>();
                if (behaviourExtension == null)
                {
                    Hide();
                }
                else
                {
                    behaviourExtension.BehaviourChanged += BehaviourExtensionOnBehaviourChanged;
                    Show();
                }
            }
            else
            {
                Hide();
            }
        }
            /// <summary>
            /// Recalculates the agent path that will be traversed
            /// </summary>
            private void RecalculatePath()
            {
                pathPositions.Clear();
                pathArrivals.Clear();
                var previousPosition = agent.TransformForPlayback.position;

                pathPositions.Add(previousPosition);
                var arrival = 0.0f;

                pathArrivals.Add(arrival);
                var waypointsExtension = agent.GetExtension <AgentWaypoints>();

                if (waypointsExtension != null)
                {
                    for (var i = 0; i < waypointsExtension.Waypoints.Count; i++)
                    {
                        var waypoint = waypointsExtension.Waypoints[i];
                        var speed    = waypoint.Speed;
                        //Agent won't move further after stopping
                        if (speed <= 0.0f)
                        {
                            break;
                        }
                        var position = waypoint.transform.position;
                        pathPositions.Add(position);
                        var distance = Vector3.Distance(previousPosition, position);
                        arrival += distance / speed;
                        pathArrivals.Add(arrival);
                        previousPosition = position;
                    }
                }

                duration = pathArrivals[pathArrivals.Count - 1];
            }
Example #5
0
        /// <summary>
        /// Method called when another scenario element has been selected
        /// </summary>
        /// <param name="previousElement">Scenario element that has been deselected</param>
        /// <param name="selectedElement">Scenario element that has been selected</param>
        private void OnSelectedOtherElement(ScenarioElement previousElement, ScenarioElement selectedElement)
        {
            //Detach from current agent events
            if (colorExtension != null)
            {
                colorExtension.ColorChanged -= SelectedAgentOnColorChanged;
            }

            selectedAgent = selectedElement as ScenarioAgent;
            //Attach to selected agent events
            if (selectedAgent != null)
            {
                colorExtension = selectedAgent.GetExtension <AgentColorExtension>();
                if (colorExtension == null)
                {
                    Hide();
                }
                else
                {
                    colorExtension.ColorChanged += SelectedAgentOnColorChanged;
                    Show();
                }
            }
            else
            {
                Hide();
            }
        }
        /// <summary>
        /// Method called when another scenario element has been selected
        /// </summary>
        /// <param name="selectedElement">Scenario element that has been selected</param>
        private void OnSelectedOtherElement(ScenarioElement selectedElement)
        {
            //Detach from current agent events
            if (selectedAgent != null)
            {
                selectedAgent.VariantChanged -= SelectedAgentOnVariantChanged;
                if (sensorsConfiguration != null)
                {
                    sensorsConfiguration.SensorsConfigurationIdChanged -= SelectedAgentOnSensorsConfigurationIdChanged;
                }
            }

            selectedAgent = selectedElement as ScenarioAgent;
            //Attach to selected agent events
            if (selectedAgent != null)
            {
                sensorsConfiguration = selectedAgent.GetExtension <AgentSensorsConfiguration>();
                if (sensorsConfiguration == null)
                {
                    Hide();
                }
                else
                {
                    selectedAgent.VariantChanged += SelectedAgentOnVariantChanged;
                    sensorsConfiguration.SensorsConfigurationIdChanged += SelectedAgentOnSensorsConfigurationIdChanged;
                    Show();
                }
            }
            else
            {
                Hide();
            }
        }
        /// <summary>
        /// Method called when another scenario element has been selected
        /// </summary>
        /// <param name="selectedElement">Scenario element that has been selected</param>
        private void OnSelectedOtherElement(ScenarioElement selectedElement)
        {
            if (agentWaypoints != null)
            {
                agentWaypoints.IsActiveChanged -= AgentWaypointsOnIsActiveChanged;
            }

            selectedAgent = selectedElement as ScenarioAgent;
            //Attach to selected agent events
            if (selectedAgent != null)
            {
                agentWaypoints = selectedAgent.GetExtension <AgentWaypoints>();
                if (agentWaypoints == null)
                {
                    Hide();
                }
                else
                {
                    agentWaypoints.IsActiveChanged += AgentWaypointsOnIsActiveChanged;
                    Show();
                }
            }
            else
            {
                Hide();
            }
        }
Example #8
0
        /// <inheritdoc/>
        public override void Initialize(ScenarioElement parentElement)
        {
            base.Initialize(parentElement);
            ParentAgent = (ScenarioAgent)parentElement;
            SetStartEndElements(parentElement, null);
            ParentAgent.ExtensionAdded   += ParentAgentOnExtensionAdded;
            ParentAgent.ExtensionRemoved += ParentAgentOnExtensionRemoved;
            var behaviourExtension = ParentAgent.GetExtension <AgentBehaviour>();

            if (behaviourExtension != null)
            {
                behaviourExtension.BehaviourChanged += ParentAgentOnBehaviourChanged;
            }
        }
        /// <summary>
        /// Attach this destination point to the agent
        /// </summary>
        /// <param name="agent">Scenario agent to which destination point will be attached</param>
        /// <param name="initializeTransform">Should this attach initialize the transform</param>
        public void AttachToAgent(ScenarioAgent agent, bool initializeTransform)
        {
            ParentAgent = agent;
            PlaybackPath.Initialize(this);
            var extension = agent.GetExtension <AgentDestinationPoint>();

            extension.SetDestinationPoint(this);
            if (!initializeTransform)
            {
                return;
            }
            transform.SetParent(agent.transform);
            var forward = agent.TransformToMove.forward;

            TransformToMove.localPosition   = forward * InitialOffset;
            TransformToRotate.localRotation = Quaternion.LookRotation(forward);
            Refresh();
        }
Example #10
0
        /// <summary>
        /// Method called when another scenario element has been selected
        /// </summary>
        /// <param name="previousElement">Scenario element that has been deselected</param>
        /// <param name="selectedElement">Scenario element that has been selected</param>
        private void OnSelectedOtherElement(ScenarioElement previousElement, ScenarioElement selectedElement)
        {
            //Detach from current agent events
            if (behaviourExtension != null)
            {
                behaviourExtension.BehaviourChanged -= SelectedAgentOnBehaviourChanged;
                Hide();
            }

            selectedAgent      = selectedElement as ScenarioAgent;
            behaviourExtension = selectedAgent == null ? null : selectedAgent.GetExtension <AgentBehaviour>();
            //Attach to selected agent events
            if (behaviourExtension != null)
            {
                behaviourExtension.BehaviourChanged += SelectedAgentOnBehaviourChanged;
                Show();
            }
            SelectedAgentOnBehaviourChanged(behaviourExtension == null ? "" : behaviourExtension.Behaviour);
        }
        /// <summary>
        /// Method called when another scenario element has been selected
        /// </summary>
        /// <param name="previousElement">Scenario element that has been deselected</param>
        /// <param name="selectedElement">Scenario element that has been selected</param>
        private void OnSelectedOtherElement(ScenarioElement previousElement, ScenarioElement selectedElement)
        {
            if (isAddingWaypoints)
            {
                ScenarioManager.Instance.GetExtension <InputManager>().CancelAddingElements(this);
            }

            //Force input apply on deselect
            if (selectedWaypoint != null)
            {
                SubmitChangedInputs();
            }
            selectedWaypoint           = selectedElement as ScenarioAgentWaypoint;
            selectedAgent              = selectedWaypoint != null ? (ScenarioAgent)selectedWaypoint.ParentElement : null;
            selectedAgentWaypointsPath =
                selectedAgent == null ? null : selectedAgent.GetExtension <AgentWaypointsPath>();
            //Disable waypoints for ego vehicles
            if (selectedAgent == null || selectedAgentWaypointsPath == null ||
                !selectedAgent.Source.AgentSupportWaypoints(selectedAgent))
            {
                gameObject.SetActive(false);
            }
            else
            {
                gameObject.SetActive(true);
                speedPanel.SetActive(selectedWaypoint != null);
                accelerationPanel.SetActive(selectedWaypoint != null);
                waitTimePanel.SetActive(selectedWaypoint != null);
                if (selectedWaypoint != null)
                {
                    speedInput.CurrentContext = selectedWaypoint;
                    speedInput.ExternalValueChange(selectedWaypoint.DestinationSpeed, selectedWaypoint, false);
                    accelerationInput.CurrentContext = selectedWaypoint;
                    accelerationInput.ExternalValueChange(selectedWaypoint.Acceleration, selectedWaypoint, false);
                    waitTimeInput.text = selectedWaypoint.WaitTime.ToString("F");
                }

                triggerEditPanel.OnSelectedNewTrigger(selectedWaypoint.LinkedTrigger);
                UnityUtilities.LayoutRebuild(transform as RectTransform);
            }
        }
Example #12
0
        /// <inheritdoc/>
        public override bool AgentSupportWaypoints(ScenarioAgent agent)
        {
            var behaviourExtension = agent.GetExtension <AgentBehaviour>();

            return(behaviourExtension != null && behaviourExtension.Behaviour == nameof(NPCWaypointBehaviour));
        }