using System;
namespace Unity.MLAgents
{
///
/// Factory class for an ICommunicator instance. This is used to the at startup.
/// By default, on desktop platforms, an ICommunicator will be created and attempt to connect
/// to a trainer. This behavior can be prevented by setting to false
/// *before* the is initialized.
///
public static class CommunicatorFactory
{
static Func s_Creator;
static bool s_Enabled = true;
///
/// Whether or not an ICommunicator instance will be created when the is initialized.
/// Changing this has no effect after the has already been initialized.
///
public static bool Enabled
{
get => s_Enabled;
set => s_Enabled = value;
}
public static bool CommunicatorRegistered => s_Creator != null;
internal static ICommunicator Create()
{
return s_Enabled ? s_Creator() : null;
}
public static void Register(Func creator) where T : ICommunicator
{
s_Creator = () => creator();
}
public static void ClearCreator()
{
s_Creator = null;
}
}
}