using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
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();
[FormerlySerializedAs("_brainsToControl")]
[SerializeField]
private List m_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 m_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 && !m_BrainsToControl.Contains(brain))
{
m_BrainsToControl.Add(brain);
}
if (!controlled && m_BrainsToControl.Contains(brain))
{
m_BrainsToControl.Remove(brain);
}
}
}
///
/// Removes all the Brains of the BroadcastHub
///
public void Clear()
{
broadcastingBrains.Clear();
m_BrainsToControl.Clear();
}
}
}