/// <inheritdoc/>
        public override GameObject GetModelInstance(SourceVariant variant)
        {
            var instance  = base.GetModelInstance(variant);
            var colliders = instance.GetComponentsInChildren <Collider>();

            foreach (var collider in colliders)
            {
                collider.isTrigger = true;
            }

            //Destroy all the custom components from the ego vehicle
            var allComponents = instance.GetComponents <MonoBehaviour>();

            for (var i = 0; i < allComponents.Length; i++)
            {
                var component = allComponents[i];
                DestroyImmediate(component);
            }

            var rigidbody = instance.GetComponent <Rigidbody>();

            rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
            rigidbody.isKinematic            = true;
            return(instance);
        }
        /// <inheritdoc/>
        public override GameObject GetModelInstance(SourceVariant variant)
        {
            var instance = variant.Prefab != null
                ? base.GetModelInstance(variant)
                : ScenarioManager.Instance.prefabsPools.GetInstance(defaultRendererPrefab);

            ((EgoAgentVariant)variant).AddRequiredComponents(instance, defaultRendererPrefab);
            var colliders = instance.GetComponentsInChildren <Collider>();

            foreach (var collider in colliders)
            {
                collider.isTrigger = true;
            }

            var agent = instance.GetComponent <IAgentController>();

            agent?.DisableControl();

            //Destroy all the custom components from the ego vehicle
            var allComponents = instance.GetComponents <MonoBehaviour>();

            for (var i = 0; i < allComponents.Length; i++)
            {
                var component = allComponents[i];
                DestroyImmediate(component);
            }
            return(instance);
        }
        /// <inheritdoc/>
        public override GameObject GetModelInstance(SourceVariant variant)
        {
            var instance = base.GetModelInstance(variant);

            if (instance.GetComponent <BoxCollider>() == null)
            {
                var collider = instance.AddComponent <BoxCollider>();
                collider.isTrigger = true;
                var b = new Bounds(instance.transform.position, Vector3.zero);
                foreach (Renderer r in instance.GetComponentsInChildren <Renderer>())
                {
                    b.Encapsulate(r.bounds);
                }
                collider.center = b.center - instance.transform.position;
                //Limit collider size
                b.size        = new Vector3(Mathf.Clamp(b.size.x, 0.1f, 0.5f), b.size.y, Mathf.Clamp(b.size.z, 0.1f, 0.5f));
                collider.size = b.size;
            }

            if (instance.GetComponent <Rigidbody>() == null)
            {
                var rigidbody = instance.AddComponent <Rigidbody>();
                rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
                rigidbody.isKinematic            = true;
            }

            return(instance);
        }
        /// <inheritdoc/>
        public override GameObject GetModelInstance(SourceVariant variant)
        {
            var instance = base.GetModelInstance(variant);

            if (instance == null)
            {
                ScenarioManager.Instance.logPanel.EnqueueError($"Could not instantiate a prefab for the {variant.Name} NPC variant.");
                return(null);
            }
            if (instance.GetComponent <BoxCollider>() == null)
            {
                var collider = instance.AddComponent <BoxCollider>();
                collider.isTrigger = true;
                var b = new Bounds(instance.transform.position, Vector3.zero);
                foreach (Renderer r in instance.GetComponentsInChildren <Renderer>())
                {
                    b.Encapsulate(r.bounds);
                }
                collider.center = b.center - instance.transform.position;
                collider.size   = b.size;
            }

            // Set/Add limited rigidbody
            var rigidbody = instance.GetComponent <Rigidbody>();

            if (rigidbody == null)
            {
                rigidbody = instance.AddComponent <Rigidbody>();
            }
            rigidbody.interpolation          = RigidbodyInterpolation.None;
            rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
            rigidbody.isKinematic            = true;

            return(instance);
        }
Exemple #5
0
        /// <inheritdoc/>
        public override ScenarioElement GetElementInstance(SourceVariant 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);
        }
Exemple #6
0
 /// <inheritdoc/>
 public override void OnVariantSelected(SourceVariant variant)
 {
     selectedVariant = variant as AgentVariant;
     if (selectedVariant != null)
     {
         DragNewAgent();
     }
 }
        /// <inheritdoc/>
        public override ScenarioElement GetElementInstance(SourceVariant variant)
        {
            var newGameObject = new GameObject(ElementTypeName);

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

            scenarioAgent.Setup(this, variant);
            scenarioAgent.GetOrAddExtension <AgentWaypointsPath>();
            return(scenarioAgent);
        }
Exemple #8
0
        /// <inheritdoc/>
        public override GameObject GetModelInstance(SourceVariant variant)
        {
            var instance = variant.Prefab != null
                ? base.GetModelInstance(variant)
                : ScenarioManager.Instance.prefabsPools.GetInstance(defaultRendererPrefab);

            ((EgoAgentVariant)variant).AddRequiredComponents(instance, defaultRendererPrefab);
            var colliders = instance.GetComponentsInChildren <Collider>();

            foreach (var collider in colliders)
            {
                collider.isTrigger = true;
            }

            var agent = instance.GetComponent <IAgentController>();

            agent?.DisableControl();

            // Destroy all the custom components from the ego vehicle
            var allComponents = instance.GetComponents <MonoBehaviour>();

            for (var i = 0; i < allComponents.Length; i++)
            {
                var component = allComponents[i];
                DestroyImmediate(component);
            }

            // Set/Add limited rigidbody
            var rigidbody = instance.GetComponent <Rigidbody>();

            if (rigidbody == null)
            {
                rigidbody = instance.AddComponent <Rigidbody>();
            }
            rigidbody.interpolation          = RigidbodyInterpolation.None;
            rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
            rigidbody.isKinematic            = true;
            return(instance);
        }