using UnityEngine; namespace Unity.MLAgents.Sensors { /// /// Grid-based sensor with one-hot observations. /// public class OneHotGridSensor : GridSensorBase { /// /// Create a OneHotGridSensor with the specified configuration. /// /// The sensor name /// The scale of each cell in the grid /// Number of cells on each side of the grid /// Tags to be detected by the sensor /// Compression type public OneHotGridSensor( string name, Vector3 cellScale, Vector3Int gridSize, string[] detectableTags, SensorCompressionType compression ) : base(name, cellScale, gridSize, detectableTags, compression) { } /// protected override int GetCellObservationSize() { return DetectableTags == null ? 0 : DetectableTags.Length; } /// protected override bool IsDataNormalized() { return true; } /// protected internal override ProcessCollidersMethod GetProcessCollidersMethod() { return ProcessCollidersMethod.ProcessClosestColliders; } /// /// Get the one-hot representation of the detected game object's tag. /// /// The game object that was detected within a certain cell /// The index of the detectedObject's tag in the DetectableObjects list /// The buffer to write the observation values. /// The buffer size is configured by . /// protected override void GetObjectData(GameObject detectedObject, int tagIndex, float[] dataBuffer) { dataBuffer[tagIndex] = 1; } } }