GitHub
4 年前
当前提交
3fbcc26c
共有 18 个文件被更改,包括 1253 次插入 和 1005 次删除
-
342Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/FoodCollectorArea.prefab
-
245Project/Assets/ML-Agents/Examples/FoodCollector/Scenes/FoodCollector.unity
-
693com.unity.ml-agents.extensions/Runtime/Sensors/GridSensor.cs
-
2com.unity.ml-agents.extensions/Runtime/Sensors/GridSensorComponent.cs.meta
-
128com.unity.ml-agents.extensions/Tests/Editor/Sensors/ChannelHotPerceiveTests.cs
-
20com.unity.ml-agents.extensions/Tests/Editor/Sensors/ChannelHotShapeTests.cs
-
128com.unity.ml-agents.extensions/Tests/Editor/Sensors/ChannelPerceiveTests.cs
-
16com.unity.ml-agents.extensions/Tests/Editor/Sensors/ChannelShapeTests.cs
-
45com.unity.ml-agents.extensions/Tests/Editor/Sensors/CountingGridSensorPerceiveTests.cs
-
8com.unity.ml-agents.extensions/Tests/Editor/Sensors/CountingGridSensorShapeTests.cs
-
35com.unity.ml-agents.extensions/Tests/Editor/Sensors/GridObservationPerceiveTests.cs
-
14com.unity.ml-agents.extensions/Tests/Editor/Sensors/GridSensorTestUtils.cs
-
50com.unity.ml-agents.extensions/Tests/Utils/GridObsTestComponents/SimpleTestGridSensor.cs
-
121com.unity.ml-agents.extensions/Editor/GridSensorComponentEditor.cs
-
11com.unity.ml-agents.extensions/Editor/GridSensorComponentEditor.cs.meta
-
286com.unity.ml-agents.extensions/Runtime/Sensors/GridSensorComponent.cs
-
114com.unity.ml-agents.extensions/Runtime/Sensors/CountingGridSensor.cs
-
0/com.unity.ml-agents.extensions/Runtime/Sensors/GridSensorComponent.cs.meta
|
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
using Unity.MLAgents.Editor; |
|||
using Unity.MLAgents.Extensions.Sensors; |
|||
|
|||
namespace Unity.MLAgents.Extensions.Editor |
|||
{ |
|||
[CustomEditor(typeof(GridSensorComponent))] |
|||
[CanEditMultipleObjects] |
|||
internal class GridSensorComponentEditor : UnityEditor.Editor |
|||
{ |
|||
public override void OnInspectorGUI() |
|||
{ |
|||
var so = serializedObject; |
|||
so.Update(); |
|||
|
|||
// Drawing the GridSensorComponent
|
|||
EditorGUI.BeginChangeCheck(); |
|||
|
|||
EditorGUI.BeginDisabledGroup(!EditorUtilities.CanUpdateModelProperties()); |
|||
{ |
|||
// These fields affect the sensor order or observation size,
|
|||
// So can't be changed at runtime.
|
|||
EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_SensorName)), true); |
|||
|
|||
EditorGUILayout.LabelField("Grid Settings", EditorStyles.boldLabel); |
|||
EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_CellScale)), true); |
|||
// We only supports 2D GridSensor now so display gridNumSide as Vector2
|
|||
var gridNumSide = so.FindProperty(nameof(GridSensorComponent.m_GridNumSide)); |
|||
var gridNumSide2d = new Vector2Int(gridNumSide.vector3IntValue.x, gridNumSide.vector3IntValue.z); |
|||
var newGridNumSide = EditorGUILayout.Vector2IntField("Grid Num Side", gridNumSide2d); |
|||
gridNumSide.vector3IntValue = new Vector3Int(newGridNumSide.x, 1, newGridNumSide.y); |
|||
EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_RootReference)), true); |
|||
} |
|||
EditorGUI.EndDisabledGroup(); |
|||
EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_RotateWithAgent)), true); |
|||
|
|||
EditorGUI.BeginDisabledGroup(!EditorUtilities.CanUpdateModelProperties()); |
|||
{ |
|||
EditorGUILayout.LabelField("Channel Settings", EditorStyles.boldLabel); |
|||
EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_DepthType)), true); |
|||
|
|||
// channel depth
|
|||
var channelDepth = so.FindProperty(nameof(GridSensorComponent.m_ChannelDepth)); |
|||
var newDepth = EditorGUILayout.IntField("Channel Depth", channelDepth.arraySize); |
|||
if (newDepth != channelDepth.arraySize) |
|||
{ |
|||
channelDepth.arraySize = newDepth; |
|||
} |
|||
EditorGUI.indentLevel++; |
|||
for (var i = 0; i < channelDepth.arraySize; i++) |
|||
{ |
|||
var objectTag = channelDepth.GetArrayElementAtIndex(i); |
|||
EditorGUILayout.PropertyField(objectTag, new GUIContent("Channel " + i + " Depth"), true); |
|||
} |
|||
EditorGUI.indentLevel--; |
|||
|
|||
// detectable objects
|
|||
var detectableObjects = so.FindProperty(nameof(GridSensorComponent.m_DetectableObjects)); |
|||
var newSize = EditorGUILayout.IntField("Detectable Objects", detectableObjects.arraySize); |
|||
if (newSize != detectableObjects.arraySize) |
|||
{ |
|||
detectableObjects.arraySize = newSize; |
|||
} |
|||
EditorGUI.indentLevel++; |
|||
for (var i = 0; i < detectableObjects.arraySize; i++) |
|||
{ |
|||
var objectTag = detectableObjects.GetArrayElementAtIndex(i); |
|||
EditorGUILayout.PropertyField(objectTag, new GUIContent("Tag " + i), true); |
|||
} |
|||
EditorGUI.indentLevel--; |
|||
|
|||
EditorGUILayout.LabelField("Collider and Buffer", EditorStyles.boldLabel); |
|||
EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_MaxColliderBufferSize)), true); |
|||
EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_InitialColliderBufferSize)), true); |
|||
} |
|||
EditorGUI.EndDisabledGroup(); |
|||
EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_ObserveMask)), true); |
|||
EditorGUI.BeginDisabledGroup(!EditorUtilities.CanUpdateModelProperties()); |
|||
{ |
|||
EditorGUILayout.LabelField("Sensor Settings", EditorStyles.boldLabel); |
|||
EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_ObservationStacks)), true); |
|||
} |
|||
EditorGUI.EndDisabledGroup(); |
|||
EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_CompressionType)), true); |
|||
|
|||
EditorGUILayout.LabelField("Debug Gizmo", EditorStyles.boldLabel); |
|||
EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_ShowGizmos)), true); |
|||
EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_GizmoYOffset)), true); |
|||
|
|||
// detectable objects
|
|||
var debugColors = so.FindProperty(nameof(GridSensorComponent.m_DebugColors)); |
|||
var detectableObjectSize = so.FindProperty(nameof(GridSensorComponent.m_DetectableObjects)).arraySize; |
|||
if (detectableObjectSize != debugColors.arraySize) |
|||
{ |
|||
debugColors.arraySize = detectableObjectSize; |
|||
} |
|||
EditorGUI.indentLevel++; |
|||
for (var i = 0; i < debugColors.arraySize; i++) |
|||
{ |
|||
var debugColor = debugColors.GetArrayElementAtIndex(i); |
|||
EditorGUILayout.PropertyField(debugColor, new GUIContent("Tag " + i + " Color"), true); |
|||
} |
|||
EditorGUI.indentLevel--; |
|||
|
|||
var requireSensorUpdate = EditorGUI.EndChangeCheck(); |
|||
so.ApplyModifiedProperties(); |
|||
|
|||
if (requireSensorUpdate) |
|||
{ |
|||
UpdateSensor(); |
|||
} |
|||
} |
|||
|
|||
void UpdateSensor() |
|||
{ |
|||
var sensorComponent = serializedObject.targetObject as GridSensorComponent; |
|||
sensorComponent?.UpdateSensor(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 62dc58d0ddf584affa1f269e9c5791c2 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using Unity.MLAgents.Sensors; |
|||
|
|||
namespace Unity.MLAgents.Extensions.Sensors |
|||
{ |
|||
/// <summary>
|
|||
/// A SensorComponent that creates a <see cref="GridSensor"/>.
|
|||
/// </summary>
|
|||
[AddComponentMenu("ML Agents/Grid Sensor", (int)MenuGroup.Sensors)] |
|||
public class GridSensorComponent : SensorComponent |
|||
{ |
|||
protected GridSensor m_Sensor; |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal string m_SensorName = "GridSensor"; |
|||
// <summary>
|
|||
/// Name of the generated <see cref="GridSensor"/> object.
|
|||
/// Note that changing this at runtime does not affect how the Agent sorts the sensors.
|
|||
/// </summary>
|
|||
public string SensorName |
|||
{ |
|||
get { return m_SensorName; } |
|||
set { m_SensorName = value; } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal Vector3 m_CellScale = new Vector3(1f, 0.01f, 1f); |
|||
|
|||
/// <summary>
|
|||
/// The scale of each grid cell.
|
|||
/// Note that changing this after the sensor is created has no effect.
|
|||
/// </summary>
|
|||
public Vector3 CellScale |
|||
{ |
|||
get { return m_CellScale; } |
|||
set { m_CellScale = value; } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal Vector3Int m_GridNumSide = new Vector3Int(16, 1, 16); |
|||
/// <summary>
|
|||
/// The number of grid on each side.
|
|||
/// Note that changing this after the sensor is created has no effect.
|
|||
/// </summary>
|
|||
public Vector3Int GridNumSide |
|||
{ |
|||
get { return m_GridNumSide; } |
|||
set |
|||
{ |
|||
if (value.y != 1) |
|||
{ |
|||
m_GridNumSide = new Vector3Int(value.x, 1, value.z); |
|||
} |
|||
else |
|||
{ |
|||
m_GridNumSide = value; |
|||
} |
|||
} |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal bool m_RotateWithAgent = true; |
|||
/// <summary>
|
|||
/// Rotate the grid based on the direction the agent is facing.
|
|||
/// </summary>
|
|||
public bool RotateWithAgent |
|||
{ |
|||
get { return m_RotateWithAgent; } |
|||
set { m_RotateWithAgent = value; } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal int[] m_ChannelDepth = new int[] { 1 }; |
|||
/// <summary>
|
|||
/// Array holding the depth of each channel.
|
|||
/// Note that changing this after the sensor is created has no effect.
|
|||
/// </summary>
|
|||
public int[] ChannelDepth |
|||
{ |
|||
get { return m_ChannelDepth; } |
|||
set { m_ChannelDepth = value; } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal string[] m_DetectableObjects; |
|||
/// <summary>
|
|||
/// List of tags that are detected.
|
|||
/// Note that changing this after the sensor is created has no effect.
|
|||
/// </summary>
|
|||
public string[] DetectableObjects |
|||
{ |
|||
get { return m_DetectableObjects; } |
|||
set { m_DetectableObjects = value; } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal LayerMask m_ObserveMask; |
|||
/// <summary>
|
|||
/// The layer mask.
|
|||
/// </summary>
|
|||
public LayerMask ObserveMask |
|||
{ |
|||
get { return m_ObserveMask; } |
|||
set { m_ObserveMask = value; } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal GridDepthType m_DepthType = GridDepthType.Channel; |
|||
/// <summary>
|
|||
/// The data layout that the grid should output.
|
|||
/// Note that changing this after the sensor is created has no effect.
|
|||
/// </summary>
|
|||
public GridDepthType DepthType |
|||
{ |
|||
get { return m_DepthType; } |
|||
set { m_DepthType = value; } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal GameObject m_RootReference; |
|||
/// <summary>
|
|||
/// The reference of the root of the agent. This is used to disambiguate objects with the same tag as the agent. Defaults to current GameObject.
|
|||
/// Note that changing this after the sensor is created has no effect.
|
|||
/// </summary>
|
|||
public GameObject RootReference |
|||
{ |
|||
get { return m_RootReference == null ? gameObject : m_RootReference; } |
|||
set { m_RootReference = value; } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal int m_MaxColliderBufferSize = 500; |
|||
/// <summary>
|
|||
/// The absolute max size of the Collider buffer used in the non-allocating Physics calls. In other words
|
|||
/// the Collider buffer will never grow beyond this number even if there are more Colliders in the Grid Cell.
|
|||
/// Note that changing this after the sensor is created has no effect.
|
|||
/// </summary>
|
|||
public int MaxColliderBufferSize |
|||
{ |
|||
get { return m_MaxColliderBufferSize; } |
|||
set { m_MaxColliderBufferSize = value; } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal int m_InitialColliderBufferSize = 4; |
|||
/// <summary>
|
|||
/// The Estimated Max Number of Colliders to expect per cell. This number is used to
|
|||
/// pre-allocate an array of Colliders in order to take advantage of the OverlapBoxNonAlloc
|
|||
/// Physics API. If the number of colliders found is >= InitialColliderBufferSize the array
|
|||
/// will be resized to double its current size. The hard coded absolute size is 500.
|
|||
/// Note that changing this after the sensor is created has no effect.
|
|||
/// </summary>
|
|||
public int InitialColliderBufferSize |
|||
{ |
|||
get { return m_InitialColliderBufferSize; } |
|||
set { m_InitialColliderBufferSize = value; } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal Color[] m_DebugColors; |
|||
/// <summary>
|
|||
/// Array of Colors used for the grid gizmos.
|
|||
/// </summary>
|
|||
public Color[] DebugColors |
|||
{ |
|||
get { return m_DebugColors; } |
|||
set { m_DebugColors = value; } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal float m_GizmoYOffset = 0f; |
|||
/// <summary>
|
|||
/// The height of the gizmos grid.
|
|||
/// </summary>
|
|||
public float GizmoYOffset |
|||
{ |
|||
get { return m_GizmoYOffset; } |
|||
set { m_GizmoYOffset = value; } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal bool m_ShowGizmos = false; |
|||
/// <summary>
|
|||
/// Whether to show gizmos or not.
|
|||
/// </summary>
|
|||
public bool ShowGizmos |
|||
{ |
|||
get { return m_ShowGizmos; } |
|||
set { m_ShowGizmos = value; } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
internal SensorCompressionType m_CompressionType = SensorCompressionType.PNG; |
|||
/// <summary>
|
|||
/// The compression type to use for the sensor.
|
|||
/// </summary>
|
|||
public SensorCompressionType CompressionType |
|||
{ |
|||
get { return m_CompressionType; } |
|||
set { m_CompressionType = value; UpdateSensor(); } |
|||
} |
|||
|
|||
[HideInInspector, SerializeField] |
|||
[Range(1, 50)] |
|||
[Tooltip("Number of frames of observations that will be stacked before being fed to the neural network.")] |
|||
internal int m_ObservationStacks = 1; |
|||
/// <summary>
|
|||
/// Whether to stack previous observations. Using 1 means no previous observations.
|
|||
/// Note that changing this after the sensor is created has no effect.
|
|||
/// </summary>
|
|||
public int ObservationStacks |
|||
{ |
|||
get { return m_ObservationStacks; } |
|||
set { m_ObservationStacks = value; } |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override ISensor[] CreateSensors() |
|||
{ |
|||
m_Sensor = new GridSensor( |
|||
m_SensorName, |
|||
m_CellScale, |
|||
m_GridNumSide, |
|||
m_RotateWithAgent, |
|||
m_ChannelDepth, |
|||
m_DetectableObjects, |
|||
m_ObserveMask, |
|||
m_DepthType, |
|||
RootReference, |
|||
m_CompressionType, |
|||
m_MaxColliderBufferSize, |
|||
m_InitialColliderBufferSize |
|||
); |
|||
|
|||
if (ObservationStacks != 1) |
|||
{ |
|||
return new ISensor[] { new StackingSensor(m_Sensor, ObservationStacks) }; |
|||
} |
|||
return new ISensor[] { m_Sensor }; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Update fields that are safe to change on the Sensor at runtime.
|
|||
/// </summary>
|
|||
internal void UpdateSensor() |
|||
{ |
|||
if (m_Sensor != null) |
|||
{ |
|||
m_Sensor.CompressionType = m_CompressionType; |
|||
} |
|||
} |
|||
|
|||
void OnDrawGizmos() |
|||
{ |
|||
if (m_ShowGizmos) |
|||
{ |
|||
if (m_Sensor == null) |
|||
{ |
|||
return; |
|||
} |
|||
var cellColors = m_Sensor.PerceiveGizmoColor(); |
|||
var cellPositions = m_Sensor.GetGizmoPositions(); |
|||
var rotation = m_Sensor.GetGridRotation(); |
|||
|
|||
var scale = new Vector3(m_CellScale.x, 1, m_CellScale.z); |
|||
var gizmoYOffset = new Vector3(0, m_GizmoYOffset, 0); |
|||
var oldGizmoMatrix = Gizmos.matrix; |
|||
for (var i = 0; i < cellPositions.Length; i++) |
|||
{ |
|||
var cubeTransform = Matrix4x4.TRS(cellPositions[i] + gizmoYOffset, rotation, scale); |
|||
Gizmos.matrix = oldGizmoMatrix * cubeTransform; |
|||
var colorIndex = cellColors[i]; |
|||
var debugRayColor = Color.white; |
|||
if (colorIndex > -1 && m_DebugColors.Length > colorIndex) |
|||
{ |
|||
debugRayColor = m_DebugColors[colorIndex]; |
|||
} |
|||
Gizmos.color = new Color(debugRayColor.r, debugRayColor.g, debugRayColor.b, .5f); |
|||
Gizmos.DrawCube(Vector3.zero, Vector3.one); |
|||
} |
|||
|
|||
Gizmos.matrix = oldGizmoMatrix; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using UnityEngine; |
|||
|
|||
namespace Unity.MLAgents.Extensions.Sensors |
|||
{ |
|||
public class CountingGridSensor : GridSensor |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override void InitDepthType() |
|||
{ |
|||
ObservationPerCell = ChannelDepth.Length; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Overrides the initialization ofthe m_ChannelHotDefaultPerceptionBuffer with 0s
|
|||
/// as the counting grid sensor starts within its initialization equal to 0
|
|||
/// </summary>
|
|||
public override void InitChannelHotDefaultPerceptionBuffer() |
|||
{ |
|||
m_ChannelHotDefaultPerceptionBuffer = new float[ObservationPerCell]; |
|||
} |
|||
|
|||
/// <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; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// For each collider, calls LoadObjectData on the gameobejct
|
|||
/// </summary>
|
|||
/// <param name="foundColliders">The array of colliders</param>
|
|||
/// <param name="cellIndex">The cell index the collider is in</param>
|
|||
/// <param name="cellCenter">the center of the cell the collider is in</param>
|
|||
protected override void ParseColliders(Collider[] foundColliders, int numFound, int cellIndex, Vector3 cellCenter) |
|||
{ |
|||
GameObject currentColliderGo = null; |
|||
Vector3 closestColliderPoint = Vector3.zero; |
|||
|
|||
for (int i = 0; i < numFound; i++) |
|||
{ |
|||
currentColliderGo = foundColliders[i].gameObject; |
|||
|
|||
// Continue if the current collider go is the root reference
|
|||
if (currentColliderGo == rootReference) |
|||
continue; |
|||
|
|||
closestColliderPoint = foundColliders[i].ClosestPointOnBounds(cellCenter); |
|||
|
|||
LoadObjectData(currentColliderGo, cellIndex, |
|||
Vector3.Distance(closestColliderPoint, transform.position) * InverseSphereRadius); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Throws an execption as this should not be called from the CountingGridSensor class
|
|||
/// </summary>
|
|||
/// <param name="currentColliderGo">The current gameobject to get data from</param>
|
|||
/// <param name="typeIndex">the index of the detectable tag of this gameobject</param>
|
|||
/// <param name="normalizedDistance">The normalized distance to the gridsensor</param>
|
|||
/// <returns></returns>
|
|||
protected override float[] GetObjectData(GameObject currentColliderGo, float typeIndex, float normalizedDistance) |
|||
{ |
|||
throw new Exception("GetObjectData isn't called within the CountingGridSensor"); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Adds 1 to the counting index for this gameobject of this type
|
|||
/// </summary>
|
|||
/// <param name="currentColliderGo">the current game object</param>
|
|||
/// <param name="cellIndex">the index of the cell</param>
|
|||
/// <param name="normalizedDistance">the normalized distance from the gameobject to the sensor</param>
|
|||
protected override void LoadObjectData(GameObject currentColliderGo, int cellIndex, float normalizedDistance) |
|||
{ |
|||
for (int i = 0; i < DetectableObjects.Length; i++) |
|||
{ |
|||
if (currentColliderGo != null && currentColliderGo.CompareTag(DetectableObjects[i])) |
|||
{ |
|||
if (ShowGizmos) |
|||
{ |
|||
Color debugRayColor = Color.white; |
|||
if (DebugColors.Length > 0) |
|||
{ |
|||
debugRayColor = DebugColors[i]; |
|||
} |
|||
CellActivity[cellIndex] = new Color(debugRayColor.r, debugRayColor.g, debugRayColor.b, .5f); |
|||
} |
|||
|
|||
/// <remarks>
|
|||
/// The observations are "channel count" so each grid is WxHxC where C is the number of tags
|
|||
/// This means that each value channelValues[i] is a counter of gameobject included into grid cells where i is the index of the tag in DetectableObjects
|
|||
/// </remarks>
|
|||
int countIndex = cellIndex * ObservationPerCell + i; |
|||
m_PerceptionBuffer[countIndex] = Mathf.Min(1f, m_PerceptionBuffer[countIndex] + 1f / ChannelDepth[i]); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue