浏览代码

Making the behavior type and enum (#2937)

* Making the behavior type and enum

* CamelCase
/develop-newnormalization
GitHub 5 年前
当前提交
8a15cac5
共有 2 个文件被更改,包括 38 次插入20 次删除
  1. 2
      UnitySDK/Assets/ML-Agents/Editor/BehaviorParametersEditor.cs
  2. 56
      UnitySDK/Assets/ML-Agents/Scripts/Policy/BehaviorParameters.cs

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


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

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


public class BehaviorParameters : MonoBehaviour
{
[Serializable]
private enum BehaviorType
{
Default,
HeuristicOnly,
InferenceOnly
}
[HideInInspector] [SerializeField]
[HideInInspector]
[SerializeField]
[HideInInspector] [SerializeField]
[HideInInspector]
[SerializeField]
[HideInInspector] [SerializeField]
bool m_UseHeuristic;
[HideInInspector] [SerializeField]
[HideInInspector]
[SerializeField]
BehaviorType m_BehaviorType;
[HideInInspector]
[SerializeField]
string m_BehaviorName = "My Behavior";
public BrainParameters brainParameters

public IPolicy GeneratePolicy(Func<float[]> heuristic)
{
if (m_UseHeuristic)
{
return new HeuristicPolicy(heuristic);
}
if (FindObjectOfType<Academy>().IsCommunicatorOn)
{
return new RemotePolicy(m_BrainParameters, m_BehaviorName);
}
if (m_Model != null)
{
return new BarracudaPolicy(m_BrainParameters, m_Model, m_InferenceDevice);
}
else
switch (m_BehaviorType)
return new HeuristicPolicy(heuristic);
case BehaviorType.HeuristicOnly:
return new HeuristicPolicy(heuristic);
case BehaviorType.InferenceOnly:
return new BarracudaPolicy(m_BrainParameters, m_Model, m_InferenceDevice);
case BehaviorType.Default:
if (FindObjectOfType<Academy>().IsCommunicatorOn)
{
return new RemotePolicy(m_BrainParameters, m_BehaviorName);
}
if (m_Model != null)
{
return new BarracudaPolicy(m_BrainParameters, m_Model, m_InferenceDevice);
}
else
{
return new HeuristicPolicy(heuristic);
}
default:
return new HeuristicPolicy(heuristic);
}
}

正在加载...
取消
保存