public override ISensor CreateSensor()
        {
            var rayAngles = GetRayAngles(raysPerDirection, maxRayDegrees);

            var rayPerceptionInput = new RayPerceptionInput();

            rayPerceptionInput.rayLength      = rayLength;
            rayPerceptionInput.detectableTags = detectableTags;
            rayPerceptionInput.angles         = rayAngles;
            rayPerceptionInput.startOffset    = GetStartVerticalOffset();
            rayPerceptionInput.endOffset      = GetEndVerticalOffset();
            rayPerceptionInput.castRadius     = sphereCastRadius;
            rayPerceptionInput.transform      = transform;
            rayPerceptionInput.castType       = GetCastType();
            rayPerceptionInput.layerMask      = rayLayerMask;

            m_RaySensor = new RayPerceptionSensor(sensorName, rayPerceptionInput);

            if (observationStacks != 1)
            {
                var stackingSensor = new StackingSensor(m_RaySensor, observationStacks);
                return(stackingSensor);
            }

            return(m_RaySensor);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Set up the list of ISensors on the Agent. By default, this will select any
        /// SensorBase's attached to the Agent.
        /// </summary>
        public void InitializeSensors()
        {
            // Get all attached sensor components
            SensorComponent[] attachedSensorComponents;
            if (m_PolicyFactory.useChildSensors)
            {
                attachedSensorComponents = GetComponentsInChildren <SensorComponent>();
            }
            else
            {
                attachedSensorComponents = GetComponents <SensorComponent>();
            }

            sensors.Capacity += attachedSensorComponents.Length;
            foreach (var component in attachedSensorComponents)
            {
                sensors.Add(component.CreateSensor());
            }

            // Support legacy CollectObservations
            var param = m_PolicyFactory.brainParameters;

            if (param.vectorObservationSize > 0)
            {
                collectObservationsSensor = new VectorSensor(param.vectorObservationSize);
                if (param.numStackedVectorObservations > 1)
                {
                    var stackingSensor = new StackingSensor(collectObservationsSensor, param.numStackedVectorObservations);
                    sensors.Add(stackingSensor);
                }
                else
                {
                    sensors.Add(collectObservationsSensor);
                }
            }

            // Sort the Sensors by name to ensure determinism
            sensors.Sort((x, y) => x.GetName().CompareTo(y.GetName()));

#if DEBUG
            // Make sure the names are actually unique
            for (var i = 0; i < sensors.Count - 1; i++)
            {
                Debug.Assert(!sensors[i].GetName().Equals(sensors[i + 1].GetName()), "Sensor names must be unique.");
            }
#endif
            // Create a buffer for writing vector sensor data too
            int numFloatObservations = 0;
            for (var i = 0; i < sensors.Count; i++)
            {
                if (sensors[i].GetCompressionType() == SensorCompressionType.None)
                {
                    numFloatObservations += sensors[i].ObservationSize();
                }
            }

            m_VectorSensorBuffer = new float[numFloatObservations];
        }
        public override ISensor CreateSensor()
        {
            var rayAngles = GetRayAngles(raysPerDirection, maxRayDegrees);

            m_RaySensor = new RayPerceptionSensor(sensorName, rayLength, detectableTags, rayAngles,
                                                  transform, GetStartVerticalOffset(), GetEndVerticalOffset(), sphereCastRadius, GetCastType(),
                                                  rayLayerMask
                                                  );

            if (observationStacks != 1)
            {
                var stackingSensor = new StackingSensor(m_RaySensor, observationStacks);
                return(stackingSensor);
            }

            return(m_RaySensor);
        }