public SimpleTestGridSensor( string name, Vector3 cellScale, Vector3Int gridNumSide, bool rotateWithAgent, int[] channelDepth, string[] detectableObjects, LayerMask observeMask, GridDepthType depthType, GameObject root, SensorCompressionType compression, int maxColliderBufferSize, int initialColliderBufferSize ) : base( name, cellScale, gridNumSide, rotateWithAgent, channelDepth, detectableObjects, observeMask, depthType, root, compression, maxColliderBufferSize, initialColliderBufferSize) { }
/// <summary> /// Sets the parameters of the grid sensor /// </summary> /// <param name="detectableObjects">array of strings representing the tags to be detected by the sensor</param> /// <param name="channelDepth">array of ints representing the depth of each channel</param> /// <param name="gridDepthType">enum representing the GridDepthType of the sensor</param> /// <param name="cellScaleX">float representing the X scaling of each cell</param> /// <param name="cellScaleZ">float representing the Z scaling of each cell</param> /// <param name="gridWidth">int representing the number of cells in the X direction. Width of the Grid</param> /// <param name="gridHeight">int representing the number of cells in the Z direction. Height of the Grid</param> /// <param name="observeMaskInt">int representing the layer mask to observe</param> /// <param name="rotateToAgent">bool if true then the grid is rotated to the rotation of the transform the rootReference</param> /// <param name="debugColors">array of colors corresponding the the tags in the detectableObjects array</param> public virtual void SetParameters(string[] detectableObjects, int[] channelDepth, GridDepthType gridDepthType, float cellScaleX, float cellScaleZ, int gridWidth, int gridHeight, int observeMaskInt, bool rotateToAgent, Color[] debugColors) { this.ObserveMask = observeMaskInt; this.DetectableObjects = detectableObjects; this.ChannelDepth = channelDepth; this.gridDepthType = gridDepthType; this.CellScaleX = cellScaleX; this.CellScaleZ = cellScaleZ; this.GridNumSideX = gridWidth; this.GridNumSideZ = gridHeight; this.RotateToAgent = rotateToAgent; this.DiffNumSideZX = (GridNumSideZ - GridNumSideX); this.OffsetGridNumSide = (GridNumSideZ - 1f) / 2f; this.DebugColors = debugColors; }
public GridSensor( string name, Vector3 cellScale, Vector3Int gridNum, bool rotateWithAgent, int[] channelDepths, string[] detectableObjects, LayerMask colliderMask, GridDepthType depthType, GameObject rootReference, SensorCompressionType compression, int maxColliderBufferSize, int initialColliderBufferSize ) { m_Name = name; m_CellScale = cellScale; m_GridSize = gridNum; m_RotateWithAgent = rotateWithAgent; m_RootReference = rootReference; m_MaxColliderBufferSize = maxColliderBufferSize; m_InitialColliderBufferSize = initialColliderBufferSize; m_ColliderMask = colliderMask; m_GridDepthType = depthType; m_ChannelDepths = channelDepths; m_DetectableObjects = detectableObjects; m_CompressionType = compression; if (m_GridSize.y != 1) { throw new UnityAgentsException("GridSensor only supports 2D grids."); } if (m_GridDepthType == GridDepthType.Counting && m_DetectableObjects.Length != m_ChannelDepths.Length) { throw new UnityAgentsException("The channels of a CountingGridSensor is equal to the number of detectableObjects"); } InitGridParameters(); InitDepthType(); InitCellPoints(); ResetPerceptionBuffer(); m_ObservationSpec = ObservationSpec.Visual(m_GridSize.x, m_GridSize.z, m_CellObservationSize); m_PerceptionTexture = new Texture2D(m_GridSize.x, m_GridSize.z, TextureFormat.RGB24, false); m_ColliderBuffer = new Collider[Math.Min(m_MaxColliderBufferSize, m_InitialColliderBufferSize)]; }
/// <inheritdoc/> public override void SetParameters(string[] detectableObjects, int[] channelDepth, GridDepthType gridDepthType, float cellScaleX, float cellScaleZ, int gridWidth, int gridHeight, int observeMaskInt, bool rotateToAgent, Color[] debugColors) { this.ObserveMask = observeMaskInt; this.DetectableObjects = detectableObjects; this.ChannelDepth = channelDepth; if (DetectableObjects.Length != ChannelDepth.Length) { throw new UnityAgentsException("The channels of a CountingGridSensor is equal to the number of detectableObjects"); } this.gridDepthType = gridDepthType; this.CellScaleX = cellScaleX; this.CellScaleZ = cellScaleZ; this.GridNumSideX = gridWidth; this.GridNumSideZ = gridHeight; this.RotateToAgent = rotateToAgent; this.DiffNumSideZX = (GridNumSideZ - GridNumSideX); this.OffsetGridNumSide = (GridNumSideZ - 1f) / 2f; this.DebugColors = debugColors; }
public static void SetComponentParameters(GridSensorComponent gridComponent, string[] detectableObjects, int[] channelDepth, GridDepthType gridDepthType, float cellScaleX, float cellScaleZ, int gridWidth, int gridHeight, int colliderMaskInt, bool rotateWithAgent, Color[] debugColors) { gridComponent.DetectableObjects = detectableObjects; gridComponent.ChannelDepths = channelDepth; gridComponent.DepthType = gridDepthType; gridComponent.CellScale = new Vector3(cellScaleX, 0.01f, cellScaleZ); gridComponent.GridSize = new Vector3Int(gridWidth, 1, gridHeight); gridComponent.ColliderMask = colliderMaskInt; gridComponent.RotateWithAgent = rotateWithAgent; gridComponent.DebugColors = debugColors; }