using UnityEngine;
namespace Unity.MLAgents.Sensors
{
///
/// A SensorComponent that creates a .
///
[AddComponentMenu("ML Agents/Vector Sensor", (int)MenuGroup.Sensors)]
public class VectorSensorComponent : SensorComponent
{
///
/// Name of the generated object.
/// Note that changing this at runtime does not affect how the Agent sorts the sensors.
///
public string SensorName
{
get { return m_SensorName; }
set { m_SensorName = value; }
}
[HideInInspector, SerializeField]
private string m_SensorName = "VectorSensor";
///
/// The number of float observations in the VectorSensor
///
public int ObservationSize
{
get { return m_ObservationSize; }
set { m_ObservationSize = value; }
}
[HideInInspector, SerializeField]
int m_ObservationSize;
[HideInInspector, SerializeField]
ObservationType m_ObservationType;
VectorSensor m_Sensor;
///
/// The type of the observation.
///
public ObservationType ObservationType
{
get { return m_ObservationType; }
set { m_ObservationType = value; }
}
[HideInInspector, SerializeField]
[Range(1, 50)]
[Tooltip("Number of camera frames that will be stacked before being fed to the neural network.")]
int m_ObservationStacks = 1;
///
/// Whether to stack previous observations. Using 1 means no previous observations.
/// Note that changing this after the sensor is created has no effect.
///
public int ObservationStacks
{
get { return m_ObservationStacks; }
set { m_ObservationStacks = value; }
}
///
/// Creates a VectorSensor.
///
///
public override ISensor[] CreateSensors()
{
m_Sensor = new VectorSensor(m_ObservationSize, m_SensorName, m_ObservationType);
if (ObservationStacks != 1)
{
return new ISensor[] { new StackingSensor(m_Sensor, ObservationStacks) };
}
return new ISensor[] { m_Sensor };
}
///
/// Returns the underlying VectorSensor
///
///
public VectorSensor GetSensor()
{
return m_Sensor;
}
}
}