/// <summary> /// Initializes the agent. Can be safely called multiple times. /// </summary> public void LazyInitialize() { if (m_Initialized) { return; } m_Initialized = true; // Grab the "static" properties for the Agent. m_EpisodeId = EpisodeIdCounter.GetEpisodeId(); m_PolicyFactory = GetComponent <BehaviorParameters>(); m_Info = new AgentInfo(); m_Action = new AgentAction(); sensors = new List <ISensor>(); Academy.Instance.AgentIncrementStep += AgentIncrementStep; Academy.Instance.AgentSendState += SendInfo; Academy.Instance.DecideAction += DecideAction; Academy.Instance.AgentAct += AgentStep; Academy.Instance.AgentForceReset += _AgentReset; m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic); ResetData(); Initialize(); InitializeSensors(); // The first time the Academy resets, all Agents in the scene will be // forced to reset through the <see cref="AgentForceReset"/> event. // To avoid the Agent resetting twice, the Agents will not begin their // episode when initializing until after the Academy had its first reset. if (Academy.Instance.TotalStepCount != 0) { OnEpisodeBegin(); } }
/// <summary> /// Initializes the agent. Can be safely called multiple times. /// </summary> public void LazyInitialize() { if (m_Initialized) { return; } m_Initialized = true; // Grab the "static" properties for the Agent. m_EpisodeId = EpisodeIdCounter.GetEpisodeId(); m_PolicyFactory = GetComponent <BehaviorParameters>(); m_Info = new AgentInfo(); m_Action = new AgentAction(); sensors = new List <ISensor>(); Academy.Instance.AgentIncrementStep += AgentIncrementStep; Academy.Instance.AgentSendState += SendInfo; Academy.Instance.DecideAction += DecideAction; Academy.Instance.AgentAct += AgentStep; Academy.Instance.AgentForceReset += _AgentReset; m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic); ResetData(); InitializeAgent(); InitializeSensors(); }
/// Helper method for the <see cref="OnEnable"/> event, created to /// facilitate testing. void OnEnableHelper(Academy academy) { m_Info = new AgentInfo(); m_Action = new AgentAction(); m_Sensors = new List <ISensor>(); if (academy == null) { throw new UnityAgentsException( "No Academy Component could be found in the scene."); } academy.AgentSetStatus += SetStatus; academy.AgentResetIfDone += ResetIfDone; academy.AgentSendState += SendInfo; academy.DecideAction += DecideAction; academy.AgentAct += AgentStep; academy.AgentForceReset += _AgentReset; academy.AgentSetDoneFlagFalse += NotDone; m_PolicyFactory = GetComponent <BehaviorParameters>(); m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic); ResetData(); InitializeAgent(); InitializeSensors(); }
/// Helper method for the <see cref="OnEnable"/> event, created to /// facilitate testing. void OnEnableHelper() { m_Info = new AgentInfo(); m_Action = new AgentAction(); sensors = new List <ISensor>(); Academy.Instance.AgentSendState += SendInfo; Academy.Instance.DecideAction += DecideAction; Academy.Instance.AgentAct += AgentStep; Academy.Instance.AgentForceReset += _AgentReset; m_PolicyFactory = GetComponent <BehaviorParameters>(); m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic); ResetData(); InitializeAgent(); InitializeSensors(); }