Unity 机器学习代理工具包 (ML-Agents) 是一个开源项目,它使游戏和模拟能够作为训练智能代理的环境。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

68 行
2.2 KiB

using System.Collections.Generic;
using UnityEngine;
namespace MLAgents
{
/// <summary>
/// BroadcastHub holds reference to brains and keeps track wether or not the brain be
/// remotely controlled.
/// </summary>
[System.Serializable]
public class BroadcastHub
{
[SerializeField]
public List<Brain> broadcastingBrains = new List<Brain>();
[SerializeField]
private List<Brain> _brainsToControl = new List<Brain>();
/// <summary>
/// The number of Brains inside the BroadcastingHub.
/// </summary>
public int Count
{
get { return broadcastingBrains.Count; }
}
/// <summary>
/// Checks that a given Brain is set to be remote controlled.
/// </summary>
/// <param name="brain"> The Brain that is beeing checked</param>
/// <returns>true if the Brain is set to Controlled and false otherwise. Will return
/// false if the Brain is not present in the Hub.</returns>
public bool IsControlled(Brain brain)
{
return _brainsToControl.Contains(brain);
}
/// <summary>
/// Sets a brain to controlled.
/// </summary>
/// <param name="brain"> The Brain that is being set to controlled</param>
/// <param name="controlled"> if true, the Brain will be set to remote controlled. Otherwise
/// the brain will be set to broadcast only.</param>
public void SetControlled(Brain brain, bool controlled)
{
if (broadcastingBrains.Contains(brain))
{
if (controlled && !_brainsToControl.Contains(brain))
{
_brainsToControl.Add(brain);
}
if (!controlled && _brainsToControl.Contains(brain))
{
_brainsToControl.Remove(brain);
}
}
}
/// <summary>
/// Removes all the Brains of the BroadcastHub
/// </summary>
public void Clear()
{
broadcastingBrains.Clear();
_brainsToControl.Clear();
}
}
}