浏览代码

Made BehaviorParameters internal (#3546)

* Made the BrainParameters internal

* Editing the docs

* [skip-ci] A lot more controversial

* [skip ci] Added formerly serialized as

* Use cached BehaviorParameters
/bug-failed-api-check
GitHub 5 年前
当前提交
47755a62
共有 7 个文件被更改,包括 27 次插入12 次删除
  1. 8
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs
  2. 4
      Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs
  3. 1
      com.unity.ml-agents/CHANGELOG.md
  4. 2
      com.unity.ml-agents/Editor/BehaviorParametersEditor.cs
  5. 13
      com.unity.ml-agents/Runtime/Agent.cs
  6. 10
      com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs
  7. 1
      docs/Migrating.md

8
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs


void OverrideModel()
{
m_Agent.LazyInitialize();
var bp = m_Agent.GetComponent<BehaviorParameters>();
var name = m_Agent.BehaviorName;
var nnModel = GetModelForBehaviorName(bp.behaviorName);
Debug.Log($"Overriding behavior {bp.behaviorName} for agent with model {nnModel?.name}");
var nnModel = GetModelForBehaviorName(name);
Debug.Log($"Overriding behavior {name} for agent with model {nnModel?.name}");
m_Agent.GiveModel($"Override_{bp.behaviorName}", nnModel);
m_Agent.GiveModel($"Override_{name}", nnModel);
}
}

4
Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs


[HideInInspector]
public Rigidbody agentRb;
SoccerSettings m_SoccerSettings;
BehaviorParameters m_BehaviorParameters;
m_BehaviorParameters = gameObject.GetComponent<BehaviorParameters>();
if (m_BehaviorParameters.m_TeamID == (int)Team.Blue)
if (TeamId == (int)Team.Blue)
{
team = Team.Blue;
m_Transform = new Vector3(transform.position.x - 4f, .5f, transform.position.z);

1
com.unity.ml-agents/CHANGELOG.md


- All Sensor related code has been moved to the namespace `MLAgents.Sensors`.
- All SideChannel related code has been moved to the namespace `MLAgents.SideChannels`.
- `BrainParameters` and `SpaceType` have been removed from the public API
- `BehaviorParameters` have been removed from the public API.
### Minor Changes
- Monitor.cs was moved to Examples. (#3372)

2
com.unity.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_TeamID"));
EditorGUILayout.PropertyField(so.FindProperty("TeamId"));
EditorGUILayout.PropertyField(so.FindProperty("m_UseChildSensors"), true);
// EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Heuristic"), true);
EditorGUI.indentLevel--;

13
com.unity.ml-agents/Runtime/Agent.cs


public int maxStep;
}
public int TeamId {
get {
LazyInitialize();
return m_PolicyFactory.TeamId;
}
}
public string BehaviorName {
get {
LazyInitialize();
return m_PolicyFactory.behaviorName;
}
}
[SerializeField][HideInInspector]
internal AgentParameters agentParameters;
[SerializeField][HideInInspector]

10
com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs


/// The Factory to generate policies.
/// </summary>
[AddComponentMenu("ML Agents/Behavior Parameters", (int)MenuGroup.Default)]
public class BehaviorParameters : MonoBehaviour
internal class BehaviorParameters : MonoBehaviour
{
[Serializable]
enum BehaviorType

/// </summary>
[HideInInspector]
[SerializeField]
public int m_TeamID;
[FormerlySerializedAs("m_TeamID")]
public int TeamId;
[FormerlySerializedAs("m_useChildSensors")]
[HideInInspector]
[SerializeField]

/// </summary>
public string fullyQualifiedBehaviorName
{
get { return m_BehaviorName + "?team=" + m_TeamID; }
get { return m_BehaviorName + "?team=" + TeamId; }
internal IPolicy GeneratePolicy(Func<float[]> heuristic)
public IPolicy GeneratePolicy(Func<float[]> heuristic)
{
switch (m_BehaviorType)
{

1
docs/Migrating.md


* The `--multi-gpu` option has been removed temporarily.
* `AgentInfo.actionMasks` has been renamed to `AgentInfo.discreteActionMasks`.
* `BrainParameters` and `SpaceType` have been removed from the public API
* `BehaviorParameters` have been removed from the public API.
### Steps to Migrate
* Add the `using MLAgents.Sensors;` in addition to `using MLAgents;` on top of your Agent's script.

正在加载...
取消
保存