using UnityEngine;
namespace Unity.MLAgents.Sensors
{
///
/// A SensorComponent that creates a .
///
[AddComponentMenu("ML Agents/Buffer Sensor", (int)MenuGroup.Sensors)]
public class BufferSensorComponent : 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 = "BufferSensor";
///
/// This is how many floats each entities will be represented with. This number
/// is fixed and all entities must have the same representation.
///
public int ObservableSize
{
get { return m_ObservableSize; }
set { m_ObservableSize = value; }
}
[HideInInspector, SerializeField]
private int m_ObservableSize;
///
/// This is the maximum number of entities the `BufferSensor` will be able to
/// collect.
///
public int MaxNumObservables
{
get { return m_MaxNumObservables; }
set { m_MaxNumObservables = value; }
}
[HideInInspector, SerializeField]
private int m_MaxNumObservables;
private BufferSensor m_Sensor;
///
public override ISensor CreateSensor()
{
m_Sensor = new BufferSensor(MaxNumObservables, ObservableSize, m_SensorName);
return m_Sensor;
}
///
public override int[] GetObservationShape()
{
return new[] { MaxNumObservables, ObservableSize };
}
///
/// Appends an observation to the buffer. If the buffer is full (maximum number
/// of observation is reached) the observation will be ignored. the length of
/// the provided observation array must be equal to the observation size of
/// the buffer sensor.
///
/// The float array observation
public void AppendObservation(float[] obs)
{
m_Sensor.AppendObservation(obs);
}
}
}