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