浏览代码

AcademyStepper to DontDestroyOnLoad (#3789)

* AcademyStepper to DontDestroyOnLoad

* Adding a try-catch around DontDestroyOnLoad because it cannot be used in Editor Tests
/develop/no-threading
GitHub 4 年前
当前提交
bc45453b
共有 3 个文件被更改,包括 28 次插入7 次删除
  1. 24
      Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicController.cs
  2. 6
      com.unity.ml-agents/Runtime/Academy.cs
  3. 5
      com.unity.ml-agents/Runtime/Agent.cs

24
Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicController.cs


using UnityEngine;
using UnityEngine.SceneManagement;
using MLAgents;
/// <summary>

Agent m_Agent;
ResetAgent();
m_Position = 10;
transform.position = new Vector3(m_Position - 10f, 0f, 0f);
smallGoal.transform.position = new Vector3(k_SmallGoalPosition - 10f, 0f, 0f);
largeGoal.transform.position = new Vector3(k_LargeGoalPosition - 10f, 0f, 0f);
}
/// <summary>

}
public void ResetAgent()
{
m_Position = 10;
smallGoal.transform.position = new Vector3(k_SmallGoalPosition - 10f, 0f, 0f);
largeGoal.transform.position = new Vector3(k_LargeGoalPosition - 10f, 0f, 0f);
{
// This is a very inefficient way to reset the scene. Used here for testing.
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
m_Agent = null; // LoadScene only takes effect at the next Update.
// We set the Agent to null to avoid using the Agent before the reload
}
public void FixedUpdate()

void WaitTimeInference()
{
if (m_Agent == null)
{
return;
}
m_Agent.RequestDecision();
m_Agent?.RequestDecision();
}
else
{

ApplyAction(m_Agent.GetAction());
m_TimeSinceDecision = 0f;
m_Agent.RequestDecision();
m_Agent?.RequestDecision();
}
else
{

6
com.unity.ml-agents/Runtime/Academy.cs


// Don't show this object in the hierarchy
m_StepperObject.hideFlags = HideFlags.HideInHierarchy;
m_FixedUpdateStepper = m_StepperObject.AddComponent<AcademyFixedUpdateStepper>();
try
{
// This try-catch is because DontDestroyOnLoad cannot be used in Editor Tests
GameObject.DontDestroyOnLoad(m_StepperObject);
}
catch {}
}
/// <summary>

5
com.unity.ml-agents/Runtime/Agent.cs


void NotifyAgentDone(DoneReason doneReason)
{
if (m_Info.done)
{
// The Agent was already marked as Done and should not be notified again
return;
}
m_Info.episodeId = m_EpisodeId;
m_Info.reward = m_Reward;
m_Info.done = true;

正在加载...
取消
保存