File size: 2,218 Bytes
05c9ac2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using UnityEngine;

namespace Unity.MLAgents.Sensors
{
    /// <summary>
    /// An interface for GridSensor perception that defines the grid cells and collider detecting strategies.
    /// </summary>
    internal interface IGridPerception
    {
        bool RotateWithAgent
        {
            get;
            set;
        }

        LayerMask ColliderMask
        {
            get;
            set;
        }

        /// <summary>Converts the index of the cell to the 3D point (y is zero) relative to grid center</summary>
        /// <returns>Vector3 of the position of the center of the cell relative to grid center</returns>
        /// <param name="cellIndex">The index of the cell</param>
        Vector3 GetCellLocalPosition(int cellIndex);

        /// <summary>
        /// Converts the index of the cell to the 3D point (y is zero) in world space
        /// based on the result from GetCellLocalPosition()
        /// </summary>
        /// <returns>Vector3 of the position of the center of the cell in world space</returns>
        /// <param name="cellIndex">The index of the cell</param>
        Vector3 GetCellGlobalPosition(int cellIndex);

        Quaternion GetGridRotation();

        /// <summary>
        /// Perceive the latest grid status. Detect colliders for each cell, parse the collider arrays,
        /// then trigger registered sensors to encode and update with the new grid status.
        /// </summary>
        void Perceive();

        /// <summary>
        /// Same as Perceive(), but only load data for debug gizmo.
        /// </summary>
        void UpdateGizmo();

        /// <summary>
        /// Register a sensor to this GridPerception to receive the grid perception results.
        /// When the GridPerception perceive a new observation, registered sensors will be triggered
        /// to encode the new observation and update its data.
        /// </summary>
        void RegisterSensor(GridSensorBase sensor);

        /// <summary>
        /// Register an internal debug sensor.
        /// Debug sensors will only be triggered when drawing debug gizmos.
        /// </summary>
        void RegisterDebugSensor(GridSensorBase debugSensor);
    }
}