|
|
|
|
|
|
/// The Factory to generate policies.
|
|
|
|
/// </summary>
|
|
|
|
[AddComponentMenu("ML Agents/Behavior Parameters", (int)MenuGroup.Default)] |
|
|
|
internal class BehaviorParameters : MonoBehaviour |
|
|
|
public class BehaviorParameters : MonoBehaviour |
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] |
|
|
|
[HideInInspector, SerializeField] |
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The associated <see cref="BrainParameters"/> for this behavior.
|
|
|
|
/// </summary>
|
|
|
|
public BrainParameters brainParameters |
|
|
|
{ |
|
|
|
get { return m_BrainParameters; } |
|
|
|
internal set { m_BrainParameters = value; } |
|
|
|
} |
|
|
|
|
|
|
|
[HideInInspector, SerializeField] |
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] |
|
|
|
InferenceDevice m_InferenceDevice; |
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] |
|
|
|
|
|
|
|
// Disable warning /com.unity.ml-agents/Runtime/Policy/BehaviorParameters.cs(...):
|
|
|
|
// warning CS0649: Field 'BehaviorParameters.m_BehaviorType' is never assigned to,
|
|
|
|
// and will always have its default value
|
|
|
|
// This field is set in the custom editor.
|
|
|
|
#pragma warning disable 0649
|
|
|
|
internal BehaviorType m_BehaviorType; |
|
|
|
#pragma warning restore 0649
|
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] |
|
|
|
string m_BehaviorName = "My Behavior"; |
|
|
|
/// The team ID for this behavior.
|
|
|
|
/// The neural network model used when in inference mode.
|
|
|
|
/// This cannot be set directly; use <see cref="Agent.GiveModel(string,NNModel,InferenceDevice)"/>
|
|
|
|
/// to set it.
|
|
|
|
[HideInInspector, SerializeField, FormerlySerializedAs("m_TeamID")] |
|
|
|
public int TeamId; |
|
|
|
public NNModel model |
|
|
|
{ |
|
|
|
get { return m_Model; } |
|
|
|
} |
|
|
|
[FormerlySerializedAs("m_useChildSensors")] |
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] |
|
|
|
[Tooltip("Use all Sensor components attached to child GameObjects of this Agent.")] |
|
|
|
bool m_UseChildSensors = true; |
|
|
|
[HideInInspector, SerializeField] |
|
|
|
InferenceDevice m_InferenceDevice; |
|
|
|
/// The associated <see cref="BrainParameters"/> for this behavior.
|
|
|
|
/// How inference is performed for this Agent's model.
|
|
|
|
/// This cannot be set directly; use <see cref="Agent.GiveModel(string,NNModel,InferenceDevice)"/>
|
|
|
|
/// to set it.
|
|
|
|
internal BrainParameters brainParameters |
|
|
|
public InferenceDevice inferenceDevice |
|
|
|
get { return m_BrainParameters; } |
|
|
|
get { return m_InferenceDevice; } |
|
|
|
[HideInInspector, SerializeField] |
|
|
|
BehaviorType m_BehaviorType; |
|
|
|
|
|
|
|
/// Whether or not to use all the sensor components attached to child GameObjects of the agent.
|
|
|
|
/// The BehaviorType for the Agent.
|
|
|
|
/// This cannot be set directly; use <see cref="Agent.SetBehaviorType(BehaviorType)"/>
|
|
|
|
/// to set it.
|
|
|
|
public bool useChildSensors |
|
|
|
public BehaviorType behaviorType |
|
|
|
get { return m_UseChildSensors; } |
|
|
|
get { return m_BehaviorType; } |
|
|
|
internal set { m_BehaviorType = value; } |
|
|
|
[HideInInspector, SerializeField] |
|
|
|
string m_BehaviorName = "My Behavior"; |
|
|
|
|
|
|
|
/// This cannot be set directly; use <see cref="Agent.GiveModel(string,NNModel,InferenceDevice)"/>
|
|
|
|
/// to set it.
|
|
|
|
/// </summary>
|
|
|
|
public string behaviorName |
|
|
|
{ |
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The team ID for this behavior.
|
|
|
|
/// </summary>
|
|
|
|
[HideInInspector, SerializeField, FormerlySerializedAs("m_TeamID")] |
|
|
|
public int TeamId; |
|
|
|
// TODO properties here instead of Agent
|
|
|
|
|
|
|
|
[FormerlySerializedAs("m_useChildSensors")] |
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] |
|
|
|
[Tooltip("Use all Sensor components attached to child GameObjects of this Agent.")] |
|
|
|
bool m_UseChildSensors = true; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether or not to use all the sensor components attached to child GameObjects of the agent.
|
|
|
|
/// </summary>
|
|
|
|
public bool useChildSensors |
|
|
|
{ |
|
|
|
get { return m_UseChildSensors; } |
|
|
|
internal set { m_UseChildSensors = value; } // TODO make public, don't allow changes at runtime
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the behavior name, concatenated with any other metadata (i.e. team id).
|
|
|
|
/// </summary>
|
|
|
|
public string fullyQualifiedBehaviorName |
|
|
|
|
|
|
|
|
|
|
public IPolicy GeneratePolicy(Func<float[]> heuristic) |
|
|
|
internal IPolicy GeneratePolicy(Func<float[]> heuristic) |
|
|
|
{ |
|
|
|
switch (m_BehaviorType) |
|
|
|
{ |
|
|
|
|
|
|
/// <param name="newBehaviorName">New name for the behavior.</param>
|
|
|
|
/// <param name="model">New neural network model for this behavior.</param>
|
|
|
|
/// <param name="inferenceDevice">New inference device for this behavior.</param>
|
|
|
|
public void GiveModel( |
|
|
|
internal void SetModel( |
|
|
|
string newBehaviorName, |
|
|
|
NNModel model, |
|
|
|
InferenceDevice inferenceDevice = InferenceDevice.CPU) |
|
|
|