浏览代码

Add option to search agent children for SensorComponents (#3095)

/asymm-envs
GitHub 5 年前
当前提交
a074c501
共有 3 个文件被更改,包括 30 次插入3 次删除
  1. 11
      UnitySDK/Assets/ML-Agents/Editor/BehaviorParametersEditor.cs
  2. 11
      UnitySDK/Assets/ML-Agents/Scripts/Agent.cs
  3. 11
      UnitySDK/Assets/ML-Agents/Scripts/Policy/BehaviorParameters.cs

11
UnitySDK/Assets/ML-Agents/Editor/BehaviorParametersEditor.cs


EditorGUILayout.PropertyField(so.FindProperty("m_InferenceDevice"), true);
EditorGUI.indentLevel--;
EditorGUILayout.PropertyField(so.FindProperty("m_BehaviorType"));
EditorGUILayout.PropertyField(so.FindProperty("m_useChildSensors"), true);
// EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Heuristic"), true);
EditorGUI.indentLevel--;
if (EditorGUI.EndChangeCheck())

Model barracudaModel = null;
var model = (NNModel)serializedObject.FindProperty("m_Model").objectReferenceValue;
var behaviorParameters = (BehaviorParameters)target;
var sensorComponents = behaviorParameters.GetComponents<SensorComponent>();
SensorComponent[] sensorComponents;
if(behaviorParameters.useChildSensors)
{
sensorComponents = behaviorParameters.GetComponentsInChildren<SensorComponent>();
}
else
{
sensorComponents = behaviorParameters.GetComponents<SensorComponent>();
}
var brainParameters = behaviorParameters.brainParameters;
if (model != null)
{

11
UnitySDK/Assets/ML-Agents/Scripts/Agent.cs


public void InitializeSensors()
{
// Get all attached sensor components
var attachedSensorComponents = GetComponents<SensorComponent>();
SensorComponent[] attachedSensorComponents;
if(m_PolicyFactory.useChildSensors)
{
attachedSensorComponents = GetComponentsInChildren<SensorComponent>();
}
else
{
attachedSensorComponents = GetComponents<SensorComponent>();
}
sensors.Capacity += attachedSensorComponents.Length;
foreach (var component in attachedSensorComponents)
{

11
UnitySDK/Assets/ML-Agents/Scripts/Policy/BehaviorParameters.cs


{
/// <summary>
/// The Factory to generate policies.
/// The Factory to generate policies.
/// </summary>
public class BehaviorParameters : MonoBehaviour
{

[HideInInspector]
[SerializeField]
string m_BehaviorName = "My Behavior";
[HideInInspector]
[SerializeField]
[Tooltip("Use all Sensor components attached to child GameObjects of this Agent.")]
bool m_useChildSensors = true;
}
public bool useChildSensors
{
get { return m_useChildSensors; }
}
public string behaviorName

正在加载...
取消
保存