浏览代码

remove manager from academy when dispose

/MLA-1734-demo-provider
Ruo-Ping Dong 4 年前
当前提交
0ed78a36
共有 3 个文件被更改,包括 13 次插入7 次删除
  1. 14
      com.unity.ml-agents.extensions/Runtime/Teams/BaseTeamManager.cs
  2. 2
      com.unity.ml-agents/Runtime/Actuators/ITeamManager.cs
  3. 4
      com.unity.ml-agents/Runtime/Agent.cs

14
com.unity.ml-agents.extensions/Runtime/Teams/BaseTeamManager.cs


using System;
public class BaseTeamManager : ITeamManager
public class BaseTeamManager : ITeamManager, IDisposable
{
int m_StepCount;
int m_TeamMaxStep;

Academy.Instance.TeamManagerStep += _ManagerStep;
}
public void Dispose()
{
Academy.Instance.TeamManagerStep -= _ManagerStep;
}
void _ManagerStep()
{
m_StepCount += 1;

/// <summary>
/// Register the agent to the TeamManager.
/// Registered agents will be able to receive team rewards from the TeamManager.
/// All agents in the same training area should be added to the same TeamManager.
/// Registered agents will be able to receive team rewards from the TeamManager
/// and share observations during training.
/// </summary>
public virtual void RegisterAgent(Agent agent)
{

/// <summary>
/// Remove the agent from the TeamManager.
/// </summary>
public virtual void RemoveAgent(Agent agent)
public virtual void UnregisterAgent(Agent agent)
{
if (m_Agents.Contains(agent))
{

2
com.unity.ml-agents/Runtime/Actuators/ITeamManager.cs


void RegisterAgent(Agent agent);
void RemoveAgent(Agent agent);
void UnregisterAgent(Agent agent);
}
}

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


{
if (m_TeamManager != null)
{
m_TeamManager.RemoveAgent(this);
m_TeamManager.UnregisterAgent(this);
}
}

{
if (m_TeamManager != null)
{
m_TeamManager.RemoveAgent(this);
m_TeamManager.UnregisterAgent(this);
}
m_TeamManager = teamManager;
teamManager?.RegisterAgent(this);

正在加载...
取消
保存